pynapple.process.wavelets#
Functions to compute wavelets decomposition of a time series.
The main function for doing wavelet decomposition is nap.compute_wavelet_transform
For now, pynapple only implements Morlet wavelets. To check the shape and quality of the wavelets, check out the function nap.generate_morlet_filterbank to plot the wavelets.
Functions
|
Compute the time-frequency representation of a signal using Morlet wavelets. |
|
Generates a Morlet filterbank using the given frequencies and parameters. |
- pynapple.process.wavelets.compute_wavelet_transform(sig, freqs, fs=None, gaussian_width=1.5, window_length=1.0, precision=16, norm='l1')[source]#
Compute the time-frequency representation of a signal using Morlet wavelets.
- Parameters:
sig (pynapple.Tsd or pynapple.TsdFrame or pynapple.TsdTensor) – Time series.
freqs (1d array) – Frequency values to estimate with Morlet wavelets.
fs (float or None) – Sampling rate, in Hz. Defaults to sig.rate if None is given.
gaussian_width (float) – Defines width of Gaussian to be used in wavelet creation. Default is 1.5.
window_length (float) – The length of window to be used for wavelet creation. Default is 1.0.
precision (int.) – Precision of wavelet to use. Defines the number of timepoints to evaluate the Morlet wavelet at. Default is 16.
norm ({None, 'l1', 'l2'}, optional) – Normalization method: - None - no normalization - ‘l1’ - (default) divide by the sum of amplitudes - ‘l2’ - divide by the square root of the sum of amplitudes
- Returns:
Time frequency representation of the input signal.
- Return type:
pynapple.TsdFrame or pynapple.TsdTensor
Examples
>>> import numpy as np >>> import pynapple as nap >>> t = np.arange(0, 1, 1/1000) >>> signal = nap.Tsd(d=np.sin(t * 50 * np.pi * 2), t=t) >>> freqs = np.linspace(10, 100, 10) >>> mwt = nap.compute_wavelet_transform(signal, fs=1000, freqs=freqs)
Notes
This computes the continuous wavelet transform at specified frequencies across time.
- pynapple.process.wavelets.generate_morlet_filterbank(freqs, fs, gaussian_width=1.5, window_length=1.0, precision=16)[source]#
Generates a Morlet filterbank using the given frequencies and parameters.
This function can be used purely for visualization, or to convolve with a pynapple Tsd, TsdFrame, or TsdTensor as part of a wavelet decomposition process.
- Parameters:
freqs (1d array) – frequency values to estimate with Morlet wavelets.
fs (float or int) – Sampling rate, in Hz.
gaussian_width (float) – Defines width of Gaussian to be used in wavelet creation.
window_length (float) – The length of window to be used for wavelet creation.
precision (int.) – Precision of wavelet to use. Defines the number of timepoints to evaluate the Morlet wavelet at.
- Returns:
filter_bank – list of Morlet wavelet filters of the frequencies given
- Return type:
pynapple.TsdFrame
Notes
This algorithm first computes a single, finely sampled wavelet using the provided hyperparameters. Wavelets of different frequencies are generated by resampling this mother wavelet with an appropriate step size. The step size is determined based on the desired frequency and the sampling rate.