mne.time_frequency.tfr_array_multitaper#
- mne.time_frequency.tfr_array_multitaper(data, sfreq, freqs, n_cycles=7.0, zero_mean=True, time_bandwidth=4.0, use_fft=True, decim=1, output='complex', n_jobs=None, *, return_weights=False, verbose=None)[source]#
Compute Time-Frequency Representation (TFR) using DPSS tapers.
Same computation as
tfr_multitaper, but operates onNumPy arraysinstead ofEpochsorEvokedobjects.- Parameters:
- data
arrayof shape (n_epochs, n_channels, n_times) The epochs.
- sfreq
float Sampling frequency of the data in Hz.
- freqs
ndarray, shape (n_freqs,) The frequencies in Hz.
- n_cycles
int|arrayofint, shape (n_freqs,) Number of cycles in the wavelet, either a fixed number or one per frequency. The number of cycles
n_cyclesand the frequencies of interestfreqsdefine the temporal window length. See notes for additional information about the relationship between those arguments and about time and frequency smoothing.- zero_meanbool
If True, make sure the wavelets have a mean of zero. Defaults to True.
- time_bandwidth
float≥ 2.0 Product between the temporal window length (in seconds) and the full frequency bandwidth (in Hz). This product can be seen as the surface of the window on the time/frequency plane and controls the frequency bandwidth (thus the frequency resolution) and the number of good tapers. See notes for additional information.
- use_fftbool
Use the FFT for convolutions or not. Defaults to True.
- decim
int|slice Decimation factor, applied after time-frequency decomposition.
if
int, returnstfr[..., ::decim](keep only every Nth sample along the time axis).if
slice, returnstfr[..., decim](keep only the specified slice along the time axis).
Note
Decimation is done after convolutions and may create aliasing artifacts.
- output
str, default ‘complex’ 'complex': single trial per taper complex values.'power': single trial power.'phase': single trial per taper phase.'avg_power': average of single trial power.'itc': inter-trial coherence.'avg_power_itc': average of single trial power and inter-trial coherence across trials.
- n_jobs
int|None The number of jobs to run in parallel. If
-1, it is set to the number of CPU cores. Requires thejoblibpackage.None(default) is a marker for ‘unset’ that will be interpreted asn_jobs=1(sequential execution) unless the call is performed under ajoblib.parallel_configcontext manager that sets another value forn_jobs. The parallelization is implemented across channels.- return_weightsbool, default
False If True, return the taper weights. Only applies if
output='complex'or'phase'.New in v1.10.0.
- verbosebool |
str|int|None Control verbosity of the logging output. If
None, use the default verbosity level. See the logging documentation andmne.verbose()for details. Should only be passed as a keyword argument.
- data
- Returns:
- out
array Time frequency transform of
data.if
output in ('complex',' 'phase'), array of shape(n_epochs, n_chans, n_tapers, n_freqs, n_times)if
outputis'power', array of shape(n_epochs, n_chans, n_freqs, n_times)else, array of shape
(n_chans, n_freqs, n_times)
If
outputis'avg_power_itc', the real values inoutcontain the average power and the imaginary values contain the inter-trial coherence: \(out = power_{avg} + i * ITC\).- weights
arrayof shape (n_tapers, n_freqs) The taper weights. Only returned if
output='complex'or'phase'andreturn_weights=True.
- out
See also
Notes
In spectrotemporal analysis (as with traditional fourier methods), the temporal and spectral resolution are interrelated: longer temporal windows allow more precise frequency estimates; shorter temporal windows “smear” frequency estimates while providing more precise timing information.
Time-frequency representations are computed using a sliding temporal window. Either the temporal window has a fixed length independent of frequency, or the temporal window decreases in length with increased frequency.
Figure: Time and frequency smoothing. (a) For a fixed length temporal window the time and frequency smoothing remains fixed. (b) For temporal windows that decrease with frequency, the temporal smoothing decreases and the frequency smoothing increases with frequency. Source: FieldTrip tutorial: Time-frequency analysis using Hanning window, multitapers and wavelets.
In MNE-Python, the multitaper temporal window length is defined by the arguments
freqsandn_cycles, respectively defining the frequencies of interest and the number of cycles: \(T = \frac{\mathtt{n\_cycles}}{\mathtt{freqs}}\)A fixed number of cycles for all frequencies will yield a temporal window which decreases with frequency. For example,
freqs=np.arange(1, 6, 2)andn_cycles=2yieldsT=array([2., 0.7, 0.4]).To use a temporal window with fixed length, the number of cycles has to be defined based on the frequency. For example,
freqs=np.arange(1, 6, 2)andn_cycles=freqs / 2yieldsT=array([0.5, 0.5, 0.5]).In MNE-Python’s multitaper functions, the frequency bandwidth is additionally affected by the parameter
time_bandwidth. Then_cyclesparameter determines the temporal window length based on the frequencies of interest: \(T = \frac{\mathtt{n\_cycles}}{\mathtt{freqs}}\). Thetime_bandwidthparameter defines the “time-bandwidth product”, which is the product of the temporal window length (in seconds) and the frequency bandwidth (in Hz). Thus oncen_cycleshas been set, frequency bandwidth is determined by \(\frac{\mathrm{time~bandwidth}}{\mathrm{time~window}}\), and thus passing a largertime_bandwidthvalue 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_bandwidthalso 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 isfloor(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 settingtime_bandwidthlow) 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_multitaperandtfr_multitaper,time_bandwidthdefines 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_multitaperwhere the argumentbandwidthdefines the half frequency bandwidth. In the example above, the half-frequency bandwidth is 2 Hz.New in v0.14.0.