What is the equivalent of Matlab's cwt() in Python? (continuous 1-D wavelet transform)

You will probably want to use scipy.signal.cwt. Some wavelet functions are provided in the scipy.signal package:

  • Daubechies family: scipy.signal.daub(1)
  • Morlet: scipy.signal.morlet
  • Ricker: scipy.signal.ricker

Symlets do not appear to be provided as-such, but you may be able to get them from daub.


It seems like there are a few python libraries out there for Wavelet operations beyond scipy:

Pywavelets

Here's a link to the documentation, github and a basic snippet for usage. It's pretty intuitive to use and has a pretty extended library of implemented wavelets.

import pywt
import numpy as np
import matplotlib.pyplot as plt

num_steps = 512
x = np.arange(num_steps)
y = np.sin(2*np.pi*x/32)

delta_t = x[1] - x[0]
scales = np.arange(1,num_steps+1)
wavelet_type = 'morl'
coefs, freqs = pywt.cwt(y, scales, wavelet_type, delta_t)
plt.matshow(coefs) 
plt.show()

PyCWT

Here's a link to the documentation, github and a basic snippet for usage. This library has a steeper learning curve and the api is not as nice, but supports functionalities such as cone of influence or significance testing.

import pycwt as wavelet
import numpy as np
import matplotlib.pyplot as plt

num_steps = 512
x = np.arange(num_steps)
y = np.sin(2*np.pi*x/32)

delta_t = x[1] - x[0]
scales = np.arange(1,num_steps+1)
freqs = 1/(wavelet.Morlet().flambda() * scales)
wavelet_type = 'morlet'

coefs, scales, freqs, coi, fft, fftfreqs = wavelet.cwt(y, delta_t, wavelet=wavelet_type, freqs=freqs)
plt.matshow(coefs.real)
plt.show()

You can easily install them using pip or conda.

Finally, here's other references that I haven't tried using:

  1. one
  2. two
  3. three