Daubechies-4 Wavelet Simulator Back
Signal Processing Simulator

Daubechies-4 Wavelet Simulator — db4 Multiresolution Analysis

Multi-level db4 decomposition of 1D signals. Threshold detail coefficients to compress, then compare the reconstructed signal against the original — and see how db4 beats Haar on smooth signals.

Parameters
Samples N=2^k
Decomposition level L
Detail-coefficient threshold
Signal type (0=sine, 1=step, 2=gaussian peak)

N is auto-rounded to the nearest power of two (e.g. 250 → 256). Boundaries are handled with periodic (cyclic) convolution.

Results
256
Samples N=2^k
4
Decomposition level L
Non-zero coefficients after threshold
Reconstruction MSE
Signal, coefficients, reconstruction

Top to bottom: original x[n] / approximation a^(L)[n] / per-level detail d^(L)[n] / reconstructed x_rec[n]

Theory & Key Formulas

Daubechies-4 scaling coefficients $h_k$ and matching wavelet coefficients $g_k = (-1)^k h_{3-k}$:

$$h_0 = \frac{1+\sqrt3}{4\sqrt2},\ h_1 = \frac{3+\sqrt3}{4\sqrt2},\ h_2 = \frac{3-\sqrt3}{4\sqrt2},\ h_3 = \frac{1-\sqrt3}{4\sqrt2}$$

One-level decomposition (periodic convolution + downsample by 2) with approximation $a$, detail $d$, signal $x$, filter length $K=4$:

$$a[i] = \sum_{k=0}^{3} h_k\,x[(2i+k)\bmod N], \qquad d[i] = \sum_{k=0}^{3} g_k\,x[(2i+k)\bmod N]$$

Orthogonality $\sum h_k^2=1,\ \sum g_k^2=1,\ \sum h_k g_k=0$ guarantees that the transposed filter reconstructs the signal exactly.

Reconstruction MSE ($N$-point mean squared error):

$$\mathrm{MSE} = \frac{1}{N}\sum_{n=0}^{N-1}\bigl(x[n]-x_\text{rec}[n]\bigr)^2$$

What is the Daubechies-4 Wavelet Simulator?

🙋
How is wavelet analysis different from Fourier analysis? Both decompose a signal — when should I pick one over the other?
🎓
Roughly speaking, Fourier tells you which frequencies are present averaged over the whole signal. Wavelets tell you which frequencies are present at which position. Try switching the signal type to "1 (step)". Fourier needs infinitely many sines to represent that step; db4 only needs a handful of large detail coefficients near the discontinuity, and the rest are nearly zero.
🙋
Wow, the detail-coefficient rows really do spike only around the middle. If I raise the threshold to 0.1, almost all the small coefficients vanish, but the reconstruction MSE barely moves...
🎓
That is the heart of wavelet compression. Energy concentrates in a few coefficients (the sparsity property), so dropping the small ones barely affects reconstruction. JPEG 2000, DICOM medical-image compression and several audio codecs all rely on this. Unlike Haar, db4 can represent piecewise-linear pieces, so ringing near a step is much milder.
🙋
What does the "Decomposition level" slider do?
🎓
Each extra level halves the approximation again and repeats the same one-level transform on it. That is multiresolution analysis. With L=4 you get a coarse approximation that is N/16 long, plus four bands of detail coefficients at progressively finer scales. Think "thumbnail plus successive sharpening differences."
🙋
If I pick signal type 0 (sine), the detail coefficients are almost all zero. Would Haar behave the same way?
🎓
Sharp observation. db4 has one extra vanishing moment, so any constant and any linear trend is annihilated in the detail band. Haar only kills constants, so even smooth slopes leak into Haar details. That is why db4 (and beyond) is preferred over Haar for compressing real images and audio.

FAQ

