---
title: Parametric models and linear prediction
heading: Autoregressive signal models, the Yule–Walker equations, the Levinson–Durbin recursion and its reflection coefficients, prediction error and spectral envelopes
eyebrow: S7 · Lesson 34 · Parametric models and linear prediction
xp: 50
---

::: hook
Many signals are well described as white noise passed through an all-pole filter: a vocal tract shaping the buzz of the vocal folds, a resonant structure shaping random forces, a channel shaping data. If that's the model, the signal's whole spectrum is captured by a handful of filter coefficients, and those coefficients can be found from the signal's autocorrelation by solving a small set of linear equations. The same coefficients make the best linear predictor of each sample from the ones before it, which is how speech codecs squeeze a voice into a few kilobits per second.
:::

::: play
- The power spectrum of a second-order autoregressive process, $\frac{\sigma^2}{|1 - a_1e^{-j\omega} - a_2e^{-2j\omega}|^2}$ in dB, with its poles at $re^{\pm j\theta}$ ($a_1 = 2r\cos\theta$, $a_2 = -r^2$) and unit driving noise.
- The spectrum peaks near the pole angle; the closer r is to 1, the taller and narrower the peak, the shape of a formant in speech.
- Two coefficients describe the whole curve. A speech codec sends about ten such coefficients per 20 ms frame instead of the samples themselves.
:::
:::

```sim plot
view: graph
x: w = 0..3.1416
y: P = -20..40 dB
slider: r = 0.3..0.99 = 0.9
slider: t = 0.1..3 = 1
plot: -10*log((1 - 2*r*cos(t)*cos(w) + r^2*cos(2*w))^2 + (2*r*cos(t)*sin(w) - r^2*sin(2*w))^2) | samples: 800 | label: AR(2) spectrum, dB
readout: a₁ = 2*r*cos(t)
readout: a₂ = -r^2
```

::: predict
## A first-order AR process has x[n] = 0.9x[n − 1] + w[n]. How well can x[n] be predicted from x[n − 1]?

- [ ] Perfectly
- [x] The prediction error has only 19% of the signal's power, a 7.2 dB prediction gain
- [ ] Not at all, since w is white
- [ ] The error has 90% of the signal's power

::: reveal
The best predictor is $\hat{x}[n] = 0.9x[n - 1]$, leaving exactly the new noise w[n] as error. The signal's power is $\sigma_w^2/(1 - 0.81)$ = 5.26 σ², so the error is 1 − 0.81 = 19% of it: a prediction gain of 7.2 dB. Only the part that's genuinely new can't be predicted.
:::
:::

::: nameit
## Autoregressive models

An AR(p) process is white noise w[n] of variance $\sigma_w^2$ through an all-pole filter:

$$x[n] = \sum_{k=1}^{p}a_kx[n - k] + w[n], \qquad P_{xx}(\omega) = \frac{\sigma_w^2}{\left|1 - \sum_ka_ke^{-j\omega k}\right|^2}$$

For AR(1), $\phi_{xx}[m] = \frac{\sigma_w^2}{1 - a^2}a^{|m|}$.

## Linear prediction and the Yule–Walker equations

The predictor $\hat{x}[n] = \sum_{k=1}^{p}a_kx[n - k]$ minimizing the mean-square error satisfies

$$\sum_{k=1}^{p}a_k\phi[|i - k|] = \phi[i], \quad i = 1, \dots, p$$

a Toeplitz system, with minimum error $E_p = \phi[0] - \sum_ka_k\phi[k]$. If x really is AR(p), the predictor recovers the model's coefficients and $E_p = \sigma_w^2$. The **prediction gain** is $10\log(\phi[0]/E_p)$.

## The Levinson–Durbin recursion

Solve order by order in $O(p^2)$ operations, starting from $E_0 = \phi[0]$:

$$k_i = \frac{\phi[i] - \sum_{j=1}^{i-1}a_j^{(i-1)}\phi[i - j]}{E_{i-1}}, \quad a_i^{(i)} = k_i, \quad a_j^{(i)} = a_j^{(i-1)} - k_ia_{i-j}^{(i-1)}, \quad E_i = E_{i-1}(1 - k_i^2)$$

The $k_i$ are the **reflection coefficients** of lesson 17's lattice; $|k_i| < 1$ for a valid autocorrelation, so the model is always stable, and $E_i$ never increases with order. Choosing the order is a balance: too low misses spectral peaks, too high fits noise.
:::

::: example
## A process has φ[0] = 1, φ[1] = 0.8 and φ[2] = 0.5. Find the second-order predictor by Levinson–Durbin.

::: solution
1. **First order.**
   $$\begin{aligned} k_1 &= 0.8 \\ E_1 &= 1 - 0.64 \\ &= 0.36 \end{aligned}$$
