Wavelets and Time-Frequency Analysis

Beyond Fourier: Adaptive Time-Frequency Analysis

The STFT uses a fixed window, giving the same time-frequency resolution everywhere. Wavelets overcome this limitation by using short windows at high frequencies and long windows at low frequencies, naturally matching the behavior of many real-world signals (transients are brief and wideband, while tonal components are long and narrowband). The wavelet transform is the foundation of JPEG 2000 compression, denoising algorithms, and multi-resolution signal analysis.

Definition:

Continuous Wavelet Transform (CWT)

The CWT of a signal x(t)x(t) with respect to a mother wavelet ψ(t)\psi(t) is:

W(a,b)=1∣aβˆ£βˆ«βˆ’βˆžβˆžx(t)β€‰Οˆβˆ—β€‰β£(tβˆ’ba)dtW(a, b) = \frac{1}{\sqrt{|a|}} \int_{-\infty}^{\infty} x(t)\, \psi^*\!\left(\frac{t-b}{a}\right) dt

where aa is the scale (inversely related to frequency) and bb is the translation (time shift). The factor 1/∣a∣1/\sqrt{|a|} ensures energy normalization across scales.

import pywt
scales = np.arange(1, 128)
coeffs, freqs = pywt.cwt(x, scales, 'morl', sampling_period=1/fs)

Definition:

Discrete Wavelet Transform (DWT)

The DWT decomposes a signal into approximation coefficients (low frequency) and detail coefficients (high frequency) at each level using a pair of complementary filters:

cA[n]=βˆ‘kx[k] ϕ~[2nβˆ’k](lowpass)c_A[n] = \sum_k x[k]\, \tilde{\phi}[2n - k] \quad \text{(lowpass)} cD[n]=βˆ‘kx[k]β€‰Οˆ~[2nβˆ’k](highpass)c_D[n] = \sum_k x[k]\, \tilde{\psi}[2n - k] \quad \text{(highpass)}

followed by downsampling by 2.

import pywt
cA, cD = pywt.dwt(x, 'db4')     # single-level DWT
coeffs = pywt.wavedec(x, 'db4', level=5)  # multi-level DWT
x_rec = pywt.waverec(coeffs, 'db4')       # reconstruction

The DWT is critically sampled (no redundancy) and perfectly invertible. Each level halves the time resolution and doubles the frequency resolution.

Definition:

Common Wavelet Families

Different wavelet families have different properties:

Family PyWavelets Name Vanishing Moments Properties
Haar 'haar' 1 Simplest, discontinuous
Daubechies 'db1'-'db20' 1-20 Compact support, smooth for high order
Symlets 'sym2'-'sym20' 2-20 Near-symmetric Daubechies
Coiflets 'coif1'-'coif17' 2-34 Symmetric, vanishing moments for scaling fn
Morlet 'morl' ∞\infty CWT only, Gaussian-modulated sinusoid
Mexican Hat 'mexh' 2 CWT only, second derivative of Gaussian
wavelet = pywt.Wavelet('db4')
print(f"Filter length: {wavelet.dec_len}")
print(f"Vanishing moments: {wavelet.dec_len // 2}")

Definition:

Multi-Resolution Analysis (MRA)

Multi-resolution analysis decomposes a signal into components at different resolution levels. At level jj, the signal is represented as:

x(t)=βˆ‘kcJ,k ϕJ,k(t)+βˆ‘j=1Jβˆ‘kdj,kβ€‰Οˆj,k(t)x(t) = \sum_k c_{J,k}\, \phi_{J,k}(t) + \sum_{j=1}^{J} \sum_k d_{j,k}\, \psi_{j,k}(t)

where Ο•j,k\phi_{j,k} and ψj,k\psi_{j,k} are scaled and translated versions of the scaling and wavelet functions. Each level captures a specific frequency band:

  • Level 1 details: [fs/4,fs/2][f_s/4, f_s/2]
  • Level 2 details: [fs/8,fs/4][f_s/8, f_s/4]
  • Level jj details: [fs/2j+1,fs/2j][f_s/2^{j+1}, f_s/2^j]

Definition:

Wavelet Denoising (Thresholding)

Wavelet denoising exploits the fact that signal energy concentrates in a few large wavelet coefficients, while noise spreads across all coefficients. The procedure is:

  1. Compute the DWT: coeffs=wavedec(x,wavelet,level)\text{coeffs} = \text{wavedec}(x, \text{wavelet}, \text{level})
  2. Threshold the detail coefficients
  3. Reconstruct: x^=waverec(coeffs,wavelet)\hat{x} = \text{waverec}(\text{coeffs}, \text{wavelet})

Common thresholding rules:

  • Hard: d^=dβ‹…1∣d∣>Ξ»\hat{d} = d \cdot \mathbf{1}_{|d| > \lambda}
  • Soft: d^=sign(d)β‹…max⁑(∣dβˆ£βˆ’Ξ»,0)\hat{d} = \text{sign}(d) \cdot \max(|d| - \lambda, 0)

Universal threshold: Ξ»=Οƒ2ln⁑N\lambda = \sigma \sqrt{2 \ln N} where Οƒ=MAD(d1)/0.6745\sigma = \text{MAD}(d_1) / 0.6745 (median absolute deviation of level-1 detail coefficients).

Theorem: Perfect Reconstruction in the DWT

