Skip to content

Parametric models and linear prediction

Fit a few coefficients instead of estimating every bin: predict each sample from its past, solve Yule–Walker order by order, and read a smooth spectrum.

Before this21.1 · 25.1 · 5 more
Chapter 25 · Lesson 3 of 4

First, the picture

Here 4096 samples of noise, made by a filter with four coefficients, are fitted one order at a time: each order predicts every sample from one more sample before it. Watch the error power left over: it falls until order 4, then stays near 1.

One order at a time

AR(4) noise (seed 253), 4096 samples: the estimated autocorrelation fed to the Levinson–Durbin recursion.

Order 0: no prediction; the error power is the whole power, 13.350.

order m
0
k_m
—
E_m
13.350
0.00 / 16.50 s
Describe this picture

Two panels for AR(4) noise (seed 253), 4096 samples, whose estimated autocorrelation is fed to the Levinson–Durbin recursion. The first shows the reflection coefficients kmk_m, from −1 to 1 against order mm from 1 to 8: the estimates are stems with square heads, and the true values, from the exact autocorrelation, open rings labelled “true”. The second shows the prediction-error power EmE_m as bars, from 0 to 14 against order 0 to 8. A dotted level at 1 is labelled “σ_v² = 1 (measured 1.003)”: the driving noise’s nominal power and the mean square of the 4096 draws used. The readouts are the order mm, kmk_m and EmE_m. There is no control. Order 0 is one bar: no prediction, so the error power is the whole power, 13.350. Orders are then added one at a time, each with a stem and a bar. Orders 1 to 4 give kk = −0.711, 0.778, −0.358 and 0.736, beside the true rings, and the error power falls to 1.041. Orders 5 to 8 add coefficients no larger than 0.022, and the error power stays near 1 (1.040 at order 8): the data are AR(4).

A few numbers instead of a whole spectrum

In The periodogram (25.1), “More data, same scatter” showed the trouble with estimating a PSD bin by bin. Each bin scatters about the truth by about the truth itself, and more data only gives more bins.

But much of the noise we meet is white noise through a filter with a handful of coefficients. If I know that, I only need to estimate those few numbers. Then the filter hands me the whole spectrum, smooth, through 24.4’s rule.

Here is the model. An autoregressive model of order pp, AR(pp) for short, makes each sample from the pp before it plus fresh white noise:

x[n]=−∑k=1pak x[n−k]+v[n].x[n]=-\sum_{k=1}^{p}a_k\,x[n-k]+v[n].

The number pp is the model order. The coefficients aka_k are the output-side coefficients of a difference equation, as in Difference equations (6.1), with a0=1a_0=1. So x[n]x[n] is white noise v[n]v[n], of variance σv2\sigma_v^2, through the all-pole filter 1/A(z)1/A(z), where A(z)=1+a1z−1+⋯+apz−pA(z)=1+a_1z^{-1}+\dots+a_pz^{-p}.

The AR(1) noise of “White noise forgets, coloured noise remembers” in Random processes (24.2), x[n]=a x[n−1]+v[n]x[n]=a\,x[n-1]+v[n], is the case p=1p=1 with a1=−aa_1=-a. The minus sign is the difference-equation habit; this page keeps it.

What is its spectrum? In Power spectral density (24.4), “Memory in time, narrowness in frequency” gave two facts. White noise has a flat PSD, σv2\sigma_v^2, and a filter multiplies a PSD by ∣H∣2\lvert H\rvert^2. Here H=1/AH=1/A, so

Sx(ejΩ)=σv2∣A(ejΩ)∣2.S_x(e^{j\Omega})=\frac{\sigma_v^2}{\lvert A(e^{j\Omega})\rvert^2}.

Every pole pair of 1/A(z)1/A(z) near the unit circle makes a peak at its angle, as “Where the pair sits is how h[n] moves” showed in Transfer functions, poles & zeros (16.3). A pair takes two coefficients, so pp numbers can draw up to p/2p/2 such peaks.

