S747 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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, 10log10⁡(Pecho/σn2).
  • 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?

Name it

What the lab computes

  • LMS: e=d−𝐰T𝐱, 𝐰←𝐰+μe𝐱, with 𝐱[n]=[x[n],…,x[n−P+1]] and zeros before the start.
  • NLMS: the step μ~/(δ+‖𝐱‖2).
  • ERLE: 10log10⁡∑echo2∑e2 over a block after convergence, where e is what's left after the canceller subtracts its echo estimate.
  • Wiener–Hopf: solve ∑kh[k]ϕxx[i−k]=ϕsx[i] by Gaussian elimination. For a unit-variance AR(1) signal (a = 0.9) in unit white noise, ϕxx[m]=0.9|m|+δ[m] and ϕsx[m]=0.9|m|.

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?