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.
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 allows us to analyze signals in different frequencies with different resolutions. For continuous signal
Here,
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:
Here, we use the SciPy library to show the wavelet calculation.
import numpy as npfrom scipy import signalimport matplotlib.pyplot as pltt = 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 domainmother_wavelet = signal.rickerwidths = np.arange(1, 71)transform = signal.cwt(data, mother_wavelet, widths)plt.imshow(transform)plt.savefig("./output/fig.png")
Line 5: We define a time interval t
with
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.
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