The discrete wavelet transform (DWT) captures information in both the time and frequency domains. The mathematician Alfred Haar created the first wavelet. We will use this Haar wavelet in this recipe too. The transform returns approximation and detail coefficients, which we need to use together to get the original signal back. The approximation coefficients are the result of a low-pass filter. A high-pass filter produces the detail coefficients. The Haar wavelet algorithm is of order O(n) and, similar to the STFT algorithm (refer to the Analyzing the frequency spectrum of audio recipe), combines frequency and time information.
The difference with the Fourier transform is that we express the signal as a sum of sine and cosine terms, while the wavelet is represented by a single wave (wavelet function). Just as in the STFT, we split the signal in the time domain and then apply the wavelet function to each segment. The DWT can have multiple levels in this...