S7 · Lesson 44 · Sparse signals and compressed sensing
Recovering a signal from far fewer measurements than the sampling theorem asks, when it's sparse
The sampling theorem says a signal with bandwidth needs samples per second. But many signals are far simpler than their bandwidth suggests: a radar scene with a handful of targets, an MRI image that's mostly smooth, a spectrum with a few strong tones. Lesson 43's wavelets showed that natural signals are sparse in the right basis, with most coefficients near zero. If a signal has only nonzero coefficients out of , it should take about numbers to describe, not . Compressed sensing makes that practical: take a few random linear measurements, then find the sparsest signal consistent with them. MRI scanners use it to cut scan times severalfold.
- The number of random measurements needed to recover a -sparse signal of length , by the rule of thumb , against , for = 1024.
- It grows only slightly faster than itself and stays far below for sparse signals. The dashed line is : when approaches about , compressed sensing stops paying off.
Predict
A length-1024 signal has 10 nonzero values, at unknown positions. About how many random linear measurements does compressed sensing need to recover it exactly?
By the rule of thumb : = 185. More than , because the positions are unknown, but five times fewer than . The is the price of not knowing where the nonzeros are: roughly the information needed to name positions among .
Name it
Sparsity
A signal of length is -sparse if only of its coefficients are nonzero, in some basis: samples, Fourier coefficients, wavelets. Natural images and audio are approximately sparse: their sorted wavelet or DCT coefficients fall off quickly, which is why JPEG works (lesson 28).
Measurements
Instead of sampling directly, take linear measurements , where is an matrix, for instance with random Gaussian entries. With there are infinitely many consistent with ; the question is whether the sparsest one is unique and findable.
Recovery
- ℓ₁ minimization (basis pursuit): minimize subject to . A convex problem, solvable efficiently, and it finds the sparse solution when satisfies the restricted isometry property: it nearly preserves the length of every sparse vector. Random matrices satisfy it with high probability once .
- Orthogonal matching pursuit (OMP): a greedy algorithm. Repeat times: pick the column of most correlated with the residual, add it to the support, refit on the chosen columns by least squares, and update the residual.
Why random
A measurement that looks at only a few coefficients can miss the nonzero ones entirely; a random combination of all of them can't. Coherence, the largest normalized inner product between columns of (or between the measurement and sparsity bases), measures how well spread the measurements are; low coherence means fewer measurements.
Limits
Noise turns exact recovery into approximate recovery, with error proportional to the noise. Signals that are only approximately sparse are recovered to about their best -term approximation. And the measurements must be designed into the hardware: random sampling of MRI's frequency space, random modulation in a radio receiver.
Worked example
How many measurements does the rule suggest for = 4096 and = 20, and how does that compare with ?
Show the solution
- Apply the rule. so about 426 measurements.
- Compare with N. That's about a tenth of , or 21 per nonzero value.
- Sparser signals. Halving the sparsity to 10 roughly halves it again (241).
Answer about 426 measurements, roughly a tenth of N = 4096.
Worked example
Run one step of OMP. has unit-norm columns with = 0.4, = −1.3, = 0.9. Which column is chosen, and with one column selected what is its coefficient?
Show the solution
- Pick a column. OMP picks the largest correlation in magnitude: , at 1.3.
- Its coefficient. With a single unit-norm column, the least-squares coefficient is
- Residual. The residual is orthogonal to , so the next step can't pick it again.
Answer column is chosen, with coefficient −1.3.
Worked example
An MRI scan acquires 256 lines of k-space in 4 minutes. If the image is sparse enough in a wavelet basis that compressed sensing needs only a quarter of the lines, chosen at random, how long does the scan take?
Show the solution
- Scan time. 64 lines instead of 256 take 1 minute instead of 4.
- Reconstruction. The reconstruction becomes an optimization (ℓ₁ minimization in the wavelet domain) instead of a single inverse FFT, but computing is cheap compared with a patient's time in the scanner.
- Choosing the lines. Undersampled lines are chosen randomly, denser near the center of k-space where the energy is, so that aliasing spreads out as noise-like artifacts the reconstruction can remove, instead of coherent ghosts.
Answer 1 minute.
Check
By the rule of thumb , about how many random measurements recover a 5-sparse signal of length 1024?
Check
A first OMP step sees correlations 0.4, −1.3 and −0.5 between three unit-norm columns and the measurements. What coefficient does it assign to the column it picks?
Check
A scan acquires 256 lines in 6 minutes. Compressed sensing needs only a fraction 0.2 of them. How long does the accelerated scan take?
Check
An 8-sparse signal of length 512.
(a)
What fraction of the Nyquist samples does the rule of thumb need?
(b)
How many measurements per nonzero coefficient is that?
Check
Why does compressed sensing use random measurements instead of simply sampling a few of the signal's values?
Check
Recover a sparse signal with OMP. With rng = numpy.random.default_rng(seed), M = ceil(4*K*ln(N/K)), A = rng.standard_normal((M, N))/sqrt(M), a support idx = rng.choice(N, K, replace=False) and values rng.standard_normal(K) + numpy.sign(rng.standard_normal(K)) placed there (draws in that order), measure y = A @ x. Write omp(A, y, K) and set x_hat and err, the relative error .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
A spectrum analyzer design wants to monitor a 2 GHz band in which at most a few narrowband signals are active at once, using an ADC far slower than 4 GS/s. Explain how compressed sensing could make that possible, and what it requires.
A band with only a few active narrowband signals is sparse in frequency: of the many frequency bins across 2 GHz, only a handful hold signals. Compressed sensing says such a signal can be recovered from a number of measurements proportional to the number of active signals times a logarithmic factor, not the full Nyquist rate. A practical front end mixes the input with a pseudorandom sequence (a random demodulator or modulated wideband converter), which spreads every frequency across the slow ADC's band, then samples slowly; each sample is a random-looking linear combination of all the frequencies, and a sparse-recovery algorithm such as OMP finds which bins are active and their amplitudes. It requires that the band really be sparse, that the random sequence and hardware be known precisely enough to build the measurement matrix, enough SNR, and computing for the recovery. If the band fills up, recovery fails.
Practice
Keep practicing
7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.