A signal of length N = 1024 is transformed into an orthonormal wavelet basis, y* = WTy, computed level by level in O(N) operations. Noise spreads evenly over all coefficients, while a signal with smooth stretches and a few sharp features concentrates in a few of them. Minimising ‖y − Wθ‖2 + 2λ‖θ‖1 (5.68) shrinks each coefficient toward zero by λ and kills the small ones (soft thresholding, (5.69)); the inverse transform gives the fit. The threshold can be the universal σ√(2 log N), the level-wise SURE choice, or your own.
The NMR-type signal is a synthetic spectrum with a fixed noise realisation (the book's spectrum is not distributed with its data). The other test signals (Donoho and Johnstone 1994) are scaled to standard deviation 7 and get unit-variance Gaussian noise from a seeded generator; "smooth" is (5.22) with unit noise. σ̂ is the median absolute deviation of the finest-level coefficients divided by 0.6745. SURE: at each level the threshold minimising Stein's unbiased risk estimate over [0, σ̂√(2 log n)], or the universal one when the level looks too sparse (SureShrink's hybrid rule). Boundaries are handled by periodic extension.
code/ch05_basis_expansions.py (daubechies_filter, dwt, idwt, sure_threshold, wavelet_shrink, nmr_like_signal, dj_signal).