---
title: Equalization with an adaptive filter
heading: Undoing a channel's echoes with a filter, the zero-forcing equalizer as the channel's inverse and how many taps it needs, the noise it amplifies at the channel's notches, the LMS algorithm that learns the taps from a training sequence and then from its own decisions, and its step size
eyebrow: D12 · Lesson 11 · Equalization
xp: 40
---

::: hook
If the channel adds an echo, a filter at the receiver can subtract it again, but only if it knows the echo's size and delay, and in a room those change every time someone moves. An **adaptive equalizer** learns them. It starts with a known training sequence, compares its output with what it knows was sent, and nudges its taps to shrink the error, thousands of times a second. Once trained it keeps adapting on its own decisions. Every dial-up modem, DSL line and Wi-Fi radio does a version of this.
:::

::: play
- A channel with an echo of size a one symbol late, $H = 1 + a z^{-1}$, and an N-tap zero-forcing equalizer, the first N terms of its inverse: $1 - az^{-1} + a^2z^{-2} - \cdots$. The x axis is frequency in symbol rates.
- The equalizer boosts where the channel dips, and together they're nearly flat. The leftover ripple is an echo of size $a^N$, N symbols late.
- Push a toward 1: the channel's notch deepens, the equalizer's boost there grows, and so does the noise it amplifies.
:::

```sim plot
view: graph
x: f = 0..1
y: G = -25..25
slider: a = 0.1..0.95 step 0.05 = 0.6
slider: N = 1..12 step 1 = 4
plot: 10*log(1 + 2*a*cos(2*pi*f) + a^2) | samples: 600 | label: channel, dB (f in symbol rates)
plot: 10*log(1 - 2*(-a)^N*cos(2*pi*N*f) + a^(2*N)) - 10*log(1 + 2*a*cos(2*pi*f) + a^2) | samples: 600 | color: ch3 | label: equalizer
plot: 10*log(1 - 2*(-a)^N*cos(2*pi*N*f) + a^(2*N)) | samples: 600 | color: ch4 | label: channel and equalizer together
readout: leftover echo, dB = 20*N*log(a) | digits: 3
readout: noise enhancement of the full inverse, dB = 10*log(1/(1 - a^2)) | digits: 3
```

::: predict
## An echo of half the direct signal's size arrives one symbol late. How many taps must a zero-forcing equalizer have to leave less than 1% of echo?

- [ ] 2
- [ ] 4
- [x] 7
- [ ] 100

::: reveal
The inverse of $1 + 0.5z^{-1}$ has taps 1, −0.5, 0.25, −0.125, ..., and cutting it after N taps leaves an echo of $0.5^N$. $0.5^6$ = 1.6% and $0.5^7$ = 0.78%, so 7 taps. An echo nearly as big as the direct path would need many more, since $a^N$ shrinks slowly when a is near 1.
:::
:::

::: nameit
## Zero forcing

An equalizer $G(z)$ after the channel $H(z)$ removes ISI when $G(z)H(z) = z^{-\Delta}$, a pure delay. For $H = 1 + az^{-1}$ with |a| < 1, $G = \sum_k (-a)^kz^{-k}$, and truncating to N taps leaves $1 - (-a)^Nz^{-N}$, an echo of $|a|^N$.

## Noise enhancement

Where the channel has a deep notch, the inverse has a tall peak, and it amplifies the noise there just as much. For the full inverse of $1 + az^{-1}$, white noise power grows by $\sum_k a^{2k} = 1/(1 - a^2)$: 1.25 dB at a = 0.5, 7.2 dB at a = 0.9. The **MMSE** equalizer balances leftover ISI against noise and is what LMS converges to.

## LMS

With the last N received samples in a vector **x**, taps **w**, output $y = \mathbf w^\mathsf T\mathbf x$ and the desired symbol d (from the training sequence, or the decision once trained):

$$e = d - y, \qquad \mathbf w \leftarrow \mathbf w + \mu e\mathbf x$$

Each update steps the taps a little way down the gradient of $e^2$. The step μ trades speed against noise: it must stay below $2/(NP)$, with P the received power, or the taps diverge, and smaller steps converge slower but settle closer to the optimum.

