---
title: Adaptive filters
heading: Filters that learn the Wiener solution from data, the LMS algorithm and its step size, stability, convergence time and misadjustment, normalized LMS and RLS, and echo cancellation
eyebrow: S7 · Lesson 37 · Adaptive filters
xp: 50
---

::: hook
The Wiener filter needs the signal's statistics, which in practice are unknown and keep changing: a phone's echo path changes when someone moves, a channel fades, a noise source drifts. An adaptive filter finds the Wiener solution by itself, nudging its coefficients after every sample in the direction that reduces the error. Widrow and Hoff's least-mean-squares algorithm, from 1960, does it with one multiplication per tap per sample and still runs in nearly every speakerphone and modem. Its one design choice, the step size, trades how fast it learns against how precisely it settles.
:::

::: play
- The average weight error of a one-tap LMS filter learning a fixed system with unit-power input, $(1 - \mu)^n$, sample by sample, for step size μ.
- Small steps converge smoothly but slowly, with a time constant of about 1/μ samples. Near μ = 1 it converges in one step.
- Between 1 and 2 the weight overshoots and oscillates while converging; beyond 2 it diverges. Larger μ also leaves more residual noise in the weights, the misadjustment, about μ/2 here.
:::
:::

```sim plot
view: graph
x: n = 0..60
y: e = -1.5..1.5
slider: m = 0.01..2.2 = 0.1
plot: (1 - m)^n | stems | label: mean weight error
readout: time constant, samples = -1/ln(abs(1 - m) + 1e-9)
readout: misadjustment = m/2
```

::: predict
## An echo canceller has 256 taps and its input has power 0.1. Roughly what's the largest LMS step size that keeps it stable?

- [ ] 2
- [ ] 0.2
- [x] About 0.078
- [ ] About 0.0004

::: reveal
A safe bound is $\mu < 2/\text{tr}(R) = 2/(P\sigma_x^2)$ = 2/(256 × 0.1) = 0.078. In practice the step is chosen ten times smaller still, for low misadjustment: μ = 0.0078 gives 10% excess error, with weights converging over about 1280 samples, 0.16 s at 8 kHz.
:::
:::

::: nameit
## The LMS algorithm

For a P-tap filter with weights $\mathbf{w}$ and input vector $\mathbf{x}[n]$, desired response d[n]:

$$e[n] = d[n] - \mathbf{w}^T\mathbf{x}[n], \qquad \mathbf{w} \leftarrow \mathbf{w} + \mu\,e[n]\,\mathbf{x}[n]$$

a stochastic-gradient step on the mean-square error, whose minimum is the Wiener solution $\mathbf{w}_o = R^{-1}\mathbf{p}$.

## Step size

- **Stability** (in the mean): $0 < \mu < 2/\lambda_\text{max}$ of R; the conservative, easily computed bound is $\mu < 2/\text{tr}(R) = 2/(P\sigma_x^2)$.
- **Convergence**: each eigenmode of the weight error decays as $(1 - \mu\lambda_k)^n$, with time constant about $1/(\mu\lambda_k)$ samples. A large eigenvalue spread $\lambda_\text{max}/\lambda_\text{min}$ (a strongly colored input) means some modes converge slowly.
- **Misadjustment**: the excess mean-square error relative to the Wiener minimum, $M \approx \frac{\mu}{2}\text{tr}(R) = \frac{\mu P\sigma_x^2}{2}$.

Fast convergence and small misadjustment pull μ in opposite directions.

## Variants

- **Normalized LMS**: $\mathbf{w} \leftarrow \mathbf{w} + \frac{\tilde{\mu}}{\delta + \|\mathbf{x}\|^2}e\,\mathbf{x}$, stable for $0 < \tilde{\mu} < 2$ whatever the input level; the effective step is about $\tilde{\mu}/(P\sigma_x^2)$.
- **RLS** (recursive least squares) inverts the correlation recursively, converging in about 2P samples regardless of eigenvalue spread, at $O(P^2)$ cost per sample.

## Applications

System identification and **echo cancellation** (the filter models the echo path and subtracts its estimate), **noise cancellation** with a reference microphone, **channel equalization**, and adaptive line enhancers.
:::

::: example
## Design the step size for a 256-tap echo canceller with input power 0.1, aiming for 10% misadjustment.