If the analysis filters (h0,h1)(h_0, h_1) and synthesis filters (h~0,h~1)(\tilde{h}_0, \tilde{h}_1) satisfy the perfect reconstruction conditions:

H~0(z)H0(z)+H~1(z)H1(z)=2\tilde{H}_0(z) H_0(z) + \tilde{H}_1(z) H_1(z) = 2 H~0(z)H0(βˆ’z)+H~1(z)H1(βˆ’z)=0\tilde{H}_0(z) H_0(-z) + \tilde{H}_1(z) H_1(-z) = 0

then the DWT followed by the inverse DWT recovers the original signal exactly (up to floating-point precision).

The first condition ensures no gain distortion (the signal energy is preserved). The second condition ensures no aliasing (the downsampling artifacts from the analysis stage are exactly cancelled during synthesis).

Example: Multi-Level DWT Decomposition

Decompose a noisy ECG-like signal into 5 levels using the Daubechies-4 wavelet. Examine the detail coefficients at each level.

Example: Wavelet Denoising with Soft Thresholding

Add Gaussian noise to a piecewise-smooth signal and denoise it using soft thresholding with the universal threshold.

Example: CWT Scalogram of a Non-Stationary Signal

Generate a signal with a chirp component and a transient burst. Compute the CWT using the Morlet wavelet and display the scalogram.

Wavelet Denoising Explorer

Adjust the wavelet family, decomposition level, and threshold to observe the effect on denoising quality.

Parameters

Wavelet Transform Recipes

python
Complete examples: DWT/CWT, wavelet families, multi-resolution analysis, denoising with hard/soft thresholding, scalograms.
# Code from: ch07/python/wavelets.py
# Load from backend supplements endpoint

Quick Check

What is the key advantage of the wavelet transform over the STFT?

Wavelets are always faster to compute

Wavelets provide adaptive time-frequency resolution

Wavelets can analyze non-stationary signals while STFT cannot

Wavelets require fewer parameters to configure

Quick Check

In wavelet denoising, the universal threshold Ξ»=Οƒ2ln⁑N\lambda = \sigma\sqrt{2\ln N} is estimated using:

The standard deviation of the original signal

The median absolute deviation of the finest-scale detail coefficients

The mean of all wavelet coefficients

The peak value of the approximation coefficients

Common Mistake: Ignoring Boundary Effects in the DWT

Mistake:

Applying the DWT to a short signal without considering boundary extension. The default mode in PyWavelets is 'symmetric', which can introduce artifacts for signals that are not symmetric at the boundaries.

Correction:

Choose the boundary mode appropriate for your signal:

coeffs = pywt.wavedec(x, 'db4', mode='periodization')  # periodic signals
coeffs = pywt.wavedec(x, 'db4', mode='zero')           # zero-padded

Key Takeaway

Wavelets provide adaptive time-frequency resolution: fine time resolution at high frequencies and fine frequency resolution at low frequencies. The DWT is fast (O(N)O(N)), critically sampled, and perfectly invertible. Wavelet denoising with soft thresholding is near-optimal for piecewise-smooth signals.

Why This Matters: Wavelets in Wireless Channel Estimation

Wireless channels often exhibit sparse multipath structure: a few strong reflections arriving at specific delays. Wavelet-based channel estimation exploits this sparsity by decomposing the channel impulse response with the DWT and thresholding small coefficients. This approach denoises the channel estimate without blurring the sharp multipath arrivals, outperforming linear smoothing filters that assume continuous channel variation.

See full treatment in Chapter 18

Historical Note: Wavelets: From Seismology to JPEG 2000

1980s

Jean Morlet, a French geophysicist, introduced wavelets in the early 1980s for analyzing seismic data. Ingrid Daubechies constructed the first families of compactly supported orthogonal wavelets in 1988, making the DWT practical. Stephane Mallat connected wavelets to multi-resolution analysis in 1989. Today wavelets are used in JPEG 2000 image compression, FBI fingerprint compression, and numerous scientific applications.

CWT (Continuous Wavelet Transform)

A time-frequency representation that correlates a signal with scaled and translated versions of a mother wavelet, providing adaptive resolution across frequencies.

Related: Discrete Wavelet Transform (DWT), Scalogram

DWT (Discrete Wavelet Transform)

A critically-sampled wavelet transform that decomposes a signal into approximation and detail coefficients at dyadic scales using complementary lowpass and highpass filters.

Related: Continuous Wavelet Transform (CWT), multi-resolution analysis

Scalogram

The squared magnitude of the CWT coefficients, ∣W(a,b)∣2|W(a,b)|^2, displayed as a 2D image with time on the horizontal axis and scale (or frequency) on the vertical axis.

Related: Continuous Wavelet Transform (CWT), Spectrogram

STFT vs Wavelet Transform

PropertySTFTWavelet Transform
Time-Frequency ResolutionFixed (set by window length)Adaptive (varies with frequency)
Basis FunctionsComplex exponentials Γ—\times windowScaled/translated wavelets
RedundancyAdjustable (overlap)CWT: highly redundant; DWT: critically sampled
Computational CostO(Nlog⁑N)O(N \log N) per frameDWT: O(N)O(N); CWT: O(Nβ‹…S)O(N \cdot S)
Best ForStationary or slowly varying signalsTransients, multi-scale analysis, denoising
InvertibilityAlways (with overlap-add)DWT: perfect reconstruction; CWT: depends on wavelet