mne_denoise.qa.spectral_distortion#

mne_denoise.qa.spectral_distortion(freqs: ndarray, psd_before: ndarray, psd_after: ndarray, line_freq: float = 50.0, n_harmonics: int = 3, bandwidth: float = 2.0) float[source]#

Spectral distortion (dB RMS) at non-harmonic frequencies.

This measures how much the cleaning process changed the spectrum outside of the target line-noise frequencies.

Parameters:
  • freqs (array of shape (n_freqs,)) – Frequency vector.

  • psd_before (array) – PSDs before and after cleaning.

  • psd_after (array) – PSDs before and after cleaning.

  • line_freq (float) – Fundamental line frequency (Hz).

  • n_harmonics (int) – Number of harmonics to exclude.

  • bandwidth (float) – Base exclusion bandwidth (Hz).

Returns:

distortion – RMS distortion in dB.

Return type:

float

Notes

This is an RMS variant of broadband distortion using channel-averaged PSDs. Evaluation is restricted to 2-160 Hz and excludes line-frequency harmonics.

Examples

>>> import numpy as np
>>> from mne_denoise.qa import spectral_distortion
>>> freqs = np.arange(0, 200, 0.5)
>>> psd = np.ones((2, len(freqs)))
>>> spectral_distortion(freqs, psd, psd, line_freq=50.0, n_harmonics=3)
0.0