::: solution
1. **Step size.** Solve $M = \mu P\sigma_x^2/2$ for μ:
   $$\begin{aligned} \mu &= \frac{2(0.1)}{256 \times 0.1} \\ &= 0.0078 \end{aligned}$$
   a tenth of the stability bound 0.078.
2. **Time constant.** For white input every eigenvalue is 0.1, so each weight mode has
   $$\begin{aligned} \tau &= \frac{1}{0.0078 \times 0.1} \\ &= 1280\ \text{samples} \end{aligned}$$
   which is 0.16 s at 8 kHz.
3. **The trade.** Halving the misadjustment would double the convergence time.

**Answer:** μ = 0.0078, which converges with a time constant of 1280 samples (0.16 s).
:::
:::

::: example
## The same canceller uses NLMS with $\tilde{\mu}$ = 0.5. What's its effective step, and what happens when the talker gets 10 dB louder?

::: solution
1. **Effective step.**
   $$\begin{aligned} \mu &\approx \frac{0.5}{256 \times 0.1} \\ &= 0.0195 \end{aligned}$$
   with a misadjustment of about 25%.
2. **Plain LMS, 10 dB louder.** If the input power rises tenfold, plain LMS with a fixed μ would see its effective step, $\mu\sigma_x^2$, rise tenfold, past the stability bound.
3. **NLMS, 10 dB louder.** NLMS divides by $\|\mathbf{x}\|^2$, which rises tenfold too, so its behavior doesn't change.

**Answer:** an effective step of about 0.0195; when the talker gets 10 dB louder, NLMS behaves the same, where plain LMS would go unstable.
:::
:::

::: example
## A one-tap LMS filter with unit-power input uses μ = 0.01. How fast does its mean weight error decay, and what misadjustment does it have?

::: solution
1. **Decay.** The error shrinks as
   $$(1 - \mu)^n = 0.99^n$$
   a time constant of about $1/\mu$ = 100 samples.
2. **Down to 1%.**
   $$\begin{aligned} n &= \frac{\ln 0.01}{\ln 0.99} \\ &= 458\ \text{samples} \end{aligned}$$
3. **Misadjustment.**
   $$\begin{aligned} M &= \mu\sigma_x^2/2 \\ &= 0.5\% \end{aligned}$$
4. **The trade.** Ten times the step would converge ten times faster with ten times the excess error.

**Answer:** the mean weight error decays as $0.99^n$ (a time constant of about 100 samples, 1% after 458), and the misadjustment is 0.5%.
:::
:::

::: check
given: P = 32 | 128 | 512; s = 0.01 | 0.1 | 1
answer: 2/(P*s)
tolerance: 0.5%

## A {P}-tap LMS filter has input power {s}. What's the trace bound on its step size?

::: right
Right. $2/(P\sigma_x^2)$ = {answer}.
:::

::: misses
- [2/s] That's for one tap; the trace of R grows with P.
- [1/(P*s)] The bound is 2/tr(R).
- [any] Not yet. $\mu < 2/\text{tr}(R)$.
:::
:::

::: check
given: m = 0.001 | 0.005 | 0.02; P = 32 | 128; s = 0.1 | 0.5
answer: 100*m*P*s/2
unit: %
tolerance: 0.5%

## An LMS filter with μ = {m}, {P} taps and input power {s}. What's its misadjustment?

::: right
Right. $\mu P\sigma_x^2/2$ = {answer}%.
:::

::: misses
- [100*m*P*s] Half of μ tr(R).
- [any] Not yet. $M \approx \frac{\mu}{2}\text{tr}(R)$.
:::
:::

::: check
given: M = 5 | 10 | 20; P = 64 | 256; s = 0.05 | 0.5
answer: 2*M/100/(P*s)
tolerance: 0.5%

## What step size gives {M}% misadjustment for {P} taps at input power {s}?

::: right
Right. $\mu = 2M/(P\sigma_x^2)$ = {answer}.
:::

::: misses
- [M/100/(P*s)] Misadjustment is μ tr(R)/2, so μ is twice M over tr(R).
- [any] Not yet. Invert $M = \mu P\sigma_x^2/2$.
:::
:::

::: check
given: m = 0.002 | 0.01 | 0.05; l = 0.1 | 0.5 | 2; f = 8 | 48
answer: 1/(m*l)/(f*1000)*1000
unit: ms
tolerance: 0.5%

## A weight mode has eigenvalue {l} and the step size is {m}. At {f} kHz, what's its time constant?

