How to increase the resolution?

  • MNE version: `1.2
  • operating system: Windows 11
    For the following function with sfreq = 2500, and tmin = 0.5 with tmax =4 seconds. I want to calculate the psds of the epochs object with a higher resolution. Currently, the wrapper function called compute_psd for the EpochsSpectrum(
    self, method=method, fmin=fmin, fmax=fmax, tmin=tmin, tmax=tmax,
    picks=picks, proj=proj, n_jobs=n_jobs, verbose=verbose,
    object is called. The current frequency resolution I achieve is 0.2857 between the returned frequencies. I want to increase this to 0.05. Does anybody know how I can change my parameters on how to do this or an interpolation method?
 tmin = 0.5
        tmax = 4.
        fmin = 1.
        fmax = 90.

        # get the sampling frequency
        sfreq =['sfreq']

        spectrum = epochs.compute_psd(
            n_fft=int(sfreq * (tmax - tmin)),
            n_overlap=0, n_per_seg=None,
            tmin=tmin, tmax=tmax,
            fmin=fmin, fmax=fmax,
        psds, freqs = spectrum.get_data(return_freqs=True)

Best regards,


Hi @Sjoerd .

In short, your frequency resolution can be calculated by 1 / [your window size in seconds]. If you are calculating the PSD on your full epoch, then the window size is the same as your epoch length.

In that scenario, if your epochs are 1-second:
1 / 1 # equals 1 (Hz frequeny resolution)
2 seconds…
1 / 2 # equals 0.5 (Hz frequency resolution)
4 seconds …
1 / 4 # equals 0.25 (Hz frequency resolution)
20 seconds…
1 / 20 # equals 0.05 (Hz frequency resolution)

But with the welch method, which you are using, the n_fft parameter sets the window size (in samples)…

So in your example with a 2500Hz sfreq, n_fft=(2500 * (4 - 0.5)) , or 8,750 samples.

If we convert samples to seconds so we can use the calculation introduced above…
# convert samples to seconds.. FYI .0004 is the sampling interval (in seconds) for 2,500Hz
8,750 * .0004 # equals 3.5 (seconds window size).

and finally…
1 / 3.5 = 0.2857
This is why your frequency resolution is 0.2587.

To answer your question, your window size effectively needs to be 20 seconds to achieve a 0.05Hz frequency resolution… so given your example, you’d need to epoch your data into 20.5 seconds chunks, so that int(2500 * (20.5 - .5)) will give you a 20 second window size.

With that being said, a 0.05Hz frequency resolution seems unnecessarily precise to me. And typically, you set your window size to be long enough to encompass two full cycles of the lowest frequency of interest… So if the lowest frequency you want to calculate power for is 1Hz… Your window size would be 2-seconds.

this thread might also help you.