The Haar transform writes a signal of length n = 2L as its overall average plus one detail layer per level j = 0, …, L − 1: the layer gj = Σk Dj,kψj,k holds what is seen at resolution 2−(j+1) but not at 2−j. The lower panel draws the layers as a ladder, coarse at the top. A linear estimate keeps the first J layers whole (the resolution-J approximation (21.34)): fine detail is lost everywhere, or noise is kept everywhere. Thresholding keeps single coefficients that exceed λ = σ̂√(2 log n/n), wherever they are, so the fine layers survive only where the signal has fine structure. The last panel checks the claim behind this choice (Theorem 21.15): pure noise almost never crosses the universal threshold.
The noise is drawn from a seeded generator; "New noise" moves to the next seed, and pure-noise sample r uses its own seed. Design points are xi = i/n, so the Haar functions are taken constant on (k2−j, (k+1)2−j]. The noise level σ̂ is (21.37), from the finest level only. The error shown is the average squared error at the design points.
code/ch21_orthogonal_functions.py (haar_dwt, haar_idwt, haar_threshold, mad_sigma, noise_survival).