how to calculate the shape of result of cwt?

78 views
Skip to first unread message

国强胡

unread,
Apr 2, 2023, 9:16:12 PM4/2/23
to PyWavelets
i use pywt.cwt to a data, which has sample rating:22050HZ, i get (128, 184989)
import pywt
import numpy as np
import matplotlib.pyplot as plt
import scipy.io.wavfile as wav

# 读取WAV数据
fs, data = wav.read("/content/drive/MyDrive/tacotron2-master/DUMMY/LJ001-0007.wav")

# 进行连续小波变换
cwtmatr, freqs = pywt.cwt(data, np.arange(1129), 'morl')

# 绘制时频图
plt.imshow(abs(cwtmatr), extent=[0len(data)/fs, freqs[-1], freqs[0]], cmap='PRGn', aspect='auto')
plt.colorbar()

plt.xlabel('Time (seconds)')
plt.ylabel('Frequency (Hz)')
plt.show()
print(cwtmatr.shape)
(128, 184989)

Deepu

unread,
May 22, 2023, 1:54:44 AM5/22/23
to PyWavelets

The result of the continuous wavelet transform (CWT) using `pywt.cwt` will have a shape `(scale_length, signal_length)`, where:

- `scale_length`: Number of scales used in the CWT. In your case, it is 128, as you used `np.arange(1, 129)` to specify the scales.
- `signal_length`: Length of the input signal.

In your example code, you are performing the CWT on an audio signal stored in the `data` variable, which has a length of `184989` samples. By specifying `np.arange(1, 129)` as the scales, you are using 128 different scales for the CWT.

Therefore, the resulting `cwtmatr` will have a shape of `(128, 184989)`.

You can verify the shape by printing `cwtmatr.shape`, as you did in your code. It will output `(128, 184989)`.

This shape represents the CWT coefficients at different scales and time points, providing a time-frequency representation of the input signal.
Reply all
Reply to author
Forward
0 new messages