---
title: Subspace methods for spectral estimation
heading: Sinusoids in noise, eigenvalues of the correlation matrix, Pisarenko and MUSIC, and the Cramér–Rao bound
eyebrow: S7 · Lesson 32 · Subspace methods for spectral estimation
xp: 50
---

::: hook
The periodogram and its averages (lesson 31) assume nothing about the signal, and pay for that generality with resolution limited to about one bin, $f_s/N$. When the signal is known to be a few sinusoids in white noise, as in radar, direction finding and many measurement problems, far better is possible. The correlation matrix of such a signal splits cleanly into a signal subspace and a noise subspace, and the frequencies can be read from either one, resolving tones much closer than a bin. How well any method can do is bounded by the Cramér–Rao limit, which falls much faster with record length than the bin width does.
:::

::: play
- The curves compare the DFT's bin width, $f_s/N$, with the Cramér–Rao bound on the standard deviation of a single tone's frequency estimate, $\frac{f_s}{2\pi}\sqrt{\frac{12}{\text{SNR}\,N(N^2 - 1)}}$, against record length N at 1 kHz.
- The bound falls as $N^{-3/2}$, the bin width only as $N^{-1}$: long records allow frequency estimates far finer than a bin.
- More SNR lowers the bound as its square root.
:::

```sim plot
view: graph
x: N = 10..10000 log
y: f = 0.0001..100 Hz log
slider: S = 0..40 = 10 dB
plot: 1000/N | label: DFT bin width
plot: 1000/(2*pi)*sqrt(12/(10^(S/10)*N*(N^2 - 1))) | dashed | label: Cramér–Rao bound
```

::: predict
## A single tone at 10 dB SNR is recorded for 100 samples at 1 kHz. The DFT's bins are 10 Hz apart. How precisely could the best unbiased estimator find its frequency?

- [ ] About 10 Hz
- [ ] About 3 Hz
- [x] About 0.17 Hz rms
- [ ] Exactly

::: reveal
The Cramér–Rao bound gives a variance of at least $\frac{12}{10 \times 100 \times 9999} = 1.2 \times 10^{-6}$ rad², a standard deviation of 0.0011 rad, which is 0.17 Hz at 1 kHz: sixty times finer than a bin. Peak interpolation, maximum likelihood or subspace methods can approach it at good SNR.
:::
:::

::: nameit
## Sinusoids in white noise

For K complex exponentials of powers $P_i$ at frequencies $\omega_i$ in white noise of variance σ², the M × M correlation matrix ($R_{mn} = \phi[m - n]$) is
$$R = \sum_{i=1}^{K}P_i\mathbf{a}(\omega_i)\mathbf{a}^H(\omega_i) + \sigma^2I, \qquad \mathbf{a}(\omega) = [1, e^{j\omega}, \dots, e^{j(M-1)\omega}]^T$$
Its K largest eigenvalues exceed σ² (for a single exponential, $MP + \sigma^2$); the other M − K equal σ² exactly, and their eigenvectors, the **noise subspace**, are orthogonal to every $\mathbf{a}(\omega_i)$. A real sinusoid counts as two complex exponentials.

## Pisarenko and MUSIC

- **Pisarenko**: use M = K + 1; the single noise eigenvector's polynomial has its roots at the frequencies. For one real sinusoid (power P, so φ[m] = P cos mω plus σ² at m = 0), the closed form is
$$\cos\omega = \frac{\phi[2] + \sqrt{\phi[2]^2 + 8\phi[1]^2}}{4\phi[1]}, \qquad P = \frac{\phi[1]}{\cos\omega}, \qquad \sigma^2 = \phi[0] - P$$
- **MUSIC**: use M > K + 1 and plot the pseudospectrum $1/\sum_{\text{noise}}|\mathbf{a}^H(\omega)\mathbf{v}_k|^2$, which peaks sharply where $\mathbf{a}(\omega)$ is orthogonal to the noise subspace. More noise eigenvectors make it robust.
- Both need the number of components K, chosen where the eigenvalues level off (or by criteria like AIC and MDL). Wrong K or low SNR produces spurious peaks.

## The Cramér–Rao bound

For one real tone of amplitude A in white noise σ² (SNR = A²/2σ²) over N samples, any unbiased frequency estimate has
$$\text{var}(\hat\omega) \ge \frac{12}{\text{SNR}\cdot N(N^2 - 1)}\ \text{rad}^2$$
falling as $N^{-3}$, much faster than the periodogram's bin width.
:::

::: example
## A process has φ[0] = 1.5, φ[1] = 0.309 and φ[2] = −0.809. Assuming one real sinusoid in white noise, find its frequency, power and the noise power.

::: solution
1. **The square root.**
   $$\sqrt{0.655 + 8 \times 0.0955} = 1.191$$
