S7 · Lesson 47 · Adaptive filtering lab
LMS system identification, NLMS scale invariance, an echo canceller's ERLE and the Wiener–Hopf solution, in Python
Lessons 34 to 38 developed optimal and adaptive filters on paper. This lab runs them: LMS identifying an unknown system, NLMS shown to behave identically whatever the input level, an echo canceller measured by how much echo it removes, and the Wiener–Hopf equations solved directly for the FIR filter that adaptive filters converge toward.
- The curve is an echo canceller's best possible echo return loss enhancement (ERLE) when the microphone also picks up independent noise: the echo's power over the noise's, .
- No canceller can remove the near-end noise, so that ratio bounds what it can achieve; misadjustment takes a little more.
- With an echo of power 0.35 and noise at σ = 0.01, the bound is 35.4 dB.
Predict
An NLMS filter runs on an input and its desired signal, then again on both scaled by 10. With the same step , how do the two weight trajectories compare?
NLMS divides each update by the input's energy , which scales by 100, while the error times the input scales by 100 too: the update is unchanged. Plain LMS with the same μ would take steps 100 times larger on the scaled data, and here would diverge.
Name it
What the lab computes
- LMS: , , with and zeros before the start.
- NLMS: the step .
- ERLE: over a block after convergence, where e is what's left after the canceller subtracts its echo estimate.
- Wiener–Hopf: solve by Gaussian elimination. For a unit-variance AR(1) signal (a = 0.9) in unit white noise, and .
Check
Write lms(x, d, P, mu): run LMS and return (final weights, list of errors).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write nlms(x, d, P, mu, delta=1e-12): run NLMS and return (final weights, list of errors).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Use your nlms idea to write erle_db(far, echo, noise_sigma, P, mu, seed): the microphone hears echo plus Gaussian noise (from random.Random(seed)); cancel it with a P-tap NLMS filter and return the ERLE over the last 1000 samples (echo power over residual power).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write solve(A, b) (Gaussian elimination with partial pivoting) and wiener_ar1(a, noise_var, P): the P-tap FIR Wiener filter for a unit-variance AR(1) signal with coefficient a in white noise of variance noise_var.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why can an echo canceller never remove more than the ratio of echo to near-end noise, however long it adapts?
The canceller builds an estimate of the echo from the far-end signal, which is all it can see, and subtracts it from the microphone signal. The near-end noise, and the near-end talker's speech, are uncorrelated with the far-end signal, so no filter of the far-end signal can predict or cancel them; they pass through to the residual. Even a perfect echo estimate therefore leaves the noise behind, so the echo return loss enhancement is bounded by the echo's power over the noise's. Adaptation noise, the misadjustment, adds a little more residual on top.