Haar uses a 2-tap filter with a discontinuous box-shaped basis. Daubechies-4 (db4) uses 4 taps and is the shortest orthogonal wavelet with one extra vanishing moment beyond Haar. As a result, piecewise-linear signals can be represented with far fewer coefficients, and ringing near step edges is noticeably reduced. db4 is widely used in image and audio compression.
Daubechies wavelets form an infinite family indexed by the number of vanishing moments: db1 (Haar), db2 (4 taps), db3 (6 taps), ..., dbN (2N taps). Larger N gives smoother basis functions but longer filters, which raise boundary-handling costs and widen the effective support. In practice db4 through db8 are the most popular choices.
JPEG 2000 is built on the discrete wavelet transform (DWT) and uses CDF 5/3 for lossless and CDF 9/7 for lossy — biorthogonal wavelets chosen for symmetry. Daubechies wavelets are not symmetric, but the design philosophy is the same as db4: concentrate signal energy into a few large coefficients. Extending this 1D demo to 2D (rows and columns) is essentially a prototype of wavelet image compression.
The wavelet transform concentrates signal energy into a small number of large coefficients (sparsity). The remaining small detail coefficients mostly represent noise or minor variations, so zeroing them has limited impact on reconstruction quality. A coefficient sequence full of zeros compresses efficiently with run-length and entropy coding, which is why thresholding plus entropy coding is the standard pipeline in modern image and audio compression.

Real-world applications

Image compression (JPEG 2000, DICOM): JPEG 2000 uses a 2D discrete wavelet transform as its core technology, decomposing images into multiscale subbands with biorthogonal wavelets. Medical-image DICOM compression is also wavelet-based and supports both lossless and lossy modes. The "energy concentrates into a few large coefficients" property that this tool visualizes is what lets these codecs combine high compression ratios with acceptable visual quality.

Audio and music compression and analysis: Successor codecs to MP3 and feature-extraction front ends for speech recognition use wavelet packets or adaptive wavelet decompositions. Transient sounds such as percussion can be reproduced with far fewer parameters than Fourier would need, preserving natural timbre even at low bitrates.

Non-stationary signal analysis — seismic, ECG, EEG: Seismograms, ECG/EEG traces and vibration sensor signals share the question "what frequency content happened, when?" Wavelets are the standard tool here. Spike detection and denoising algorithms commonly choose db4 through db8 as their analyzing wavelet.

Signal processing and feature extraction in CAE: When extracting events or anomalies from vibration-test response data, structural-health monitoring, or turbulent-flow velocity records, threshold-based wavelet denoising is highly effective. FFT loses time information, but wavelets keep "what happened when" — making them a popular preprocessing step for machine-learning pipelines.

Common misconceptions and caveats

The most common misconception is to treat wavelets as a strict upgrade to Fourier. The two tools have different strongholds. Stationary frequency analysis (the 50 Hz line frequency, the natural frequency of a rotating machine) is much cleaner and easier to interpret with Fourier. Wavelets shine on transient phenomena, edges and local events. Switch the signal type to "0 (pure sine)" in this simulator and the detail coefficients almost vanish — a sine is not sparse in the db4 basis (the sine itself is more compact). Pick the right tool for the right job.

The second misconception is that raising the threshold gives unlimited compression. Yes, the non-zero count drops, but past a critical point the reconstruction MSE explodes and the main features of the signal are lost. Sweep the threshold from 0 to 1 with a step signal selected and watch the MSE card: it stays flat up to about 0.1, then rises sharply. In practice you first fix an acceptable distortion budget and then search for the largest threshold that still meets it.

Finally, do not ignore boundary handling. This tool uses periodic (cyclic) convolution for implementation simplicity. That assumes the two ends of the signal are joined, and for real signals the resulting end-point discontinuity creates large detail coefficients and ringing in reconstruction. In production code you would choose zero padding, symmetric (reflection) extension, or periodic extension depending on the signal class — symmetric is preferred for natural images, periodic for textures with genuine wrap-around.