Wavelets
pynapple.process.wavelets
Wavelets decomposition
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.
compute_wavelet_transform
compute_wavelet_transform(
sig,
freqs,
fs=None,
gaussian_width=1.5,
window_length=1.0,
precision=16,
norm="l1",
)
Compute the time-frequency representation of a signal using Morlet wavelets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sig |
Tsd or TsdFrame or TsdTensor
|
Time series. |
required |
freqs |
1d array
|
Frequency values to estimate with Morlet wavelets. |
required |
fs |
float or None
|
Sampling rate, in Hz. Defaults to |
None
|
gaussian_width |
float
|
Defines width of Gaussian to be used in wavelet creation. Default is 1.5. |
1.5
|
window_length |
float
|
The length of window to be used for wavelet creation. Default is 1.0. |
1.0
|
precision |
Precision of wavelet to use. Defines the number of timepoints to evaluate the Morlet wavelet at. Default is 16. |
16
|
|
norm |
(None, l1, l2)
|
Normalization method: - None - no normalization - 'l1' - (default) divide by the sum of amplitudes - 'l2' - divide by the square root of the sum of amplitudes |
None
|
Returns:
Type | Description |
---|---|
TsdFrame or TsdTensor
|
Time frequency representation of the input signal. |
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.
Source code in pynapple/process/wavelets.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
generate_morlet_filterbank
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:
Name | Type | Description | Default |
---|---|---|---|
freqs |
1d array
|
frequency values to estimate with Morlet wavelets. |
required |
fs |
float or int
|
Sampling rate, in Hz. |
required |
gaussian_width |
float
|
Defines width of Gaussian to be used in wavelet creation. |
1.5
|
window_length |
float
|
The length of window to be used for wavelet creation. |
1.0
|
precision |
Precision of wavelet to use. Defines the number of timepoints to evaluate the Morlet wavelet at. |
16
|
Returns:
Name | Type | Description |
---|---|---|
filter_bank |
TsdFrame
|
list of Morlet wavelet filters of the frequencies given |
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.
Source code in pynapple/process/wavelets.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|