There are two other models. A moving-average model, MA, is white noise through an FIR filter: x[n]=b0v[n]+b1v[n−1]+…x[n]=b_0v[n]+b_1v[n-1]+\dots, with zeros instead of poles. An ARMA model has both, and its PSD is σv2∣B(ejΩ)∣2/∣A(ejΩ)∣2\sigma_v^2\lvert B(e^{j\Omega})\rvert^2/\lvert A(e^{j\Omega})\rvert^2. This page fits AR models, because their coefficients come from linear equations.

Predict the next sample

How do I find the aka_k from data? Turn the model round. If x[n]x[n] is made from its past plus something new, I can guess it from its past. The prediction from the pp samples before is

xpred[n]=−∑k=1pak x[n−k],x_\text{pred}[n]=-\sum_{k=1}^{p}a_k\,x[n-k],

and the prediction error is what is left:

x[n]−xpred[n]=x[n]+∑k=1pak x[n−k].\begin{aligned} x[n]-x_\text{pred}[n]&=x[n]\\ &\quad+\sum_{k=1}^{p}a_k\,x[n-k]. \end{aligned}

That is x[n]x[n] through the FIR filter A(z)A(z). If xx really is AR(pp) with these aka_k, the error is exactly v[n]v[n]: the part nobody could have guessed.

I choose the aka_k that make the mean square of the error as small as possible. As in “Least squares or least worst” in Optimal FIR design (19.3), the error is linear in the coefficients, so its mean square is a quadratic. Its lowest point comes from pp linear equations.

Here is a way to see those equations without calculus. Suppose the error were still correlated with one of the past samples, say x[n−i]{x[n-i]}. Then I could add a little more of x[n−i]{x[n-i]} to the prediction and shrink the error. So at the best coefficients the error is uncorrelated with each of the pp past samples:

E{(x[n]+∑k=1pak x[n−k])×x[n−i]}=0.\begin{aligned} \mathbb{E}\Big\{\Big(x[n]&+\sum_{k=1}^{p}a_k\,x[n-k]\Big)\\ &\times x[n-i]\Big\}=0. \end{aligned}

Averages add (24.2), and each product averages to an autocorrelation: E{x[n] x[n−i]}=Rx[i]\mathbb{E}\{x[n]\,x[n-i]\}=R_x[i] and E{x[n−k] x[n−i]}=Rx[i−k]\mathbb{E}\{x[n-k]\,x[n-i]\}=R_x[i-k]. So for i=1,…,pi=1,\dots,p,

∑k=1pak Rx[i−k]=−Rx[i].\sum_{k=1}^{p}a_k\,R_x[i-k]=-R_x[i].

These are the Yule–Walker equations. For p=3p=3 they read

[Rx[0]Rx[1]Rx[2]Rx[1]Rx[0]Rx[1]Rx[2]Rx[1]Rx[0]][a1a2a3]=−[Rx[1]Rx[2]Rx[3]],\begin{aligned} &\begin{bmatrix}R_x[0]&R_x[1]&R_x[2]\\R_x[1]&R_x[0]&R_x[1]\\R_x[2]&R_x[1]&R_x[0]\end{bmatrix} \begin{bmatrix}a_1\\a_2\\a_3\end{bmatrix}\\ &\qquad=-\begin{bmatrix}R_x[1]\\R_x[2]\\R_x[3]\end{bmatrix}, \end{aligned}

where I used Rx[−ℓ]=Rx[ℓ]R_x[-\ell]=R_x[\ell] from 24.2. In general they are Ra=−r\mathbf{R}\mathbf{a}=-\mathbf{r}. The p×pp\times p matrix R\mathbf{R} has Rx[i−k]R_x[i-k] in row ii, column kk; a\mathbf{a} holds a1a_1 to apa_p, and r\mathbf{r} holds Rx[1]R_x[1] to Rx[p]R_x[p].

