〰️ Wavelet Transform — Haar & Daubechies

Decompose a signal with Discrete Wavelet Transform (DWT). Haar and Daubechies-4 filters split signal into approximation and detail coefficients. See multi-resolution analysis on the scalogram.

SignalsInteractive
Scalogram + coefficient rows · Toggle view to switch display

How it Works

The Discrete Wavelet Transform (DWT) applies a pair of filters — a low-pass scaling filter h and a high-pass wavelet filter g — to the signal, then downsamples by 2. Each level splits the previous approximation into a coarser approximation (cA) and a detail band (cD). This is Mallat's fast pyramid algorithm.

cA[n] = Σ h[k] · x[2n − k] (low-pass, downsample) cD[n] = Σ g[k] · x[2n − k] (high-pass, downsample) Haar: h = [1/√2, 1/√2], g = [−1/√2, 1/√2] DB4: h = [(1+√3)/4√2, (3+√3)/4√2, (3−√3)/4√2, (1−√3)/4√2]

The scalogram visualises wavelet coefficient magnitude as a heatmap over time and scale (level). The reconstruction (IDWT) is exact when all coefficients are retained.

Frequently Asked Questions

What is the Discrete Wavelet Transform?

The Discrete Wavelet Transform (DWT) decomposes a signal into approximation and detail coefficients at multiple resolution levels using scaling and wavelet functions.

How does the Haar wavelet work?

The Haar wavelet uses a simple averaging (low-pass) and differencing (high-pass) filter pair. It is the simplest orthogonal wavelet and splits the signal into coarse approximations and fine details.

What are Daubechies wavelets?

Daubechies wavelets (db2, db4, etc.) are compactly supported orthogonal wavelets with vanishing moments. They provide smoother decomposition than Haar, at the cost of slight phase shift.

What is multi-resolution analysis?

Multi-resolution analysis (MRA) decomposes a signal into nested subspaces at different scales, allowing simultaneous time-frequency localisation — something the Fourier transform cannot provide.

What is a scalogram?

A scalogram is a 2D plot of wavelet coefficient energy as a function of time and scale. Bright regions indicate large wavelet coefficients, revealing time-localised frequency content.

What is the difference between DWT and STFT?

The Short-Time Fourier Transform (STFT) uses a fixed window, giving uniform time-frequency resolution. The DWT uses variable-width wavelets: high frequency → narrow time window, low frequency → wide window.

What are vanishing moments?

A wavelet with N vanishing moments is orthogonal to polynomials of degree up to N-1. More vanishing moments mean smoother wavelets that compress smooth signals more efficiently.

How is the DWT used in JPEG 2000?

JPEG 2000 uses the Cohen-Daubechies-Feauveau 9/7 biorthogonal wavelet (CDF 9/7) for lossy compression, and the 5/3 wavelet for lossless compression, replacing the DCT used in JPEG.

What is coefficient thresholding?

Thresholding sets small wavelet detail coefficients to zero. Hard thresholding zeros all coefficients below a threshold; soft thresholding also shrinks large coefficients. Used for denoising.

Can the DWT be inverted exactly?

Yes. The Inverse DWT (IDWT) reconstructs the original signal exactly from approximation and detail coefficients using the conjugate mirror filters, provided no coefficients have been discarded or quantised.

About this simulation

This simulation runs Mallat's pyramid algorithm on a 256-sample synthetic signal, repeatedly convolving with a low-pass/high-pass filter pair and downsampling by 2 to peel off approximation and detail coefficients level by level. Switching between the Haar and Daubechies-4 filter banks, or between sine, chirp, step, and noisy signals, shows directly how filter smoothness and signal structure shape the resulting scalogram.

🔬 What it shows

The original waveform above a colour-coded scalogram whose rows are detail coefficient magnitudes at each decomposition level, or — after toggling view — stacked line plots of the approximation and each detail band separately.

🎮 How to use

Choose Haar or Daubechies-4 wavelet and a signal type from the dropdowns, drag the decomposition-levels and signal-frequency sliders, click Rebuild to recompute, and press Toggle View (or the I key) to flip between scalogram and coefficient-row display.

💡 Did you know?

Unlike the Fourier transform, which uses the same fixed window at every frequency, the wavelet transform's implicit window narrows automatically at high frequencies and widens at low ones — which is exactly why a Chirp signal (frequency rising over time) lights up different scalogram levels at different moments instead of smearing across the whole time axis.

Frequently asked questions

Why does switching to the Step Function signal light up so many detail levels at once?

A sharp discontinuity contains energy across a very wide range of frequencies, so the high-pass filter g extracts non-trivial detail coefficients right around the jump point at every decomposition level — this is exactly why the scalogram shows a bright vertical band at the step location cutting across all rows.

What's actually different between choosing Haar and Daubechies-4?

Haar's two-tap filter is just an averaging/differencing pair, so it reacts to abrupt changes instantly but produces blocky-looking detail coefficients; Daubechies-4's four-tap filter has more vanishing moments, giving smoother, more spread-out coefficients for the same signal — compare the two on the Sine Wave signal to see the visual difference in coefficient smoothness.

Why does "Energy (recon)" nearly match "Energy (orig)" in the stats panel?

Because Haar and Daubechies wavelets are orthogonal, Parseval's theorem guarantees the total energy split across the approximation and all detail bands equals the original signal's energy — the small numerical difference you see comes only from boundary-handling in the convolution, not from any information loss.

Why does increasing decomposition levels stop having an effect after a certain point?

Each level halves the approximation length via downsampling, and the loop in the code stops once the remaining approximation is too short to filter — so past roughly log₂(256)=8 levels there's nothing left to decompose, which is why the levels slider is capped well below that.

Why does a Noisy Sine signal still show a clear pattern in the low-level scalogram rows?

Random noise is spread roughly evenly across all frequencies and appears mostly in the finest detail level (highest row, shortest scale), while the sine wave's genuine periodic structure concentrates energy in the coarser levels that match its frequency — this separation by scale is the same principle wavelet denoising exploits.