2. **Reflection coefficient.**
   $$\begin{aligned} k_2 &= \frac{0.5 - 0.8 \times 0.8}{0.36} \\ &= -0.389 \end{aligned}$$
   so $a_2$ = −0.389.
3. **Update $a_1$.**
   $$\begin{aligned} a_1 &= 0.8 - (-0.389)(0.8) \\ &= 1.111 \end{aligned}$$
4. **Error.**
   $$\begin{aligned} E_2 &= 0.36(1 - 0.151) \\ &= 0.306 \end{aligned}$$
5. **Check against Yule–Walker.**
   $$\begin{aligned} 1.111 + 0.8(-0.389) &= 0.8 \\ 0.8(1.111) - 0.389 &= 0.5 \end{aligned}$$
6. **Prediction gain.**
   $$\begin{aligned} G &= 10\log(1/0.306) \\ &= 5.1\ \text{dB} \end{aligned}$$

**Answer:** $a_1$ = 1.111 and $a_2$ = −0.389, with error power 0.306 and a prediction gain of 5.1 dB.
:::
:::

::: example
## An AR(1) process with a = 0.9 and $\sigma_w^2$ = 1. What are its variance, its correlation one sample apart, and its PSD at DC and at π?

::: solution
1. **Variance.**
   $$\begin{aligned} \phi[0] &= \frac{1}{1 - 0.81} \\ &= 5.26 \end{aligned}$$
2. **Correlation one sample apart.** φ[1]/φ[0] = 0.9.
3. **PSD at DC.**
   $$\begin{aligned} P(0) &= \frac{1}{(1 - 0.9)^2} \\ &= 100 \end{aligned}$$
   which is 20 dB.
4. **PSD at π.**
   $$\begin{aligned} P(\pi) &= \frac{1}{1.9^2} \\ &= 0.277 \end{aligned}$$
   which is −5.6 dB: a strongly lowpass process.

**Answer:** a variance of 5.26, a correlation of 0.9 one sample apart, and a PSD of 100 (20 dB) at DC and 0.277 (−5.6 dB) at π.
:::
:::

::: example
## A process has $\phi[m] = 0.8^{|m|}$. Run Levinson–Durbin to order 2. What does the second order add, and what is the prediction gain?

::: solution
1. **First order.**
   $$\begin{aligned} k_1 &= \phi[1]/\phi[0] \\ &= 0.8 \end{aligned}$$
   $$\begin{aligned} E_1 &= 1 - 0.64 \\ &= 0.36 \end{aligned}$$
2. **Second order.**
   $$\begin{aligned} k_2 &= \frac{\phi[2] - a_1\phi[1]}{E_1} \\ &= \frac{0.64 - 0.8 \times 0.8}{0.36} \\ &= 0 \end{aligned}$$
3. **Why it adds nothing.** This is exactly the autocorrelation of an AR(1) process with a = 0.8.
4. **Prediction gain.**
   $$\begin{aligned} G &= 10\log_{10}(1/0.36) \\ &= 4.4\ \text{dB} \end{aligned}$$
   at every order from 1 on.

**Answer:** $k_2$ = 0, so the second order adds nothing, and the prediction gain is 4.4 dB.
:::
:::

::: check
given: a = 0.5 | 0.8 | -0.7 | 0.95; v = 1 | 2.5
answer: v/(1 - a^2)
tolerance: 0.5%

## An AR(1) process x[n] = {a}x[n − 1] + w[n] is driven by white noise of variance {v}. What's the variance of x?

::: right
Right. $\sigma_w^2/(1 - a^2)$ = {answer}.
:::

::: misses
- [v/(1 - a)] Square the coefficient: the past contributes $a^2$ of its variance.
- [any] Not yet. $\sigma_x^2 = a^2\sigma_x^2 + \sigma_w^2$.
:::
:::

::: check
given: a = 0.5 | 0.8 | -0.7 | 0.95
answer: 10*log(1/(1 - a^2))
unit: dB
tolerance: 0.05

## What's the one-step prediction gain for that AR(1) process?

::: right
Right. $\phi[0]/\sigma_w^2 = 1/(1 - a^2)$: {answer} dB.
:::

::: misses
- [20*log(1/(1 - abs(a)))] The error power is $(1 - a^2)$ of the signal power, not $(1 - |a|)^2$.
- [any] Not yet. Signal power over error power.
:::
:::

::: check
given: p = 0.5 | 0.6 | 0.7; q = 0.05 | 0.6
answer: (q - p*p)/(1 - p*p)
tolerance: 0.5%

## A process has φ[0] = 1, φ[1] = {p}, φ[2] = {q}. What's the second reflection coefficient $k_2$?

::: right
Right. $k_2 = (\phi[2] - k_1\phi[1])/E_1$ with $k_1$ = {p} and $E_1 = 1 - k_1^2$: {answer}.
:::

::: misses
- [q - p*p] Divide by $E_1 = 1 - k_1^2$.
- [any] Not yet. Run Levinson–Durbin to order 2.
:::
:::