Look at the matrix. Every diagonal holds one value: Rx[0]R_x[0] on the main one, Rx[1]R_x[1] beside it, and so on. A matrix that is constant along each diagonal is called Toeplitz.

The error power left at the best coefficients is worth knowing too. The error is uncorrelated with the past samples, so its mean square equals the mean of the error times x[n]x[n] alone:

Ep=Rx[0]+∑k=1pak Rx[k].E_p=R_x[0]+\sum_{k=1}^{p}a_k\,R_x[k].

With data, I replace each Rx[ℓ]R_x[\ell] by an estimate from NN samples. 24.2 divided the N−ℓN-\ell products at lag ℓ\ell by their number. Here I divide by NN:

R^x[ℓ]=1N∑n=ℓN−1x[n] x[n−ℓ].\hat R_x[\ell]=\frac1N\sum_{n=\ell}^{N-1}x[n]\,x[n-\ell].

The reason is stability. With 1N\frac1N, R\mathbf{R} is positive definite: every weighted sum of samples gets a positive power from it, as a real power must. That keeps the error powers of the next section positive, and the fitted model stable. Dividing by N−ℓN-\ell does not promise it.

Solving it one order at a time

Elimination solves pp equations in about p3p^3 steps. The Levinson–Durbin recursion uses the Toeplitz pattern to do it in about p2p^2. It solves the order-1 problem, then grows the answer to order 2, 3, and on up to pp.

It starts from no prediction at all, with error power E0=Rx[0]E_0=R_x[0], the whole power. Going from order m−1m-1 to order mm takes three lines. First the reflection coefficient

km=−Rx[m]+∑k=1m−1ak Rx[m−k]Em−1.k_m=-\frac{R_x[m]+\sum_{k=1}^{m-1}a_k\,R_x[m-k]}{E_{m-1}}.

Then the new coefficients, for k=1,…,m−1k=1,\dots,m-1, all computed from the old ones at once, and one more:

ak←ak+km am−k,am=km.\begin{aligned} a_k&\leftarrow a_k+k_m\,a_{m-k},\\ a_m&=k_m. \end{aligned}

Then the new error power:

Em=Em−1 (1−km2).E_m=E_{m-1}\,(1-k_m^2).

The top of kmk_m has a meaning. It is the average of the order-(m−1)(m-1) error times x[n−m]{x[n-m]}, the one sample the shorter predictor did not use. If the error has nothing in common with it, km=0k_m=0, the coefficients stay as they were, and so does the error power.

The name comes from Filter structures (21.1). In “Three more ways to build it”, the lattice of 1/A(z)1/A(z) had k2=a2k_2=a_2 and k1=a1/(1+a2)k_1=a_1/(1+a_2). That is this recursion at order 2. It sets a2=k2a_2=k_2 and turns a1=k1a_1=k_1 into k1+k2k1=k1(1+k2)k_1+k_2k_1=k_1(1+k_2), so 21.1’s formulas are the recursion read from the aa‘s back to the kk‘s.

21.1 also showed that the biquad’s stability triangle of Stability and causality (16.4), “The triangle is the inside of the circle”, is ∣k1∣<1\lvert k_1\rvert<1 and ∣k2∣<1\lvert k_2\rvert<1. The rule holds at every order: 1/Ap(z)1/A_p(z) is stable when every ∣km∣<1\lvert k_m\rvert<1. A positive definite R\mathbf{R} keeps every EmE_m positive, and Em=Em−1(1−km2)E_m=E_{m-1}(1-k_m^2) then forces each ∣km∣<1\lvert k_m\rvert<1.