## Decision-directed mode

After training, the receiver's own decisions stand in for d. While most decisions are right, the equalizer keeps tracking slow changes in the channel.
:::

::: example
## What are the first four zero-forcing taps for an echo of 0.5 one symbol late, and how much echo is left?

::: solution
1. **The taps.** Inverting the echo term by term gives
   $$1,\ -0.5,\ 0.25,\ -0.125$$
2. **Product with the channel.**
   $$1 - 0.0625z^{-4}$$
3. **Leftover echo.** An echo of 0.0625 remains four symbols late:
   $$20\log_{10}0.0625 = -24.1\ \text{dB}$$

**Answer:** the taps are 1, −0.5, 0.25 and −0.125, and an echo of 0.0625 (−24.1 dB) remains four symbols late.
:::
:::

::: example
## An 11-tap LMS equalizer sees received samples of power 2. What's the largest stable step size?

::: solution
1. **Stability limit.**
   $$\begin{aligned} \mu_{\max} &= \frac{2}{NP} \\ &= \frac{2}{11 \times 2} \\ &= 0.091 \end{aligned}$$
2. **In practice.** μ is chosen several times smaller, like 0.01, so the taps settle without much jitter.

**Answer:** about 0.091.
:::
:::

::: example
## How many equalizer taps does it take to span 5 ms of echo at 1200 baud?

::: solution
1. **Echo span in symbols.**
   $$0.005 \times 1200 = 6\ \text{symbols}$$
2. **Taps.** The main tap plus six makes at least 7 taps.
3. **Fractionally spaced equalizers.** Sampling twice per symbol, they need about twice as many.

**Answer:** at least 7 taps.
:::
:::

::: check
kind: python

## Train an LMS equalizer and let it run on its own decisions.

```python starter
import numpy as np

def lms_equalize(r, train, ntaps, mu):
    # r holds received BPSK samples, one per symbol; train holds the known symbols sent first.
    # Keep taps w (ntaps of them, all 0 except w[0] = 1). For each n:
    #   x = [r[n], r[n-1], ..., r[n-ntaps+1]] (zeros before the start), y = w @ x;
    #   d = train[n] while n < len(train), afterwards the decision sign(y);
    #   e = d - y and w += mu*e*x.
    # Return (outputs y as an array, final w).
    return np.array(r, dtype=float), np.r_[1.0, np.zeros(ntaps - 1)]
```

```python solution
import numpy as np

def lms_equalize(r, train, ntaps, mu):
    w = np.zeros(ntaps); w[0] = 1.0
    buf = np.zeros(ntaps)
    out = np.empty(len(r))
    for n, v in enumerate(r):
        buf = np.r_[v, buf[:-1]]
        y = w @ buf
        out[n] = y
        d = train[n] if n < len(train) else (1.0 if y >= 0 else -1.0)
        w += mu*(d - y)*buf
    return out, w
```

```python tests
_rng = np.random.default_rng(11)
_s = _rng.choice([-1.0, 1.0], 6000)
_r = np.convolve(_s, [1.0, 0.9, 0.4])[:6000] + 0.05*_rng.standard_normal(6000)
assert np.mean(np.sign(_r[1000:]) != _s[1000:]) > 0.05, "This channel closes the eye: unequalized decisions are often wrong."
_y, _w = lms_equalize(_r, _s[:1000], 11, 0.01)
assert len(_y) == 6000 and len(_w) == 11, "One output per input, and the final taps."
assert np.all(np.sign(_y[1000:]) == _s[1000:]), "After 1000 training symbols, every decision should be right."
assert abs(_w[0] - 1) < 0.05 and abs(_w[1] + 0.9) < 0.05 and abs(_w[2] - 0.41) < 0.05, f"The taps should approach the channel's inverse, 1, −0.9, 0.41, ...; got {np.round(_w[:3], 3)}."
```

::: right
Right. Your equalizer learns the inverse of the channel from 1000 training symbols and then gets every decision right on its own.
:::
:::

::: check
given: a = 0.3 | 0.5 | 0.8; k = 1 | 3 | 5
answer: (-a)^k
tolerance: 0.5%

