getting psds of wide range of frequency


  • MNE version: 1.0.3
  • operating system: macOS 11.1

I have continuous resting state EEG data of some subjects which were measured at one timepoint.

To see how different the power between 5 and 30 Hz is, I first compute FFT (with multitaper) ,

psds, freqs = psd_multitaper(preprocessed_raw, fmin=5, fmax=30, tmin=0, tmax=120)

then I want to concatenate ‘psds’ of all subjects and compute the average of psd between 5-30 Hz to visualize them, for example, with following plot at the end.

Screenshot 2022-10-14 at 13.54.59

However, the output “psds” have different shape depending on the data because of the different number of frequencies. For instance, when computing FFT between 5 and 30 Hz, psds is sometimes (n_channels, 3200) or (n_channels, 3010).
I’m looking for a solution to this problem so that psds of each subject can be concatenated without getting lag of frequency power across subjects…

I’d like to know whether there’s a good way to deal with that.
Thank you in advance!


Correct me if I’m wrong, to get the band power, e.g. 5 to 30 Hz, you need to integrate the spectral estimate (PSD) between those frequencies.

For instance, using simpson rule: scipy.integrate.simpson — SciPy v1.9.2 Manual

from scipy.integrate import simpson

# assumes MNE 1.2, else use the `psd_multitaper` and select fq manually
spectrum = raw.compute_psd(method="multitaper")
freq_res = spectrum.freqs[1] - spectrum.freqs[0]
data = spectrum.get_data(fmin=5, fmax=30)  # shape (n_channels, n_freqs)
bandpower = simpson(data, dx=freq_res, axis=-1)  # shape (n_channels,)

The integration will get rid of the mismatch between the n_freqs dimension.


1 Like

the reason you get a different number of frequency bins is that the multitaper method computes frequency bin values based on the length of the signal. To avoid this you could truncate all signals to the same length before estimating spectral power (if that is a reasonable thing to do, given your data / analysis).

As @mscheltienne says, for band power you can aggregate across bins even if the bin spacing is not identical for all files / subjects. When you’re dealing with 3000+ bins, I wouldn’t expect it to make much difference.

1 Like