Try it on 24.2’s AR(1) noise with a=0.9a=0.9, scaled to variance 1, so Rx[ℓ]=0.9∣ℓ∣R_x[\ell]=0.9^{\lvert\ell\rvert}. Order 1 gives k1=−0.9/1=−0.9k_1=-0.9/1=-0.9 and E1=1⋅(1−0.81)=0.19E_1=1\cdot(1-0.81)=0.19, the driving noise’s power. Order 2 gives k2=−(0.81+(−0.9)(0.9))/0.19=0k_2=-(0.81+(-0.9)(0.9))/0.19=0. The second sample back adds nothing, because the noise is AR(1).

The picture at the top of the page runs the recursion on a known AR(4) process. Its poles are two pairs, 0.950.95 at angles ±0.2π\pm0.2\pi and 0.90.9 at ±0.45π\pm0.45\pi, and σv2=1\sigma_v^2=1. Multiplying out the two biquads gives the coefficients aa = 1, −1.8187, 2.1453, −1.4992, 0.7310. Its true PSD has peaks at 0.20π and 0.44π. The second peak sits a little below its pole angle, because it rides on the downward slope of the first.

One order at a time

That picture feeds the 1N\frac1N estimates R^x[0]\hat R_x[0] to R^x[8]\hat R_x[8] of 4096 samples to the recursion, and shows each order as it is added: a stem for kmk_m and a bar for EmE_m. Its dotted level marks the driving noise’s power, 1, which measures 1.003 for the draws used.

Watch the bars. Each order shrinks the error power, from 13.350 to 1.041 at order 4. Then it stops: from order 4 on, EmE_m stays between 1.040 and 1.041, close to the driving noise’s power. Past the true order the new kmk_m are close to 0, the “nothing in common” case.

Notice also that order 3 helps little, from 2.607 to 2.273, and order 4 a lot. So look for where the error power stops falling for good, not for its first pause.

The estimated order-4 model is aa = 1, −1.8052, 2.1355, −1.4928, 0.7362, against the true 1, −1.8187, 2.1453, −1.4992, 0.7310. SciPy’s solve_toeplitz, which solves Ra=−r\mathbf{R}\mathbf{a}=-\mathbf{r} directly, gives the same numbers to about 10−1510^{-15}, which is rounding error.

Every ∣km∣\lvert k_m\rvert is at most 0.778, so the model is stable: 16.4’s triangle, at order 4. Its poles are 0.952 at ±0.202π\pm0.202\pi and 0.902 at ±0.452π\pm0.452\pi, close to the true 0.95 at ±0.2π\pm0.2\pi and 0.9 at ±0.45π\pm0.45\pi.

A smooth model against a ragged periodogram

Now the payoff: the spectrum. Once I have the aka_k of order pp, the AR estimate of the PSD is the model’s PSD, with the final error power EpE_p standing in for σv2\sigma_v^2:

S^x(ejΩ)=Ep∣Ap(ejΩ)∣2.\hat S_x(e^{j\Omega})=\frac{E_p}{\lvert A_p(e^{j\Omega})\rvert^2}.

Here ApA_p is the order-pp polynomial, and the hat means “estimated”, as in 24.1. The next instrument draws it against the periodogram of 25.1, PN(ejΩ)=1N∣X(ejΩ)∣2P_N(e^{j\Omega})=\frac1N\lvert X(e^{j\Omega})\rvert^2, from the same samples: the first 1024 samples of the record in “One order at a time”, with the fit made from their own autocorrelation.

A peak here is a local maximum that stands at least 2 dB above its surroundings. The distance from the truth is the RMS, over Ω from 0 to π, of the difference in dB between the AR estimate and the true PSD.

A smooth model against a ragged periodogram

1024 samples of the AR(4) noise: the periodogram, the AR(p) estimate and the true PSD.

Order 2: one smooth peak, at 0.26π, where the truth has two (0.20π, 0.44π); distance from the truth 7.2 dB. The periodogram's dots scatter widely about the truth.

order p
2
peaks at
0.26π
distance from truth
7.2 dB
0.00 / 13.00 s
Describe this picture

One panel for 1024 samples of the AR(4) noise: PSD in dB from −30 to 30 against Ω from 0 to π rad/sample. The periodogram is small dots, and a value below −30 dB is drawn on the floor as a small open triangle. The AR(pp) estimate is a solid curve with small filled diamonds at its peaks, and the true PSD is dashed. A key names them “periodogram”, “AR estimate”, “peak” and “true PSD”. The readouts are the order pp, where the peaks are and the distance from the truth. At order 2 there is one smooth peak, at 0.26π, where the truth has two (0.20π, 0.44π), 7.2 dB from the truth; the periodogram’s dots scatter widely about it. At order 4, the true order, the peaks are at 0.20π and 0.45π, 1.3 dB away. At order 20 the same two peaks sit at 0.21π and 0.45π, with a bump near 0.93π (1.4 dB) that the truth does not have, 1.6 dB away. When the clip ends, a slider “Order p”, named “AR order p”, sets the order from 1 to 20. At other orders the caption reads in the form “Order 8: peaks at 0.20π, 0.45π, distance 1.5 dB.”

Watch the solid curve as the order goes from 2 to 4 to 20: one peak between the true two, then both, then both with a bump the truth does not have. More order is not better.

When the clip ends, use the slider to try a few orders. At order 1 there is no peak at all, and the distance is 12.1 dB. Order 3 still finds one peak, at 0.30π, 6.0 dB away. From order 4 the two peaks are there: orders 8 and 12 sit 1.5 dB away and order 16 1.6 dB, a little worse than order 4’s 1.3 dB.

So too low an order merges the two peaks into one, between them. The right order finds both. A much higher order still finds them, but spends its spare coefficients on small bumps the truth does not have.

The periodogram of the same 1024 samples is 6.1 dB away from the truth, worse than any AR estimate from order 4 to 20. Its dots carry no assumption about the shape, and they pay for it in scatter. The AR curve assumes a few poles, and gains a smooth line when that assumption is right.

How do I choose the order with real data, where there is no truth to compare with? I look where the error power of “One order at a time” stops falling. Criteria such as Akaike’s AIC make this a rule: they add a penalty for each coefficient to the logarithm of the error power, and pick the order where the sum is smallest.

The AR estimate needs enough data too, because it is built from estimated correlations. With only the first 256 samples, the order-4 fit’s second peak, near 0.44π, stands just 0.5 dB above its surroundings.

The maths behind it · the partial autocorrelation

In statistics, the AR(pp) model and its partial autocorrelation function, PACF, are these. The PACF at lag mm is −km-k_m, and for an AR(pp) process it is 0 after lag pp. An estimate beyond the true order scatters by about 1/N1/\sqrt{N}, which is 0.016 for clip 1’s 4096 samples: the largest there, 0.022, is 1.4 times that.

Worked example

1. Levinson by hand, two orders. Take Rx[0]=1R_x[0]=1, Rx[1]=0.5R_x[1]=0.5, Rx[2]=0.1R_x[2]=0.1. Order 1: k1=−0.5/1=−0.50k_1=-0.5/1=-0.50, E1=1⋅(1−0.25)=0.75E_1=1\cdot(1-0.25)=0.75 and a1=−0.50a_1=-0.50.

Order 2: k2=−(0.1+(−0.5)(0.5))/0.75k_2=-(0.1+(-0.5)(0.5))/0.75, which is 0.15/0.75=0.200.15/0.75=0.20, and E2=0.75⋅(1−0.04)=0.72E_2=0.75\cdot(1-0.04)=0.72. The new a1=−0.5+0.2⋅(−0.5)=−0.60a_1=-0.5+0.2\cdot(-0.5)=-0.60, and a2=0.20a_2=0.20.

Check both Yule–Walker equations: −0.6⋅1+0.2⋅0.5=−0.5=−Rx[1]-0.6\cdot1+0.2\cdot0.5=-0.5=-R_x[1] and −0.6⋅0.5+0.2⋅1=−0.1=−Rx[2]-0.6\cdot0.5+0.2\cdot1=-0.1=-R_x[2]. The error power checks too: 1+(−0.6)(0.5)+(0.2)(0.1)=0.721+(-0.6)(0.5)+(0.2)(0.1)=0.72.

