What is the wavelet transform?

Wavelet transform is one of the most widely used transforms in signal processing. It is also used in data compression, pattern recognition, and more. It is also a solution to the shortcomings of the Fourier transform. Many machine learning applications use the wavelet transform as a preprocessing step.

Need for the wavelet transform

Fourier transform converts a signal from the time domain to the frequency domain. Classifiers can use a frequency spectrum generated by Fourier transform for better classification. But the drawback of Fourier transform is that it only works for stationary signals and most signals in the real world are not stationary. It can tell the frequency but not at which time it occurred.

This was overcome by introducing the short-time Fourier transform (STFT). In STFT, we divide the signal into windows and perform Fourier transform on these windows. The analysis is now dependent on the selection of window size. By fixing a window size, the frequency resolution decreases. The selection of window size had the following impacts:

  • A narrow window size will have good time resolution but result in bad frequency resolution.

  • Wider window size will have good frequency resolution but result in bad time resolution.

Wavelet transform

Wavelet transform allows us to analyze signals in different frequencies with different resolutions. For continuous signal f(t)f(t), continuous wavelet transform is given as:

Here,ssis the scale parameter which is equal to the reciprocal of the frequency. We use ψ\psi^*as the complex conjugate of the function ψ(t)\psi (t), which is a wavelet function. Wavelet transform uses a series of wavelet functions that are squished or exploded based on the parametersssandτ\tau. The wavelet ψ(t)\psi (t) is like a reference wavelet according to which other wavelets are created. It's like a small wave such as follows:

A plot of a wavelet
A plot of a wavelet

There are different kinds of wavelets, and depending on our choice of wavelets, the result will vary.

Time and frequency resolutions of STFT and wavelet transform are illustrated in the figure below:

Time and frequency resolutions of STFT and wavelet transform

Code

Here, we use the SciPy library to show the wavelet calculation.

import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
t = np.linspace(-1, 1, 200, endpoint=False)
data = np.cos(2*np.pi*8*t) + np.sin(2*np.pi*(t-2)) # signal in time domain
mother_wavelet = signal.ricker
widths = np.arange(1, 71)
transform = signal.cwt(data, mother_wavelet, widths)
plt.imshow(transform)
plt.savefig("./output/fig.png")

Explanation

  • Line 5: We define a time interval t with 200200entries in the range [1,1][-1, 1].

  • Line 7: We create a dummy signal using the time interval we defined earlier.

  • Line 8: We are using an in-built wavelet signal.ricker as the mother wavelet.

  • Line 9: We use widths to define how many different resolutions we want to generate.

  • Line 11: We are using SciPy's scipy.signal.cwt() function to calculate wavelet transform.

Applications

Wavelet transform is used in a number of applications. Some of them are as follows:

  • Data compression

  • Pattern recognition

  • Signal processing

  • ECG, EEG, and other medical applications

  • Speech recognition

  • Fingerprint verification

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved