# PSD different units

**URL:** <https://mne.discourse.group/t/psd-different-units/3809>\
**Category:** Support & Discussions\
**Created:** [October 14, 2021, 8:37am UTC](https://mne.discourse.group/t/psd-different-units/3809 "2021-10-14T08:37:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![guiomar](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@guiomar](https://mne.discourse.group/u/guiomar)\
**Post date:** [October 14, 2021, 8:37am UTC](https://mne.discourse.group/t/psd-different-units/3809/1 "2021-10-14T08:37:54Z")

</div>

Hi, I’m getting different unit ranges when doing psd.

When I epoch raw data with equal length segments and do a `plot_psd_topomap` per frequency bands, the range is different from the `plot_psd` one.  
See last figures on this [notebook](https://colab.research.google.com/drive/1SHq6nGd2VP9jHLQCF-U88U3ekZbK_0jn#scrollTo=23d408ab).  
I marked dB=True and Normalize=False. Any other thing that should be taking into account?

`plot_psd`  
 ![Captura de pantalla 2021-10-15 a las 13.42.51](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/6a153dc25eb562bd703f9691f7bfa296879f7dfc.png)

`plot_psd_topomap`  
 ![Captura de pantalla 2021-10-15 a las 13.42.58](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/215d73574856ac73f45069c804e02ca29fec4e59.png)

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [October 19, 2021, 6:48am UTC](https://mne.discourse.group/t/psd-different-units/3809/2 "2021-10-19T06:48:13Z")

</div>

The topomaps show power within specific frequency bands, whereas the PSD shows density. I’m thinking that maybe the units should not be per Hz in the topomaps because you’re basically summing power at specific frequencies.

In addition, if the unit is dB it cannot also be e.g. fT2/Hz, so we should probably fix the labels.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [October 19, 2021, 7:25am UTC](https://mne.discourse.group/t/psd-different-units/3809/3 "2021-10-19T07:25:01Z")

</div>

@cbrnr After bringing this up in a 10-second convo with @agramfort it appears that the actual difference is that in the topomaps, the unit is scaled differently (it’s actually in T^2/Hz and not in fT^2/Hz), so we should fix this or at least correct the label. Note that so far this is only a suspicion and I have yet to verify this.

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [October 19, 2021, 7:36am UTC](https://mne.discourse.group/t/psd-different-units/3809/4 "2021-10-19T07:36:45Z")

</div>

This doesn’t sound right to me. If it really were T^2/Hz, you would see nothing in the maps because the actual signal is orders of magnitudes smaller. If you consider what I suspected and add up the power e.g. within 0-4Hz, you’d actually get the values in the topomap. But I’m also not 100% and would need to confirm.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [October 19, 2021, 7:45am UTC](https://mne.discourse.group/t/psd-different-units/3809/5 "2021-10-19T07:45:42Z")

</div>

Did you consider that the values of the colorbar are MINUS ~200 dB? Your explanation doesn’t work with this

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [October 19, 2021, 7:53am UTC](https://mne.discourse.group/t/psd-different-units/3809/6 "2021-10-19T07:53:27Z")

</div>

True, I didn’t see the minus. But we’re talking about dB so it looks like the denominator in the two plot is different. But the other comment is still valid, the unit is dB and cannot be fT^2/Hz (or T^2/Hz) at the same time.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [October 19, 2021, 7:56am UTC](https://mne.discourse.group/t/psd-different-units/3809/7 "2021-10-19T07:56:54Z")

</div>

The labels indicate that the unit is, in fact, dB — indicated by “dB” written in parentheses.

To avoid confusion, the “fT^2/Hz” part could probably be renamed to “power” instead.

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [October 19, 2021, 7:59am UTC](https://mne.discourse.group/t/psd-different-units/3809/8 "2021-10-19T07:59:17Z")

</div>

Yes, this would avoid confusion, because fT^2/Hz are also just units 🙂.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [October 19, 2021, 8:02am UTC](https://mne.discourse.group/t/psd-different-units/3809/9 "2021-10-19T08:02:07Z")

</div>

OTOH it helps to figure out WHAT was “deci-Bel’d”. Maybe instead, we should have something like: “Power (dB(fT^2/Hz))”?

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [October 19, 2021, 8:02am UTC](https://mne.discourse.group/t/psd-different-units/3809/10 "2021-10-19T08:02:39Z")

</div>

Or more easily, just “dB(fT^2/Hz)”?

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [October 19, 2021, 8:14am UTC](https://mne.discourse.group/t/psd-different-units/3809/11 "2021-10-19T08:14:40Z")

</div>

But why would you want to do this? dB is a ratio of two power values on a log scale. It doesn’t matter if the original unit was fT/Hz or T/Hz, because the ratio will be the same.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [October 19, 2021, 9:16am UTC](https://mne.discourse.group/t/psd-different-units/3809/12 "2021-10-19T09:16:43Z")

</div>

To make it obvious what’s the “power” that’s considered here in the first place. I guess I’m more thinking about how to help beginners understand what they’re seeing here…

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [October 19, 2021, 10:09am UTC](https://mne.discourse.group/t/psd-different-units/3809/13 "2021-10-19T10:09:10Z")

</div>

I’ve opened a related issue that hopefully helps clarify things a bit:

> <https://github.com/mne-tools/mne-python/issues/9868>
>
> Consider the following MWE:
> \`\`\`python
> \# %%
> import numpy as np
> import matplot…lib.pyplot as plt
> 
> import mne
> from mne.time\_frequency import psd\_array\_multitaper, psd\_multitaper
> from mne.datasets import somato
> 
> data\_path = somato.data\_path()
> subject = '01'
> task = 'somato'
> raw\_fname = op.join(data\_path, 'sub-{}'.format(subject), 'meg',
> 'sub-{}\_task-{}\_meg.fif'.format(subject, task))
> 
> raw = mne.io.read\_raw\_fif(raw\_fname)
> events = mne.find\_events(raw, stim\_channel='STI 014')
> 
> picks = mne.pick\_types(raw.info, meg='grad', eeg=False, eog=True, stim=False)
> event\_id, tmin, tmax = 1, -1., 3.
> baseline = (None, 0)
> epochs = mne.Epochs(raw, events, event\_id, tmin, tmax, picks=picks,
> baseline=baseline, reject=dict(grad=4000e-13, eog=350e-6),
> preload=True)
> 
> epochs.resample(200., npad='auto') # resample to reduce computation time
> 
> 
> \# %%
> fmin = 1
> fmax = 40
> 
> epochs.plot\_psd(fmin=fmin, fmax=fmax, average=True, dB=True, area\_mode=None)
> \`\`\`
> 
> This produces the following PSD plot:
> !\[plot\_psd\](https://user-images.githubusercontent.com/2046265/137888613-5da80e17-b238-4171-999c-830ee3c6a65f.png)
> 
> Trying to reproduce this figure manually, I ran:
> 
> \`\`\`python
> \# %%
> psds, freqs = psd\_array\_multitaper(
> epochs.get\_data(),
> sfreq=epochs.info\['sfreq'\],
> fmin=fmin,
> fmax=fmax,
> n\_jobs=8
> )
> 
> psds\_scaled = psds \* 1e15\*\*2 # T -\> fT
> psds\_scaled\_dB = (10 \* np.log10(psds\_scaled)).mean(axis=0).mean(axis=0)
> 
> \_, ax = plt.subplots()
> ax.plot(freqs, psds\_scaled\_dB)
> \`\`\`
> This produces:
> !\[psd\_array\_scaled\](https://user-images.githubusercontent.com/2046265/137888778-24170ede-d228-4ed4-ad16-2384b0deab25.png)
> 
> The magnitude of the signal clearly differs from what we saw above.
> 
> Adjusting the scaling factor to \`1e13\`, I'm finally able to reproduce the output from \`epochs.plot\_psd\`:
> 
> \`\`\`python
> \# %%
> psds\_scaled = psds \* 1e13\*\*2 # T -\> 100 fT (?!)
> psds\_scaled\_dB = (10 \* np.log10(psds\_scaled)).mean(axis=0).mean(axis=0)
> 
> \_, ax = plt.subplots()
> ax.plot(freqs, psds\_scaled\_dB)
> \`\`\`
> !\[psd\_array\_scaled\_2\](https://user-images.githubusercontent.com/2046265/137889084-36ece6bb-c276-445e-98f0-cec2130ad2da.png)
> 
> Where's my mistake?
> 
> cc @cbrnr @agramfort

---

<div class="post-metadata">

**Author:** ![guiomar](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@guiomar](https://mne.discourse.group/u/guiomar)\
**Post date:** [October 19, 2021, 10:55am UTC](https://mne.discourse.group/t/psd-different-units/3809/14 "2021-10-19T10:55:55Z")

</div>

Hi! I think labels help a lot for units etc, so I wouldn’t removed them.

The issue you opened Richard dealing with the `psd_plot`, it’s instructive, I reproduced it as well using psd welch and multitapper funtions (old posts), but still I miss the relation with the `plot_psd_topomap`

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [October 19, 2021, 11:00am UTC](https://mne.discourse.group/t/psd-different-units/3809/15 "2021-10-19T11:00:35Z")

</div>

> [@guiomar](#):
>
> but still I miss the relation with the `plot_psd_topomap`

`plot_psd_topomap` doesn’t apply the unit scaling. If you run my example code from the GH issue and drop the line that scales the values, you’ll get results that resemble what you have in the topomaps.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [October 19, 2021, 11:06am UTC](https://mne.discourse.group/t/psd-different-units/3809/16 "2021-10-19T11:06:47Z")

</div>

I’ve opened an issue to address this inconsistency:

> <https://github.com/mne-tools/mne-python/issues/9870>
>
> \`Epochs.plot\_psd\` does scale the measurement units while \`Epochs.plot\_psd\_topoma…p\` doesn't, \[causing confusion\](https://mne.discourse.group/t/psd-different-units/3809/15)
> 
> \`\`\`python
> \# %%
> import numpy as np
> import matplotlib.pyplot as plt
> 
> import mne
> from mne.time\_frequency import psd\_array\_multitaper, psd\_multitaper
> from mne.datasets import somato
> 
> data\_path = somato.data\_path()
> subject = '01'
> task = 'somato'
> raw\_fname = op.join(data\_path, 'sub-{}'.format(subject), 'meg',
> 'sub-{}\_task-{}\_meg.fif'.format(subject, task))
> 
> raw = mne.io.read\_raw\_fif(raw\_fname)
> events = mne.find\_events(raw, stim\_channel='STI 014')
> 
> picks = mne.pick\_types(raw.info, meg='grad', eeg=False, eog=True, stim=False)
> event\_id, tmin, tmax = 1, -1., 3.
> baseline = (None, 0)
> epochs = mne.Epochs(raw, events, event\_id, tmin, tmax, picks=picks,
> baseline=baseline, reject=dict(grad=4000e-13, eog=350e-6),
> preload=True)
> 
> epochs.resample(200., npad='auto') # resample to reduce computation time
> 
> 
> \# %%
> fmin = 0.1
> fmax = 40
> 
> epochs.plot\_psd(fmin=fmin, fmax=fmax, average=True, dB=True, area\_mode=None)
> epochs.plot\_psd\_topomap(dB=True)
> \`\`\`
> 
> !\[a\](https://user-images.githubusercontent.com/2046265/137897334-aa71a546-e7b2-4086-9d7c-d516b4b0f4ec.png)
> 
> !\[b\](https://user-images.githubusercontent.com/2046265/137897379-9d64af29-1670-4201-9624-db696d707739.png)
> 
> The displayed data have an amplitude difference of precisely 13 orders of magnitude.
> 
> cc @cbrnr @guiomar

---

<div class="post-metadata">

**Author:** ![Mukil](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@Mukil](https://mne.discourse.group/u/Mukil)\
**Post date:** [March 7, 2023, 11:53am UTC](https://mne.discourse.group/t/psd-different-units/3809/17 "2023-03-07T11:53:19Z")

</div>

what is the reference signal used when plotting PSD in `(microvolt)^2/Hz (dB)`? Since dB is a ratio of two power values on a log scale.

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [March 7, 2023, 12:38pm UTC](https://mne.discourse.group/t/psd-different-units/3809/18 "2023-03-07T12:38:11Z")

</div>

It’s probably just 1.

---

<div class="post-metadata">

**Author:** ![Mukil](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@Mukil](https://mne.discourse.group/u/Mukil)\
**Post date:** [March 7, 2023, 12:39pm UTC](https://mne.discourse.group/t/psd-different-units/3809/19 "2023-03-07T12:39:24Z")

</div>

I’m just asking to clarify. Is it 1 W?

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [March 7, 2023, 12:42pm UTC](https://mne.discourse.group/t/psd-different-units/3809/20 "2023-03-07T12:42:07Z")

</div>

1 of the same unit as the value in the numerator. In the original example, it should be 1 fT².