2. The clip’s data. In “One order at a time” the error power falls from 13.350 to 1.041 at order 4 and then stays flat, 1.041 and 1.040. That is near the driving noise’s measured power, 1.003, so the order is 4.

Where you’ll meet this

Speech is the classic case. A voice is a buzz or a hiss shaped by the throat and mouth, and over a short frame that shaping is close to an all-pole filter. Speech coders at 8 kHz fit an AR model of order 8 to 10 to each frame of 10 to 25 ms, and send its coefficients instead of the samples. The source–filter model of speech (30.1) builds this.

Some coders send the reflection coefficients, or numbers made from them. A kmk_m is easy to keep inside (−1,1)(-1,1) after rounding, so the decoded filter stays stable.

AR estimates also suit short records, where a periodogram cannot separate close peaks. High-resolution frequency estimation (25.4) takes that further. The same Toeplitz system, with a cross-correlation on the right, returns as the Wiener–Hopf equations of The Wiener filter (26.2).

For more, see J. Makhoul, “Linear prediction: a tutorial review” (Proc. IEEE, 1975); J. G. Proakis and D. G. Manolakis, Digital Signal Processing, ch. 12 and 14; and P. Stoica and R. Moses, Spectral Analysis of Signals (2005), ch. 3. In SciPy, solve_toeplitz(r[:p], -r[1:p+1]) solves Yule–Walker, with r holding the estimates R^x[0]\hat R_x[0] to R^x[p]\hat R_x[p].

The maths behind it · symmetric Toeplitz systems

Yule–Walker is a symmetric Toeplitz system, and Levinson–Durbin solves it in about p2p^2 steps instead of p3p^3 by using that structure. The error powers E0,…,EpE_0,\dots,E_p are the pivots of the LDL⊤LDL^\top factorisation, the Cholesky factorisation without square roots, of the (p+1)×(p+1)(p+1)\times(p+1) autocorrelation matrix.

Reference card

QuantityFormulaNotes
AR(pp)x[n]=−∑k=1pakx[n−k]+v[n]x[n]=-\sum_{k=1}^{p}a_kx[n-k]+v[n]PSD σv2/∣A(ejΩ)∣2\sigma_v^2/\lvert A(e^{j\Omega})\rvert^2
MA, ARMAH=B(z)H=B(z), H=B(z)/A(z)H=B(z)/A(z)PSD σv2∣H∣2\sigma_v^2\lvert H\rvert^2
Predictionxpred[n]=−∑k=1pakx[n−k]x_\text{pred}[n]=-\sum_{k=1}^{p}a_kx[n-k]error is xx through A(z)A(z)
Yule–Walker∑kakRx[i−k]=−Rx[i]\sum_ka_kR_x[i-k]=-R_x[i], i=1..pi=1..pRa=−r\mathbf{R}\mathbf{a}=-\mathbf{r}, Toeplitz
Levinson–Durbinkm=−Rx[m]+∑akRx[m−k]Em−1k_m=-\frac{R_x[m]+\sum a_kR_x[m-k]}{E_{m-1}}, Em=Em−1(1−km2)E_m=E_{m-1}(1-k_m^2)E0=Rx[0]E_0=R_x[0]; about p2p^2 steps
Stabilityall ∣km∣<1\lvert k_m\rvert<1lattice of 21.1
AR estimateS^x=Ep/∣Ap(ejΩ)∣2\hat S_x=E_p/\lvert A_p(e^{j\Omega})\rvert^2biased 1N\frac1N correlations
Orderwhere EmE_m stops fallingAIC formalises it

End of lesson 25.3

Where to go next.

Phasorium
LibraryEvery lesson, in order

Parts

About Phasorium
Look