2. **Frequency.**
   $$\begin{aligned} \cos\omega &= \frac{-0.809 + 1.191}{4 \times 0.309} \\ &= 0.309 \end{aligned}$$
   so ω = 0.4π.
3. **Power.**
   $$\begin{aligned} P &= \frac{0.309}{0.309} \\ &= 1 \end{aligned}$$
   an amplitude of √2.
4. **Noise power.**
   $$\begin{aligned} \sigma^2 &= 1.5 - 1 \\ &= 0.5 \end{aligned}$$
5. **How far to trust it.** Three correlation values pin down all three parameters exactly; with estimated correlations the result is only as good as those estimates.

**Answer:** ω = 0.4π, a sinusoid power of 1 and a noise power of 0.5.
:::
:::

::: example
## One complex exponential of power 1 is in white noise of variance 0.1. What are the eigenvalues of its 4 × 4 correlation matrix?

::: solution
1. **The signal eigenvalue.** Along $\mathbf{a}(\omega)$:
   $$\begin{aligned} \lambda_1 &= MP + \sigma^2 \\ &= 4 \times 1 + 0.1 \\ &= 4.1 \end{aligned}$$
2. **The noise eigenvalues.** The other three are exactly 0.1, the noise floor.
3. **Why the gap matters.** The gap between them is what makes the signal and noise subspaces separable; at low SNR or with short records, estimated eigenvalues scatter and the gap blurs.

**Answer:** 4.1, 0.1, 0.1 and 0.1.
:::
:::

::: example
## A tone at 10 dB SNR is recorded for 100 samples, then for 1000, at 1 kHz. How do the Cramér–Rao bound and the DFT bin compare?

::: solution
1. **N = 100.** The bound is 0.0011 rad, 0.17 Hz rms, against 10 Hz bins.
2. **N = 1000.**
   $$\begin{aligned} \sigma_\omega &= \sqrt{\frac{12}{10 \times 1000 \times 999\,999}} \\ &= 3.5 \times 10^{-5}\ \text{rad} \end{aligned}$$
   which is 0.0055 Hz, against 1 Hz bins.
3. **Compare.** Ten times the record improves the bound thirty-two times but the bin width only ten times.

**Answer:** the bound is 0.17 Hz against 10 Hz bins for 100 samples, and 0.0055 Hz against 1 Hz bins for 1000.
:::
:::

::: check
kind: parts
given: P = 1 | 2; s = 0.2 | 0.5; w = 0.2 | 0.35; let a = P*cos(w*pi); let b = P*cos(2*w*pi); let c = P + s

## A process has φ[0] = {c}, φ[1] = {a} and φ[2] = {b}; it's one real sinusoid in white noise.

::: part
answer: acos((b + sqrt(b^2 + 8*a^2))/(4*a))/pi
tolerance: 0.5%

### What is its frequency, in units of π?

::: misses
- [any] Pisarenko: $\cos\omega = \frac{\phi[2] + \sqrt{\phi[2]^2 + 8\phi[1]^2}}{4\phi[1]}$.
:::
:::

::: part
answer: c - a/((b + sqrt(b^2 + 8*a^2))/(4*a))
tolerance: 0.5%

### What is the noise power?

::: misses
- [any] φ[0] − P with P = φ[1]/cos ω.
:::
:::
:::

::: check
kind: parts
given: M = 4 | 8 | 16; P = 0.5 | 2; s = 0.01 | 0.1 | 1

## One complex exponential of power {P} sits in white noise of variance {s}; the correlation matrix is {M} × {M}.

::: part
answer: M*P + s
tolerance: 0.5%

### What is its largest eigenvalue?

::: misses
- [P + s] The signal's power is spread along a vector of length √M: MP.
- [any] $MP + \sigma^2$.
:::
:::

::: part
answer: s
tolerance: 0.5%

### What are its other eigenvalues?

::: misses
- [any] The noise variance.
:::
:::
:::

::: check
kind: parts
given: N = 64 | 256 | 1024; S = 0 | 10 | 20; f = 1 | 48

## A tone at {S} dB SNR is recorded for N = {N} samples at {f} kHz.

::: part
answer: sqrt(12/(10^(S/10)*N*(N^2 - 1)))/(2*pi)*f*1000
unit: Hz
tolerance: 0.5%

### What is the Cramér–Rao bound on its frequency's standard deviation?

::: misses
- [any] $\sqrt{12/(\text{SNR}\,N(N^2 - 1))}$ rad, times $f_s/2\pi$.
:::
:::

::: part
answer: f*1000/N/(sqrt(12/(10^(S/10)*N*(N^2 - 1)))/(2*pi)*f*1000)
tolerance: 0.5%

### How many times finer than a DFT bin is that?

::: misses
- [any] $f_s/N$ divided by the bound.
:::
:::
:::

::: check
kind: parts
given: K = 1 | 2 | 3; M = 8 | 12