::: right
Right. $1/(\mu\lambda)$ samples = {answer} ms.
:::

::: misses
- [1/(2*m*l)/(f*1000)*1000] That's the mean-square-error time constant; the weight mode's is $1/(\mu\lambda)$.
- [any] Not yet. $(1 - \mu\lambda)^n$ decays with time constant $1/(\mu\lambda)$.
:::
:::

::: check
given: m = 0.3 | 0.8 | 1.5; n = 3 | 10
answer: (1 - m)^n
tolerance: 0.5%

## A one-tap LMS filter with unit-power input uses μ = {m}. What fraction of its initial mean weight error remains after {n} samples (with sign)?

::: right
Right. $(1 - \mu)^n$ = {answer}.
:::

::: misses
- [any] Not yet. Each step multiplies the mean error by $1 - \mu\sigma_x^2$.
:::
:::

::: check
given: u = 0.2 | 0.5 | 1; P = 64 | 256; s = 0.02 | 0.2
answer: u/(P*s)
tolerance: 0.5%

## An NLMS filter uses $\tilde{\mu}$ = {u} with {P} taps at input power {s}. What's its effective LMS step?

::: right
Right. $\tilde{\mu}/\|\mathbf{x}\|^2 \approx \tilde{\mu}/(P\sigma_x^2)$ = {answer}.
:::

::: misses
- [u/s] The norm of the input vector sums P samples' power.
- [any] Not yet. $\|\mathbf{x}\|^2 \approx P\sigma_x^2$.
:::
:::

::: check
kind: parts
given: P = 32 | 128 | 512; s = 0.1 | 1; M = 1 | 5 | 10; f = 8 | 16

## A {P}-tap LMS filter with white input of power {s} at {f} kHz is designed for {M}% misadjustment.

::: part
answer: 2*M/100/(P*s)
tolerance: 0.5%

### What step size does it use?

::: misses
- [M/100/(P*s)] Misadjustment is $\mu P\sigma_x^2/2$.
- [any] $\mu = 2M/(P\sigma_x^2)$.
:::
:::

::: part
answer: 1/(2*M/100/(P*s)*s)/(f*1000)*1000
unit: ms
tolerance: 0.5%

### What is its convergence time constant?

::: misses
- [any] $1/(\mu\lambda)$ samples with λ = σ², converted to time.
:::
:::
:::

::: check
kind: derivation
vars: m = 0.00001..0.1, P = 1..1024, s = 0.01..10

## An LMS filter with step m and P taps sees white input of power s.

::: step
answer: 2/(P*s)

### What is the trace bound on the step?
:::

::: step
answer: m*P*s/2

### What is its misadjustment?
:::

::: step
answer: 1/(m*s)

### What is its time constant in samples?
:::

::: right
Right. The product of misadjustment and time constant is P/2: for a given filter length, speed and accuracy trade one for one.
:::
:::

::: explain
## Why can't an LMS filter both converge quickly and settle precisely?

::: model
LMS updates its weights using the error on each individual sample as an estimate of the true gradient of the mean-square error. That estimate is noisy, since one sample's error is a random quantity. A large step size moves the weights quickly toward the optimum, but it also lets each noisy gradient estimate push the weights around a lot, so even after converging they keep jittering about the Wiener solution, adding excess error. A small step averages the noisy estimates over many samples, so the weights settle close to the optimum, but it takes correspondingly longer to get there. Convergence time goes as 1/μ and misadjustment as μ, so their product is fixed for a given filter and input.
:::
:::

::: practice

::: check
given: P = 16 | 1024; s = 0.05 | 2
answer: 2/(P*s)
tolerance: 0.5%

## Step-size bound: {P} taps, input power {s}?

::: misses
- [any] $2/(P\sigma_x^2)$.
:::
:::

::: check
given: m = 0.002 | 0.01; P = 64 | 200; s = 0.1 | 1
answer: 100*m*P*s/2
unit: %
tolerance: 0.5%

## Misadjustment: μ {m}, {P} taps, power {s}?

::: misses
- [any] $\mu P\sigma_x^2/2$.
:::
:::

::: check
given: m = 0.4 | 1.7; n = 4 | 8
answer: (1 - m)^n
tolerance: 0.5%

## Mean weight error after {n} steps at μ = {m}?

::: misses
- [any] $(1 - \mu)^n$.
:::
:::
:::
