Skip to main content

MorletTfr

Namespace: RTPROCESSINGLIB  ·  Library: DSP Library

Python equivalent

mne.time_frequency.tfr_morlet in MNE-Python.

#include <dsp/morlet_tfr.h>

class UTILSLIB::MorletTfr

Complex Morlet wavelet time-frequency representation.

For each requested centre frequency f the signal is convolved (via FFT) with a complex Morlet wavelet whose time-domain standard deviation is σ_t = nCycles / (2π·f) The instantaneous power at every time sample is |convolution|².

src/examples/ex_dsp_spectral/main.cpp
RowVectorXd morletFreqs(3);
morletFreqs << 20.0, 35.0, 55.0;
const MorletTfrResult morlet = MorletTfr::compute(signal, kSFreq, morletFreqs, 7.0);

Static Methods​

compute(vecData, dSFreq, vecFreqs, dNCycles)​

Compute Morlet TFR for a single channel time series.

Parameters:

  • vecData : const Eigen::RowVectorXd & Single-channel data row vector (1 × n_samples).

  • dSFreq : double Sampling frequency in Hz.

  • vecFreqs : const Eigen::RowVectorXd & Centre frequencies in Hz (row vector).

  • dNCycles : double Number of wavelet cycles (controls time–frequency trade-off; default 7).

Returns:


computeMultiChannel(matData, dSFreq, vecFreqs, dNCycles, vecPicks)​

Compute Morlet TFR for every (selected) channel of a data matrix.

Parameters:

  • matData : const Eigen::MatrixXd & Data matrix (n_channels × n_samples).

  • dSFreq : double Sampling frequency in Hz.

  • vecFreqs : const Eigen::RowVectorXd & Centre frequencies in Hz.

  • dNCycles : double Number of wavelet cycles (default 7).

  • vecPicks : const Eigen::RowVectorXi & Channel row indices; empty = all channels.

Returns:


buildWavelet(dFreq, dSFreq, dNCycles, halfLen, bZeroMean)​

Build a complex Morlet wavelet for a given frequency, as mne.time_frequency.morlet does: sampled out to 5 σ_t on either side of a sample at t = 0 and scaled to norm √2.

Parameters:

  • dFreq : double Centre frequency in Hz.

  • dSFreq : double Sampling frequency in Hz.

  • dNCycles : double Number of cycles.

  • halfLen : int & Half-length of the returned wavelet in samples.

  • bZeroMean : bool Subtract the admissibility offset (zero_mean in MNE-Python).

Returns:

  • Eigen::VectorXcd — Complex wavelet column vector of length 2·halfLen+1.

Example​

Used in examples​

ex_dsp_spectral​

Spectral and filtering tools of the dsp library on signals with known content.

src/examples/ex_dsp_spectral/main.cpp, line 152
RowVectorXd morletFreqs(3);
morletFreqs << 20.0, 35.0, 55.0;
const MorletTfrResult morlet = MorletTfr::compute(signal, kSFreq, morletFreqs, 7.0);
const VectorXd middle = morlet.matPower.col(n / 2);
// Power of a sine of amplitude A is ~ A^2 times a common wavelet gain: 20 Hz carries 4x the 55 Hz power
ok &= expect(middle(0) > 3.0 * middle(2) && middle(2) > 10.0 * middle(1),
QString("Morlet power at 20/35/55 Hz: %1 / %2 / %3").arg(middle(0)).arg(middle(1)).arg(middle(2)));

Authors of this file​