## K = {K} real sinusoids are analyzed with an M = {M} correlation matrix.

::: part
answer: 2*K
unit: eigenvalues
tolerance: 0

### How many eigenvalues belong to the signal subspace?

::: misses
- [K] Each real sinusoid is two complex exponentials.
- [any] 2K.
:::
:::

::: part
answer: M - 2*K
unit: eigenvalues
tolerance: 0

### How many span the noise subspace MUSIC uses?

::: misses
- [any] M − 2K.
:::
:::
:::

::: check
kind: choice

## Why can MUSIC resolve two tones closer together than a DFT bin, when the periodogram can't?

- [ ] It uses a longer FFT
- [x] It assumes the signal is a known number of sinusoids in white noise and finds the frequencies whose steering vectors are orthogonal to the measured noise subspace; that model-based test isn't limited by the window's main-lobe width, though it fails if the model or the number of tones is wrong
- [ ] It averages more segments
- [ ] It removes the noise first

::: misses
- [1] Zero padding doesn't improve resolution; MUSIC doesn't rely on it.
- [3] Averaging reduces variance, not resolution.
- [4] It separates the noise subspace; it doesn't subtract noise from the data.
:::
:::

::: check
kind: derivation
vars: a = 0.05..1, b = -1..1, c = 1.1..3

## A process has φ[0] = c, φ[1] = a and φ[2] = b, modeled as one real sinusoid in white noise.

::: step
answer: (b + sqrt(b^2 + 8*a^2))/(4*a)

### What is cos ω?
:::

::: step
answer: a/((b + sqrt(b^2 + 8*a^2))/(4*a))

### What is the tone's power?
:::

::: step
answer: c - a/((b + sqrt(b^2 + 8*a^2))/(4*a))

### What is the noise power?
:::

::: right
Right. Three correlation lags, three unknowns: Pisarenko's method is exact for exact correlations.
:::
:::

::: check
kind: python

## Write `pisarenko(x)`: estimate φ[0], φ[1], φ[2] from the samples (biased estimates, dividing by N) and return (ω, noise power) for one real sinusoid in white noise.

```python starter
def pisarenko(x):
    return (0.0, 0.0)
```

```python solution
import math

def pisarenko(x):
    N = len(x)
    phi = [sum(x[n] * x[n + m] for n in range(N - m)) / N for m in range(3)]
    c = (phi[2] + math.sqrt(phi[2] ** 2 + 8 * phi[1] ** 2)) / (4 * phi[1])
    return (math.acos(c), phi[0] - phi[1] / c)
```

```python tests
import math, random
r = random.Random(5)
w0 = 0.3 * math.pi
x = [math.sqrt(2) * math.cos(w0 * n + 0.7) + r.gauss(0, math.sqrt(0.5)) for n in range(4000)]
w, s = pisarenko(x)
assert abs(w - w0) < 0.01, "The frequency within 0.01 rad from 4000 samples."
assert abs(s - 0.5) < 0.05, "The noise power near 0.5."
clean = [math.cos(0.2 * n) for n in range(20000)]
assert abs(pisarenko(clean)[0] - 0.2) < 1e-3, "Noise-free: essentially exact."
```

::: right
Right. With estimated correlations Pisarenko is noisy; MUSIC's larger noise subspace averages that out.
:::
:::

::: explain
## Why does the Cramér–Rao bound on frequency fall so much faster with record length than the DFT's resolution?

::: model
The DFT's bin width, the sampling rate over the record length, describes how well two components can be told apart without any assumption about them. Estimating the frequency of a single known tone is a different problem: the phase accumulates across the record at a rate set by the frequency, so a small frequency error grows into a large phase error by the end of a long record. Fitting that phase ramp, the error in the slope falls as the record length to the power three halves, and also with the square root of the signal-to-noise ratio. So given a model, a long record pins down a tone's frequency far more precisely than a bin width.
:::
:::

::: practice
::: check
given: M = 6 | 20; P = 1 | 3; s = 0.05 | 0.5
answer: M*P + s
tolerance: 0.5%

## Largest eigenvalue: M = {M}, P = {P}, σ² = {s}?

::: misses
- [any] $MP + \sigma^2$.
:::
:::

::: check
given: N = 128 | 512; S = 5 | 15
answer: sqrt(12/(10^(S/10)*N*(N^2 - 1)))
unit: rad
tolerance: 0.5%

## Cramér–Rao bound on ω for N = {N} at {S} dB SNR?

::: misses
- [any] $\sqrt{12/(\text{SNR}\,N(N^2 - 1))}$.
:::
:::

::: check
given: K = 2 | 4; M = 10 | 16
answer: M - 2*K
unit: eigenvalues
tolerance: 0

## Noise-subspace dimension for {K} real tones, M = {M}?

::: misses
- [any] M − 2K.
:::
:::
:::
