Skip to content

Compute TFR with fmin=0Hz #5708

@cbrnr

Description

@cbrnr

Currently, tfr_morlet and tfr_multitaper throw an error if the minimum frequency is 0Hz:

/usr/local/lib/python3.7/site-packages/mne/time_frequency/tfr.py in morlet(sfreq, freqs, n_cycles, sigma, zero_mean)
     83         # this scaling factor is proportional to (Tallon-Baudry 98):
     84         # (sigma_t*sqrt(pi))^(-1/2);
---> 85         t = np.arange(0., 5. * sigma_t, 1.0 / sfreq)
     86         t = np.r_[-t[::-1], t[1:]]
     87         oscillation = np.exp(2.0 * 1j * np.pi * f * t)

ValueError: arange: cannot compute length

and

/usr/local/lib/python3.7/site-packages/mne/time_frequency/tfr.py in _make_dpss(sfreq, freqs, n_cycles, time_bandwidth, zero_mean)
    140 
    141             t_win = this_n_cycles / float(f)
--> 142             t = np.arange(0., t_win, 1.0 / sfreq)
    143             # Making sure wavelets are centered before tapering
    144             oscillation = np.exp(2.0 * 1j * np.pi * f * (t - t_win / 2.))

ValueError: arange: cannot compute length

FWIW, tfr_stockwell works fine with 0Hz.

Maybe I'm totally misunderstanding something, but I think it would be nice if TFRs started at DC, independent of the TFR method.

MWE to reproduce:

import numpy as np
import mne

sfreq = 128
n_epochs, n_ch, n_time = 144, 2, 1921
data = np.random.randn(n_epochs, n_ch, n_time)
info = mne.create_info(n_ch, sfreq, 'eeg')
epochs = mne.EpochsArray(data, info)

freqs = np.arange(0, 4)
mne.time_frequency.tfr_morlet(epochs, freqs, n_cycles=freqs / 2)  # throws error
mne.time_frequency.tfr_multitaper(epochs, freqs, n_cycles=freqs / 2)  # throws error
mne.time_frequency.tfr_stockwell(epochs, fmin=0, fmax=3)  # works

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions