Continuous Wavelet Transform (CWT)#
- ptwt.cwt(data: Tensor, scales: ndarray | Tensor, wavelet: ContinuousWavelet | str, sampling_period: float = 1.0, precision: int = 12) tuple[Tensor, ndarray][source]#
Compute the single-dimensional continuous wavelet transform.
This function is a PyTorch port of pywt.cwt as found at: PyWavelets/pywt
- Parameters:
data (torch.Tensor) – The input tensor of shape
[batch_size, time].scales (torch.Tensor or np.array) – The wavelet scales to use. One can use
f = pywt.scale2frequency(wavelet, scale)/sampling_periodto determine what physical frequency,f. Here,fis in hertz when thesampling_periodis given in seconds.wavelet (ContinuousWavelet or str) – The continuous wavelet to work with.
sampling_period (float) – Sampling period for the frequencies output (optional). The values computed for
coefsare independent of the choice ofsampling_period(i.e.scalesis not scaled by the sampling period).precision (int) – Length of the wavelet used for the CWT.
- Raises:
ValueError – If a scale is too small for the input signal.
- Returns:
A tuple (out_tensor, frequencies). The first tuple-element contains the transformation matrix of shape
[scales, batch, time]. The second element contains an array with frequency information.
Example
>>> import torch, ptwt >>> import numpy as np >>> import scipy.signal as signal >>> t = np.linspace(-2, 2, 800, endpoint=False) >>> sig = signal.chirp(t, f0=1, f1=12, t1=2, method="linear") >>> widths = np.arange(1, 31) >>> cwtmatr, freqs = ptwt.cwt( >>> torch.from_numpy(sig), widths, "mexh", sampling_period=(4 / 800) * np.pi >>> )