::: check
given: p = 0.5 | 0.6 | 0.7; q = 0.05 | 0.6
answer: p*(1 - (q - p*p)/(1 - p*p))
tolerance: 0.5%

## For the same process, what's the order-2 predictor coefficient $a_1$?

::: right
Right. $a_1 = k_1(1 - k_2)$ = {answer}.
:::

::: misses
- [p] That's the order-1 coefficient; the second stage updates it.
- [any] Not yet. $a_1^{(2)} = a_1^{(1)} - k_2a_1^{(1)}$.
:::
:::

::: check
given: p = 0.5 | 0.6 | 0.7; q = 0.05 | 0.6
answer: (1 - p*p)*(1 - ((q - p*p)/(1 - p*p))^2)
tolerance: 0.5%

## For the same process, what's the order-2 prediction error $E_2$?

::: right
Right. $E_2 = E_1(1 - k_2^2)$ = {answer}.
:::

::: misses
- [1 - p*p] That's $E_1$; the second coefficient reduces it further.
- [any] Not yet. $E_i = E_{i-1}(1 - k_i^2)$.
:::
:::

::: check
given: a = 0.5 | 0.9; v = 1 | 3; w = 0 | 1.2 | 3.1416
answer: 10*log(v/(1 - 2*a*cos(w) + a^2))
unit: dB
tolerance: 0.05

## What's the PSD of the AR(1) process with a = {a} and $\sigma_w^2$ = {v} at ω = {w}?

::: right
Right. $\sigma_w^2/|1 - ae^{-j\omega}|^2$ = {answer} dB.
:::

::: misses
- [20*log(v/(1 - 2*a*cos(w) + a^2))] The PSD is already a power: 10 log.
- [any] Not yet. $\sigma_w^2/(1 - 2a\cos\omega + a^2)$.
:::
:::

::: check
kind: parts
given: p = 0.4 | 0.6 | 0.7; q = 0.1 | 0.3

## A process has φ[0] = 1, φ[1] = {p} and φ[2] = {q}.

::: part
answer: 1 - p^2
tolerance: 0.5%

### What is the first-order prediction error $E_1$?

::: misses
- [any] $E_0(1 - k_1^2)$ with $k_1 = \phi[1]$.
:::
:::

::: part
answer: 10*log(1/((1 - p^2)*(1 - ((q - p^2)/(1 - p^2))^2)))
unit: dB
tolerance: 0.5%

### What prediction gain does order 2 give?

::: misses
- [10*log(1/(1 - p^2))] That's order 1; include $(1 - k_2^2)$.
- [any] $10\log_{10}(\phi[0]/E_2)$.
:::
:::
:::

::: check
kind: derivation
vars: p = -0.9..0.9, q = -0.5..0.5

## Levinson–Durbin runs on φ[0] = 1, φ[1] = p, φ[2] = q.

::: step
answer: p

### What is $k_1$?
:::

::: step
answer: (q - p^2)/(1 - p^2)

### What is $k_2$?
:::

::: step
answer: (1 - p^2)*(1 - ((q - p^2)/(1 - p^2))^2)

### What is $E_2$?
:::

::: right
Right. $k_2 = 0$ exactly when $\phi[2] = \phi[1]^2$, the signature of an AR(1) process.
:::
:::

::: explain
## Why does the linear predictor's error turn out to be white?

::: model
The predictor is chosen so that its error is as small as possible in the mean-square sense, and the condition for that, the Yule–Walker equations, says the error must be uncorrelated with every past sample used in the prediction. If any correlation remained, part of the error could be predicted from those samples, and adding that part would shrink the error further, contradicting optimality. When the order is high enough to capture the signal's structure, the error is then uncorrelated with all of its own past too, which is what white means. The predictor has effectively removed everything predictable, the spectral shape, leaving only the new information in each sample, which is why prediction underlies both spectral modeling and compression.
:::
:::

::: practice

::: check
given: a = 0.6 | -0.85; v = 1 | 4
answer: v/(1 - a^2)
tolerance: 0.5%

## AR(1) variance: a {a}, σ_w² {v}?

::: misses
- [any] $\sigma_w^2/(1 - a^2)$.
:::
:::

::: check
given: p = 0.6 | 0.75; q = 0.3 | 0.5
answer: (q - p*p)/(1 - p*p)
tolerance: 0.5%

## $k_2$ for φ = [1, {p}, {q}]?

::: misses
- [any] $(\phi[2] - k_1\phi[1])/E_1$.
:::
:::

::: check
given: a = 0.5 | 0.7 | 0.8 | 0.9 | 0.95 | 0.99
answer: 10*log(1/(1 - a^2))
unit: dB
tolerance: 0.05

## AR(1) prediction gain for a = {a}?

::: misses
- [any] $10\log(1/(1 - a^2))$.
:::
:::
:::
