|
| 1 | +# LMS / NLMS Adaptive Filter |
| 2 | + |
| 3 | +## Overview & Motivation |
| 4 | + |
| 5 | +Real-time systems frequently need filters whose characteristics are unknown in advance or change over time. A fixed-coefficient FIR filter cannot cancel acoustic echo from an unknown loudspeaker-to-microphone path, equalize a time-varying channel, or identify the impulse response of a vibrating structure it has never seen before. The Least Mean Squares (LMS) algorithm and its normalized variant (NLMS) address this by adjusting a FIR filter's coefficients online, one sample at a time, without requiring matrix inversions or covariance storage. |
| 6 | + |
| 7 | +## Mathematical Theory |
| 8 | + |
| 9 | +### Prerequisites |
| 10 | + |
| 11 | +Let $\mathbf{w} \in \mathbb{R}^{N}$ be the weight vector (FIR coefficients) and $\mathbf{x}_n \in \mathbb{R}^{N}$ the tapped-delay-line vector at time $n$, with $x_n$ as the newest sample and $x_{n-N+1}$ the oldest. The filter output is |
| 12 | + |
| 13 | +$$y_n = \mathbf{w}_n^\top \mathbf{x}_n.$$ |
| 14 | + |
| 15 | +Given a desired signal $d_n$, the estimation error is |
| 16 | + |
| 17 | +$$e_n = d_n - y_n.$$ |
| 18 | + |
| 19 | +### Core Definitions |
| 20 | + |
| 21 | +The instantaneous squared error $J_n = e_n^2$ is a quadratic function of $\mathbf{w}_n$. Its gradient with respect to $\mathbf{w}$ is |
| 22 | + |
| 23 | +$$\nabla J_n = -2 e_n \mathbf{x}_n.$$ |
| 24 | + |
| 25 | +### Derivation |
| 26 | + |
| 27 | +LMS takes a noisy steepest-descent step using the instantaneous gradient: |
| 28 | + |
| 29 | +$$\mathbf{w}_{n+1} = \mathbf{w}_n - \frac{\mu}{2} \nabla J_n = \mathbf{w}_n + \mu e_n \mathbf{x}_n.$$ |
| 30 | + |
| 31 | +NLMS divides the step by the input energy to make the effective step size input-level independent: |
| 32 | + |
| 33 | +$$\mathbf{w}_{n+1} = \mathbf{w}_n + \frac{\mu}{\epsilon + \|\mathbf{x}_n\|^2} e_n \mathbf{x}_n,$$ |
| 34 | + |
| 35 | +where $\epsilon > 0$ is a small regularizer that prevents division by zero during silence ($\|\mathbf{x}_n\|^2 \approx 0$). |
| 36 | + |
| 37 | +### Proof of Correctness |
| 38 | + |
| 39 | +Under the independence assumption (successive input vectors are uncorrelated), the expected weight vector converges to the Wiener solution $\mathbf{w}^* = \mathbf{R}^{-1}\mathbf{p}$ (where $\mathbf{R}$ is the input autocorrelation matrix and $\mathbf{p}$ is the cross-correlation vector) provided |
| 40 | + |
| 41 | +$$0 < \mu < \frac{2}{\lambda_{\max}(\mathbf{R})},$$ |
| 42 | + |
| 43 | +a sufficient condition being $\mu < 2 / (N \cdot \sigma_x^2)$. For NLMS the stability range simplifies to $0 < \mu < 2$. |
| 44 | + |
| 45 | +## Complexity Analysis |
| 46 | + |
| 47 | +| Case | Time | Space | Notes | |
| 48 | +|------|--------|--------|---------------------------------------------| |
| 49 | +| Any | $O(N)$ | $O(N)$ | Two dot products + one AXPY, all length $N$ | |
| 50 | + |
| 51 | +No covariance matrix is stored; memory is exactly two vectors of length $N$ (weights and delay line). |
| 52 | + |
| 53 | +## Step-by-Step Walkthrough |
| 54 | + |
| 55 | +Consider a 2-tap system with true plant $\mathbf{w}^* = [0.5,\ 0.5]^\top$, $\mu = 0.1$, and a white input sequence. |
| 56 | + |
| 57 | +| Step | Input | Delay line $\mathbf{x}$ | Output $y$ | Desired $d$ | Error $e$ | Weight update direction | |
| 58 | +|------|-------|-------------------------|------------|-------------|-----------|-----------------------------| |
| 59 | +| 1 | 1.0 | [1.0, 0.0] | 0.0 | 0.5 | 0.5 | $+0.05\mathbf{x}$ | |
| 60 | +| 2 | 0.8 | [0.8, 1.0] | 0.04 | 0.9 | 0.86 | $+0.086\mathbf{x}$ | |
| 61 | +| … | … | … | … | … | … | converges to $\mathbf{w}^*$ | |
| 62 | + |
| 63 | +After many iterations the error approaches zero and the weights stabilize near $[0.5,\ 0.5]^\top$. |
| 64 | + |
| 65 | +## Pitfalls & Edge Cases |
| 66 | + |
| 67 | +- **Stability bound:** exceeding $\mu_{\max}$ causes exponential weight growth. For stationary white input, $\mu_{\max} = 2 / (N\sigma_x^2)$. |
| 68 | +- **Misadjustment:** even at steady state, random gradient noise keeps the weights oscillating around $\mathbf{w}^*$, adding excess mean-squared error proportional to $\mu N$. |
| 69 | +- **Slow convergence vs stability tradeoff:** small $\mu$ gives low misadjustment but slow tracking; large $\mu$ tracks fast but overshoots. |
| 70 | +- **Silent input:** $\|\mathbf{x}_n\|^2 = 0$ causes a singularity in plain NLMS; $\epsilon$ prevents this but freezes adaptation during silence. |
| 71 | +- **Non-persistent excitation:** if the input does not excite all directions, some weights may drift. Leaky-LMS ($\mathbf{w} \leftarrow (1-\rho)\mathbf{w} + \mu e \mathbf{x}$) bounds the drift. |
| 72 | + |
| 73 | +## Variants & Generalizations |
| 74 | + |
| 75 | +- **NLMS:** normalizes step by input energy; removes input-power dependence; recommended for signals with variable amplitude. |
| 76 | +- **Leaky LMS:** adds a forgetting term $\rho \ll 1$ to bound weight norm under insufficient excitation. |
| 77 | +- **Block LMS:** accumulates gradients over a block before updating; lower update rate but more FFT-friendly for long filters. |
| 78 | +- **Sign-LMS / Sign-Error LMS:** replaces $e$ or $\mathbf{x}$ with their signs; extremely simple hardware implementation at the cost of convergence rate. |
| 79 | +- **RLS:** replaces the stochastic gradient with the exact least-squares update; converges in $O(N)$ steps but requires $O(N^2)$ memory and time per update. |
| 80 | + |
| 81 | +## Applications |
| 82 | + |
| 83 | +- **Acoustic echo cancellation:** adapt the loudspeaker-to-microphone path in teleconferencing. |
| 84 | +- **Adaptive noise cancellation:** estimate and subtract a correlated noise source (e.g. engine noise on an aircraft headset). |
| 85 | +- **Channel equalization:** track a time-varying ISI channel in wireless modems. |
| 86 | +- **Active noise control / vibration control:** generate an anti-phase signal to cancel mechanical vibration. |
| 87 | +- **Online system identification:** recover the impulse response of an unknown plant in real time. |
| 88 | + |
| 89 | +## Connections to Other Algorithms |
| 90 | + |
| 91 | +- **RecursiveLeastSquares:** the exact-gradient counterpart; converges in far fewer samples but needs $O(N^2)$ storage and time per step. Prefer RLS for short filter lengths or fast convergence; prefer LMS/NLMS for embedded, resource-constrained paths. |
| 92 | +- **FIR (fixed-coefficient):** LMS turns a fixed FIR into a self-tuning one; the underlying convolution is identical. |
| 93 | +- **ConvolutionCorrelation:** used to compute the cross-correlation $\mathbf{p}$ in the batch Wiener solution; LMS approximates this online. |
| 94 | + |
| 95 | +## References & Further Reading |
| 96 | + |
| 97 | +- B. Widrow, M. E. Hoff, "Adaptive switching circuits," *IRE WESCON Convention Record*, 1960. |
| 98 | +- S. Haykin, *Adaptive Filter Theory*, 5th ed., Pearson, 2014 — chapters 5–8. |
| 99 | +- S. Sayed, *Fundamentals of Adaptive Filtering*, Wiley, 2003. |
| 100 | +- D. G. Manolakis, V. K. Ingle, S. M. Kogon, *Statistical and Adaptive Signal Processing*, Artech House, 2005. |
0 commit comments