spectrogram

spectrogram(line: BaseEpochs, freqs: ndarray, baseline: BaseEpochs = None, n_cycles: ndarray = None, pad: str = '0s', correction: str = 'ratio', verbose: int = None, **kwargs) AverageTFRArray[source][source]
spectrogram(line: BaseRaw, freqs: ndarray, line_event: str, tmin: float, tmax: float, base_event: str = None, base_tmin: float = None, base_tmax: float = None, n_cycles: ndarray = None, pad: str = '500ms', correction: str = 'ratio', **kwargs) AverageTFRArray

Calculate the multitapered, baseline corrected spectrogram

Parameters:
  • line (Epochs) – The data to be processed

  • freqs (array-like | None) – The frequencies at which to compute the power estimates. Must be an array of shape (n_freqs,). None (the default) only works when using __setstate__ and will raise an error otherwise.

  • baseline (Epochs) – The baseline to be used for correction

  • n_cycles (int | array of int, shape (n_freqs,)) – Number of cycles in the wavelet, either a fixed number or one per frequency. The number of cycles n_cycles and the frequencies of interest freqs define the temporal window length. See notes for additional information about the relationship between those arguments and about time and frequency smoothing.

  • pad (str) – The amount of padding to be removed in the spectrogram

  • correction (str) – The type of baseline correction to be used

  • verbose (bool | str | int | None) – Control verbosity of the logging output. If None, use the default verbosity level. See the logging documentation and mne.verbose() for details. Should only be passed as a keyword argument.

Return type:

AverageTFRArray

Notes

In MNE-Python’s multitaper functions, the frequency bandwidth is additionally affected by the parameter time_bandwidth. The n_cycles parameter determines the temporal window length based on the frequencies of interest: \(T = \frac{\mathtt{n\_cycles}}{\mathtt{freqs}}\). The time_bandwidth parameter defines the “time-bandwidth product”, which is the product of the temporal window length (in seconds) and the frequency bandwidth (in Hz). Thus once n_cycles has been set, frequency bandwidth is determined by \(\frac{\mathrm{time~bandwidth}}{\mathrm{time~window}}\), and thus passing a larger time_bandwidth value will increase the frequency bandwidth (thereby decreasing the frequency resolution).

The increased frequency bandwidth is reached by averaging spectral estimates obtained from multiple tapers. Thus, time_bandwidth also determines the number of tapers used. MNE-Python uses only “good” tapers (tapers with minimal leakage from far-away frequencies); the number of good tapers is floor(time_bandwidth - 1). This means there is another trade-off at play, between frequency resolution and the variance reduction that multitaper analysis provides. Striving for finer frequency resolution (by setting time_bandwidth low) means fewer tapers will be used, which undermines what is unique about multitaper methods — namely their ability to improve accuracy / reduce noise in the power estimates by using several (orthogonal) tapers.

Warning

In tfr_array_multitaper and tfr_multitaper, time_bandwidth defines the product of the temporal window length with the full frequency bandwidth For example, a full bandwidth of 4 Hz at a frequency of interest of 10 Hz will “smear” the frequency estimate between 8 Hz and 12 Hz.

This is not the case for psd_array_multitaper where the argument bandwidth defines the half frequency bandwidth. In the example above, the half-frequency bandwidth is 2 Hz.

Returns:

power – The multitapered, baseline corrected spectrogram

Return type:

AverageTFR

Parameters:

Examples using ieeg.timefreq.multitaper.spectrogram

Multitaper spectrogram plot

Multitaper spectrogram plot