A function is sparse in a basis when a few coefficients carry almost all of its energy. Keeping the first k coefficients (coarse to fine, or low to high frequency) is a linear approximation: it is what a projection estimator does. Keeping the k largest is a nonlinear approximation: it is what thresholding does. For a function with jumps or with spatially varying smoothness, the largest wavelet coefficients sit where the action is, and the nonlinear error falls far faster than the linear one; in the cosine basis, the jumps spread energy over all frequencies and neither choice does well.
The function is sampled at xi = i/2048. The wavelet coefficients are those of the periodised orthonormal transform (Haar down to level 0, the others down to level 3); the cosine coefficients are the orthonormal DCT-II. Relative error = Σ(f − fk)2 / Σf2, which by Parseval is the energy of the dropped coefficients.
code/ch09_wavelets_adaptive_methods.py (daubechies_filter, cascade, dwt, nterm_errors).