You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible scaling error for 0 and Nyquist frequencies in multitaper spectra #14426
_psd_from_mt expects the coefficients for a one-sided spectra, and as such doubles the values of frequency bins. However, I would expect the 0 and Nyquist frequencies to be excluded from this, e.g., as in SciPy's spectrogram. Without the frequency bin info, _psd_from_mt just scales everything.
I tried to look for somewhere else where this might be accounted for, but nothing popped out. Apologies if I missed some other scaling in the MT spectra construction or something.
_mt_spectra has a normalization that might cancel (it divides DC bin by sqrt(2), and same for nyquist for even-length FFTs) so I think we might be okay?
@larsoner Okay yeah, that handles it. However, does this not create some inconsistency for output="complex"?
With output="power", the route is _mt_spectra (pre-downscales DC and Nyquist) → _psd_from_mt (one-sided scaling; cancels out DC and Nyquist downscaling) → output. With output="complex", the route is _mt_spectra → output, so DC and Nyquist have been downscaled alone.
This is also different to the Welch method (SciPy's spectrogram), where output="complex" returns DC, Nyquist, and one-sided freqs unscaled.
Is it worth undoing the DC and Nyquist scaling for output="complex" in the multitaper method for consistency with the established approach in SciPy's spectrogram?
Hmmm I think the way we do it makes more sense for our use case actually. With what we have now, you can scale all bins (including DC and nyquist) by a factor of 2 (during complex-to-power conversion when plotting/aggregating complex Spectrum data) and be correct without knowing what the frequencies actually are. So we "un-special" DC and Nyquist essentially. I'd lean toward keeping it and just documenting the convention in the output="complex" docstring.
I think the Welch "Scaling may be slightly off" comment in spectrum.py relates to this, and we should probably multiply the non-DC/non-Nyquist bins by 2 for consistency
I think the Welch "Scaling may be slightly off" comment in spectrum.py relates to this, and we should probably multiply the non-DC/non-Nyquist bins by 2 for consistency
Why scale the interior bins up and not downscale the DC and Nyquist bins? Doesn't that still leave an inconsistency between how users should handle the multitaper and Welch coefficients? I'm also thinking about MNE-Connectivity where we pass Welch coefficients to _psd_from_mt, just with dummy weights of ones. That relies on the interior bins not being scaled yet.
For consistency, would have everything use the current multitaper approach of pre-scaling DC and Nyquist for easier manipulation later. Would therefore need to make Welch behave the same. Should also add a note of this behaviour to the docs.
TFR should already take this pre-scaling approach for Nyquist (depending on odd/even bin count; no DC for TFR), but should check this to be sure.
hi @tsbinns@larsoner,
following up on the discussion and your consensus:
harmonizing welch's output="complex" with the multitaper convention (pre-scaling the dc and nyquist bins by $1/\sqrt{2}$) makes a lot of sense to me. it keeps downstream operations like complex-to-power conversion and cross-spectral density calculation clean and frequency-agnostic, with a uniform $\times 2$ factor. this also directly resolves the # scaling may be slightly off comment in spectrum.py (_prepare_data_for_plot).
i would be happy to take this on and prepare a pr that:
pre-scales the dc ($0\text{ Hz}$) and nyquist ($f_s / 2$) bins by $1/\sqrt{2}$ in psd_array_welch when output="complex".
updates the complex-to-power conversion in spectrum.py to include the $\times 2$ factor, so welch and multitaper align.
documents this convention clearly in the output="complex" docstrings across Spectrum and psd_array_*.
adds regression tests that check energy conservation / parseval consistency between output="complex" and output="power" for both welch and multitaper.
please let me know if it is okay for me to open a pr for this!
Thanks for letting me know @tsbinns! Glad to see it's already being addressed in #14574. I'll take a look at the PR and help test/review there if useful!
Activity
badrisatyam1-ctrl commentedon Oct 17, 2026
Hi @tsbinns,
I can reproduce this / I’d like to work on a fix, is that okay?
tsbinns commentedon Oct 18, 2026
@badrisatyam1-ctrl Thanks for your interest. It's probably worth just confirming with @larsoner or @drammock first whether this is expected behaviour.
larsoner commentedon Oct 22, 2026
_mt_spectrahas a normalization that might cancel (it divides DC bin by sqrt(2), and same for nyquist for even-length FFTs) so I think we might be okay?tsbinns commentedon Nov 4, 2026
@larsoner Okay yeah, that handles it. However, does this not create some inconsistency for
output="complex"?With
output="power", the route is_mt_spectra(pre-downscales DC and Nyquist) →_psd_from_mt(one-sided scaling; cancels out DC and Nyquist downscaling) → output. Withoutput="complex", the route is_mt_spectra→ output, so DC and Nyquist have been downscaled alone.This is also different to the Welch method (SciPy's spectrogram), where
output="complex"returns DC, Nyquist, and one-sided freqs unscaled.Is it worth undoing the DC and Nyquist scaling for
output="complex"in the multitaper method for consistency with the established approach in SciPy's spectrogram?larsoner commentedon Nov 4, 2026
Hmmm I think the way we do it makes more sense for our use case actually. With what we have now, you can scale all bins (including DC and nyquist) by a factor of 2 (during complex-to-power conversion when plotting/aggregating complex Spectrum data) and be correct without knowing what the frequencies actually are. So we "un-special" DC and Nyquist essentially. I'd lean toward keeping it and just documenting the convention in the
output="complex"docstring.I think the Welch "Scaling may be slightly off" comment in
spectrum.pyrelates to this, and we should probably multiply the non-DC/non-Nyquist bins by 2 for consistencytsbinns commentedon Nov 4, 2026
Why scale the interior bins up and not downscale the DC and Nyquist bins? Doesn't that still leave an inconsistency between how users should handle the multitaper and Welch coefficients? I'm also thinking about MNE-Connectivity where we pass Welch coefficients to
_psd_from_mt, just with dummy weights of ones. That relies on the interior bins not being scaled yet.tsbinns commentedon Nov 18, 2026
Discussed in call w/ @larsoner.
For consistency, would have everything use the current multitaper approach of pre-scaling DC and Nyquist for easier manipulation later. Would therefore need to make Welch behave the same. Should also add a note of this behaviour to the docs.
TFR should already take this pre-scaling approach for Nyquist (depending on odd/even bin count; no DC for TFR), but should check this to be sure.
ishaaaan17 commentedon Nov 20, 2026
hi @tsbinns @larsoner,$1/\sqrt{2}$ ) makes a lot of sense to me. it keeps downstream operations like complex-to-power conversion and cross-spectral density calculation clean and frequency-agnostic, with a uniform $\times 2$ factor. this also directly resolves the
following up on the discussion and your consensus:
harmonizing welch's
output="complex"with the multitaper convention (pre-scaling the dc and nyquist bins by# scaling may be slightly offcomment inspectrum.py(_prepare_data_for_plot).i would be happy to take this on and prepare a pr that:
psd_array_welchwhenoutput="complex".spectrum.pyto include theoutput="complex"docstrings acrossSpectrumandpsd_array_*.output="complex"andoutput="power"for both welch and multitaper.please let me know if it is okay for me to open a pr for this!
tsbinns commentedon Nov 20, 2026
Hi @ishaaaan17, thanks for the interest, but a PR has already been opened in #14574 addressing this.
ishaaaan17 commentedon Nov 20, 2026
Thanks for letting me know @tsbinns! Glad to see it's already being addressed in #14574. I'll take a look at the PR and help test/review there if useful!