## A channel $1 + az^{-1}$ has a = {a}. What's tap number {k} (counting from 0) of its zero-forcing equalizer?

::: right
Right. $(-a)^k$ = {answer}.
:::

::: misses
- [a^k] Mind the sign: the taps alternate, and odd ones are negative.
- [any] Not yet. Expand $1/(1 + az^{-1})$.
:::
:::

::: check
given: a = 0.3 | 0.5 | 0.8 | 0.9; N = 3 | 5 | 8
answer: 20*N*log(a)
unit: dB
tolerance: 0.5%

## An {N}-tap zero-forcing equalizer works against an echo of size {a}. How strong is the echo left over, in dB?

::: right
Right. $a^N$ is {answer} dB.
:::

::: misses
- [10*N*log(a)] The echo is an amplitude: 20 log.
- [any] Not yet. The leftover echo is $a^N$.
:::
:::

::: check
given: a = 0.3 | 0.5 | 0.7 | 0.9
answer: 10*log(1/(1 - a^2))
unit: dB
tolerance: 0.5%

## A full zero-forcing equalizer undoes an echo of size {a}. How much does it raise white noise power?

::: right
Right. $1/(1 - a^2)$ = {answer} dB.
:::

::: misses
- [20*log(1/(1 - a))] That's the peak gain at the notch; on average across the band it's less.
- [any] Not yet. The sum of the squared taps.
:::
:::

::: check
given: N = 5 | 11 | 31; P = 0.5 | 1 | 2
answer: 2/(N*P)
tolerance: 0.5%

## An LMS equalizer has {N} taps and its input has power {P}. What's the largest stable step size?

::: right
Right. $2/(NP)$ = {answer}.
:::

::: misses
- [1/(N*P)] The bound has a 2.
- [any] Not yet. The step bound scales with total input power across the taps.
:::
:::

::: check
kind: parts
given: a = 0.3 | 0.5 | 0.7; n = 3 | 4 | 6

## A zero-forcing equalizer cancels an echo of {a} one symbol late with {n} taps: 1, −a, a², ….

::: part
answer: a^n
tolerance: 0.5%

### How much echo remains?

::: misses
- [any] $a^n$.
:::
:::

::: part
answer: 20*log(a^n)
unit: dB
tolerance: 0.5%

### In decibels?

::: misses
- [any] $20\log_{10}a^n$.
:::
:::
:::

::: check
kind: parts
given: N = 7 | 11 | 31; P = 0.5 | 1 | 2; t = 2 | 5 | 10; R = 1200 | 2400

## An {N}-tap LMS equalizer sees samples of power {P}; the echo it must cover lasts {t} ms at {R} baud.

::: part
answer: 2/(N*P)
tolerance: 0.5%

### What is the largest stable step size?

::: misses
- [any] $2/(NP)$.
:::
:::

::: part
answer: t/1000*R + 1
unit: taps
tolerance: 0.5%

### How many symbol-spaced taps does covering the echo need?

::: misses
- [any] Echo in symbols, plus the main tap.
:::
:::
:::

::: explain
## Why does an LMS equalizer need a training sequence to start, but not once it's working?

::: model
LMS adjusts its taps by comparing its output with the symbol that was actually sent, and it can only do that if it knows what was sent. At the start, the channel's echoes may close the eye so badly that the receiver's own decisions are often wrong, and adapting toward wrong answers would steer the taps the wrong way. A known training sequence gives correct targets until the taps are good enough to open the eye. From then on, nearly all decisions are right, so they can serve as the targets, and the equalizer keeps following slow changes in the channel without any more training.
:::
:::

::: practice

::: check
given: a = 0.2 | 0.6 | 0.95; N = 2 | 10 | 20
answer: 20*N*log(a)
unit: dB
tolerance: 0.5%

## Leftover echo: {N} taps, echo {a}?

::: misses
- [any] $20N\log_{10}a$.
:::
:::

::: check
given: N = 3 | 64; P = 0.1 | 4
answer: 2/(N*P)
tolerance: 0.5%

## LMS step bound: {N} taps, power {P}?

::: misses
- [any] $2/(NP)$.
:::
:::
:::
