S7 · Lesson 38 · Recursive least squares
Exponentially weighted least squares, the RLS recursion, forgetting, tracking and cost
LMS (lesson 37) takes one cheap gradient step per sample, and with a strongly colored input its slow eigenmodes take thousands of samples to settle. Recursive least squares instead solves the full least-squares problem for all the data so far, updating the solution with each new sample at a cost of order P² instead of P. It converges in about twice the filter length whatever the input's spectrum, and a forgetting factor lets it track a changing system. Echo cancellers, channel equalizers and adaptive arrays that must converge fast use it or its fast variants.
- The curve is RLS's steady-state misadjustment against the forgetting factor λ, for P taps: about .
- λ close to 1 means a long memory, samples, and little excess error; smaller λ forgets faster, tracks changes faster, and is noisier.
- With 10 taps and λ = 0.99 the misadjustment is 5%, from a memory of 100 samples.
Predict
A 4-tap system is identified from 200 samples of a strongly colored input (white noise through a pole at 0.9), with no measurement noise. How do LMS (μ = 0.01) and RLS compare?
The colored input spreads the correlation matrix's eigenvalues over a ratio of hundreds, so LMS's slowest mode has barely moved in 200 samples. RLS solves the normal equations exactly at each step, so once it has more than a handful of samples beyond the four taps its error is set only by the initialization, here about 10⁻⁶.
Name it
The cost and its solution
RLS minimizes the exponentially weighted error
with forgetting factor 0 < λ ≤ 1 (memory about samples). Its solution is with and .
The recursion
Keeping and updating it by the matrix inversion lemma, each sample costs O(P²):
started from w = 0 and with δ small.
Behavior
- Convergence in about 2P samples, independent of the eigenvalue spread.
- Misadjustment for a fixed system, ; with λ = 1 it goes to zero as the data accumulate (it becomes ordinary least squares).
- Tracking: smaller λ follows a changing system faster at the cost of more misadjustment, the same trade as LMS's step size.
- Cost and numerics: O(P²) per sample against LMS's O(P); in finite precision P can lose symmetry and positive definiteness, so robust versions use square-root (QR) forms, and fast transversal or lattice versions bring the cost to O(P) for tapped-delay-line inputs.
Worked example
An RLS filter has 10 taps and λ = 0.99. What memory and misadjustment does it have? What λ gives a memory of 1000 samples?
Show the solution
- Memory.
- Misadjustment.
- For a 1000-sample memory. with misadjustment 0.5%.
- The trade. Tenfold memory gives tenfold lower excess error and tenfold slower tracking.
Answer a memory of 100 samples and 5.0% misadjustment; λ = 0.999 gives a memory of 1000 samples.
Worked example
A one-tap RLS filter with x = 1 every sample, λ = 1 and a huge initial P sees d = 2, 4, 3. What does its weight become?
Show the solution
- What the weight is. With x = 1 the least-squares weight is just the average of the d values so far.
- Step by step. That's 2 after one sample, 3 after two and 3 after three.
- Why. RLS with λ = 1 reproduces ordinary least squares exactly at every step; with λ < 1 it would be an exponentially weighted average instead.
Answer the weight goes 2, 3, 3, ending at 3.
Worked example
A 64-tap echo canceller could use LMS or RLS. Roughly how do their costs per sample compare, and what does RLS buy?
Show the solution
- LMS cost. About 2P = 128 multiplications per sample.
- RLS cost. Standard RLS costs on the order of , here a few thousand.
- What RLS buys. It converges in about 2P = 128 samples regardless of the speech's spectrum, where LMS on colored speech may take tens of thousands.
- Fast RLS. Fast RLS variants exploit the delay-line structure to get RLS's convergence at roughly ten times LMS's cost.
Answer LMS costs about 128 multiplications per sample and RLS a few thousand; RLS buys convergence in about 128 samples whatever the input's spectrum.
Check
An RLS filter has 16 taps and forgetting factor 0.95.
(a)
What is its memory?
(b)
What misadjustment does it have?
Check
An 8-tap RLS filter should remember about 200 samples.
(a)
What forgetting factor does it use?
(b)
What misadjustment results?
Check
A one-tap RLS filter with x = 1, λ = 1 and a huge initial P receives d = 2, 4, 10.
(a)
What is its weight after two samples?
(b)
After three?
Check
A 32-tap adaptive filter runs at 8 kHz.
(a)
Roughly how long does RLS take to converge?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
By roughly what factor does RLS's per-sample cost exceed LMS's (P² against P)?
Check
A channel equalizer must converge within a short training sequence, and the channel's frequency response has deep notches. Why does RLS suit it better than LMS?
Check
An RLS filter has P taps and forgetting factor l.
Step 1
What is its memory in samples?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is its misadjustment?
Step 3
About how many samples does it need to converge?
Check
Write rls(x, d, P, lam=1.0, delta=1e-4): run RLS for a P-tap filter on input x and desired d (lists), starting from w = 0 and P = I/δ, and return the final weights.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does RLS converge in about twice the filter length regardless of the input's spectrum, while LMS can take far longer?
LMS adjusts its weights along the gradient of the error, and with a colored input the error surface is a long, narrow valley: the gradient points mostly across the valley, so progress along it is slow, with a speed set by the smallest eigenvalue of the input's correlation matrix. RLS instead solves the least-squares problem exactly at each step using the inverse of the correlation matrix, which is equivalent to whitening the input before adapting; every direction then converges at the same rate. Once it has seen enough samples to estimate the P × P matrix, about twice the number of taps, the solution is essentially found, at the cost of order P² operations per sample.
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.