gastropy.morlet_tfr

Contents

gastropy.morlet_tfr#

gastropy.morlet_tfr(data, sfreq, freqs, n_cycles=7)[source]#

Compute time-frequency power using Morlet wavelet convolution.

For each target frequency, constructs a complex Morlet wavelet and convolves it with the input signal to produce an instantaneous power estimate. This is a pure scipy implementation equivalent to MNE’s tfr_array_morlet with output='power'.

Parameters:
  • data (array_like) – Input signal (1D array).

  • sfreq (float) – Sampling frequency in Hz.

  • freqs (array_like) – Frequencies of interest in Hz.

  • n_cycles (float or array_like, optional) – Number of cycles in each Morlet wavelet. Controls the time-frequency trade-off: more cycles give better frequency resolution but worse time resolution. A scalar value applies the same number of cycles to all frequencies; an array allows per-frequency control. Default is 7.

Returns:

  • freqs (np.ndarray) – Frequency values in Hz (same as input).

  • times (np.ndarray) – Time values in seconds, length n_samples.

  • power (np.ndarray, shape (n_freqs, n_samples)) – Instantaneous power at each frequency and time point.

Examples

>>> import numpy as np
>>> from gastropy.timefreq import morlet_tfr
>>> t = np.arange(0, 300, 0.1)  # 300s at 10 Hz
>>> sig = np.sin(2 * np.pi * 0.05 * t)
>>> freqs, times, power = morlet_tfr(sig, sfreq=10.0,
...     freqs=np.arange(0.02, 0.1, 0.005))