---
title: Inverse systems and deconvolution
heading: Undoing a system's effect, when it's possible, and what it costs in noise when it barely is
eyebrow: C9 · Lesson 40 · Inverse systems and deconvolution
xp: 40
---

::: hook
A phone call through a room adds an echo; a cable smears a data signal's pulses; a camera blurs an image; a sensor responds slowly. Each is an LTI system, and the natural wish is to apply its inverse and get the original back. Lesson 39 drew systems as poles and zeros, and the inverse simply swaps them: zeros become poles. That's the whole difficulty. A zero outside the unit circle becomes an unstable pole, and a zero near the circle, where the system nearly kills a frequency, becomes a pole that amplifies whatever noise is there enormously. Engineering inverses means deciding how much to undo.
:::

::: play
- A channel with an echo, $H(z) = 1 + az^{-D}$, and its inverse, $1/H(z)$, plotted as gain in dB against frequency. The echo makes a comb of peaks and notches; the inverse is its mirror image.
- As $a$ approaches 1, the channel's notches deepen toward zero gain and the inverse's peaks shoot up: any noise at those frequencies is amplified by the same amount.
:::

```sim plot
view: graph
x: w = 0..3.1416
y: G = -20..20
slider: a = 0..0.98 step 0.01 = 0.5
slider: D = 1..8 step 1 = 3
plot: 10*log(1 + a^2 + 2*a*cos(D*w)) | label: channel, dB
plot: -10*log(1 + a^2 + 2*a*cos(D*w)) | dashed | color: ch2 | label: inverse, dB
readout: largest gain of the inverse, dB = -20*log(1 - a)
```

::: predict
## A channel is $H(z) = 1 - 2z^{-1}$. Can a causal, stable filter undo it exactly?

- [ ] Yes: $1/(1 - 2z^{-1})$
- [x] No: the inverse has a pole at $z$ = 2, outside the unit circle
- [ ] Yes, with a gain of 1/2
- [ ] No, because the channel has no poles

::: reveal
The channel's zero at $z$ = 2 becomes the inverse's pole at $z$ = 2, and a causal system with a pole outside the unit circle is unstable: its impulse response is $2^n$. A stable inverse exists only if it's allowed to be anticausal (running backward in time, possible offline), or if we settle for equalizing the magnitude with the minimum-phase system $2 - z^{-1}$, whose inverse is stable.
:::
:::

::: nameit
## The inverse system

If $H(z)$ has zeros $z_k$ and poles $p_k$, then $H^{-1}(z) = 1/H(z)$ has poles at $z_k$ and zeros at $p_k$. Cascading them gives $H(z)H^{-1}(z) = 1$: the signal comes back exactly. A causal inverse is stable only if every zero of $H$ is inside the unit circle.

## Minimum phase

A system whose poles and zeros are all inside the unit circle is **minimum phase**, and it has a causal, stable inverse. Any rational system can be split as

$$H(z) = H_{min}(z)\,H_{ap}(z)$$

a minimum-phase part times an **all-pass** part (lesson 39's flat-magnitude section): reflect each outside zero $z_k$ to $1/z_k^*$ and absorb the difference into the all-pass. The minimum-phase part has the same magnitude response, so $1/H_{min}$ equalizes the magnitude perfectly, leaving only the all-pass phase distortion.

## Echoes

An echo of strength $a$ and delay $D$ samples, $H(z) = 1 + az^{-D}$, has $D$ zeros on a circle of radius $|a|^{1/D}$. If $|a| < 1$ it's minimum phase, and its inverse is the recursion

$$w[n] = y[n] - a\,w[n - D]$$

which removes the echo exactly.

## Noise and regularization

Real signals carry noise. Where $|H|$ is small, the inverse's gain $1/|H|$ is large, and so is the noise it amplifies. A **regularized** inverse limits that:

$$G(e^{j\omega}) = \frac{H^*(e^{j\omega})}{|H(e^{j\omega})|^2 + \lambda}$$

It behaves like $1/H$ where $|H|^2 \gg \lambda$ and rolls off where $|H|$ is tiny; its gain never exceeds $1/(2\sqrt\lambda)$. Choosing $\lambda$ from the noise level gives the Wiener deconvolution filter.
:::

::: example
## A telephone line adds an echo half as strong as the direct signal, 40 samples later: $y[n] = x[n] + 0.5x[n - 40]$. Write the inverse and check that it removes the echo.

::: solution
1. **Zeros of the echo.**
   $$H(z) = 1 + 0.5z^{-40}$$
   has zeros at radius $0.5^{1/40}$ = 0.983: inside the circle, so it's minimum phase.
2. **The inverse.**
   $$w[n] = y[n] - 0.5w[n - 40]$$
3. **Check it.** Substituting:
   $$\begin{aligned} w[n] &= x[n] + 0.5x[n - 40] \\ &\quad - 0.5w[n - 40] \end{aligned}$$
   and if $w = x$ up to now, $w[n] = x[n]$ again.
4. **The cost.** Its gain swings between $1/1.5$ and $1/0.5$ = 2, 6 dB of boost at the echo's notches: noise at those frequencies doubles.

**Answer:** the inverse is $w[n] = y[n] - 0.5w[n - 40]$, which gives back x exactly, at the cost of up to 6 dB of noise boost at the echo's notches.
:::
:::

::: example
## Split $H(z) = 1 - 2z^{-1}$ into a minimum-phase part and an all-pass part, and give a stable magnitude equalizer.

::: solution
1. **Reflect the zero.** Move the zero at 2 to $1/2$:
   $$\begin{aligned} H_{min}(z) &= 2 - z^{-1} \\ &= 2(1 - 0.5z^{-1}) \end{aligned}$$
2. **Same magnitude.** It has the same magnitude as $H$ at every frequency, since
   $$|1 - 2e^{-j\omega}| = 2|1 - 0.5e^{j\omega}|$$
3. **All-pass part.** This has unit magnitude:
   $$H_{ap} = \frac{1 - 2z^{-1}}{2 - z^{-1}}$$
4. **Equalizer.** It's stable and flattens the magnitude:
   $$1/H_{min} = \frac{0.5}{1 - 0.5z^{-1}}$$
5. **What's left.** The phase of $H_{ap}$ remains, which matters for data but not for, say, a loudspeaker's tonal balance.

**Answer:** $H_{min} = 2 - z^{-1}$ and $H_{ap} = (1 - 2z^{-1})/(2 - z^{-1})$, and the stable equalizer is $0.5/(1 - 0.5z^{-1})$.
:::
:::

::: example
## A sensor's response falls to $|H|$ = 0.05 at high frequencies, where the measurement noise lives. Compare the plain inverse's gain there with a regularized inverse using λ = 0.01, and give the regularized filter's largest gain.

::: solution
1. **Plain inverse.**
   $$1/0.05 = 20$$
   or 26 dB of noise gain.
2. **Regularized inverse.**
   $$\begin{aligned} |G| &= 0.05/(0.0025 + 0.01) \\ &= 4 \end{aligned}$$
   or 12 dB.
3. **Largest gain.** It's reached where $|H| = \sqrt\lambda$ = 0.1:
   $$1/(2\sqrt{0.01}) = 5$$
4. **Below that point.** The filter gives up on restoring the signal, because there's more noise than signal to restore.

**Answer:** the plain inverse's gain there is 20 (26 dB) and the regularized one's is 4 (12 dB); the regularized filter's largest gain is 5.
:::
:::

::: check
given: a = 0.3 | 0.5 | 0.8 | 0.95
answer: -20*log(1 - a)
tolerance: 0.5%

## A channel adds an echo of strength {a}. What's the largest gain of its inverse, in dB?

::: right
Right. The channel's deepest notch is $1 - a$, so the inverse peaks at $-20\log_{10}(1 - a)$ = {answer} dB.
:::

::: misses
- [20*log(1 + a)] That's the channel's peak. The inverse's peak sits at the channel's notch.
- [-10*log(1 - a)] Amplitude ratios use 20 log.
- [any] Not yet. The inverse's gain is $1/|1 + ae^{-jD\omega}|$, largest when that's $1 - a$.
:::
:::

::: check
given: a = 0.2 | 0.5 | 0.9; D = 4 | 10 | 40
answer: a^(1/D)
tolerance: 0.5%

## An echo channel $1 + az^{-D}$ has $a$ = {a} and $D$ = {D}. On what radius do its zeros lie?

::: right
Right. $|a|^{1/D}$ = {answer}: inside the unit circle, so the inverse is stable.
:::

::: misses
- [a] The $D$ zeros solve $z^D = -a$, so their radius is $|a|^{1/D}$.
- [1/a^(1/D)] That's the reflected radius. Solve $z^D = -a$.
- [any] Not yet. $z^D = -a$ gives $|z| = |a|^{1/D}$.
:::
:::

::: check
given: H = 0.01 | 0.05 | 0.2; L = 0.001 | 0.01 | 0.05
answer: 20*log(H/(H^2 + L))
tolerance: 1%

## Where a system's gain is {H}, what's the gain of a regularized inverse with λ = {L}, in dB?

::: right
Right. $|H|/(|H|^2 + \lambda)$ = {answer} dB.
:::

::: misses
- [20*log(1/H)] That's the plain inverse. Regularization adds λ to the denominator.
- [10*log(H/(H^2 + L))] It's an amplitude ratio: 20 log.
- [any] Not yet. $|G| = |H|/(|H|^2 + \lambda)$.
:::
:::

::: check
given: L = 0.0001 | 0.001 | 0.01 | 0.1
answer: 1/(2*sqrt(L))
tolerance: 0.5%

## What's the largest gain any frequency can get from a regularized inverse with λ = {L}?

::: right
Right. $|H|/(|H|^2 + \lambda)$ peaks at $|H| = \sqrt\lambda$, at $1/(2\sqrt\lambda)$ = {answer}.
:::

::: misses
- [1/sqrt(L)] At $|H| = \sqrt\lambda$ the denominator is $2\lambda$.
- [1/L] The peak comes where $|H| = \sqrt\lambda$, not where $|H|$ = 1.
- [any] Not yet. Maximize $x/(x^2 + \lambda)$.
:::
:::

::: check
kind: parts
given: z = 1.5 | 2 | 4

## A channel is $H(z) = 1 - \given{z}z^{-1}$.

::: part
answer: 1/z
tolerance: 0.5%

### Reflect its zero inside the unit circle. Where is the minimum-phase zero?

::: misses
- [-z] Reflect to the reciprocal radius, $1/z_k^*$.
- [any] Not yet. $1/z$.
:::
:::

::: part
answer: z
tolerance: 0.5%

### What gain $c$ makes $H_{min}(z) = c(1 - z^{-1}/\given{z})$ have the same magnitude as $H$ at every frequency?

::: misses
- [1/z] Compare at $\omega = 0$: $|1 - \given{z}| = c|1 - 1/\given{z}|$.
- [any] Not yet. Match the magnitudes at any one frequency.
:::
:::

::: right
Right. $H_{min}(z) = \given{z} - z^{-1}$ has the same magnitude as $H$ everywhere, and its inverse is stable.
:::
:::

::: check
kind: choice

## Which systems have a causal, stable inverse?

- [x] Those whose zeros (and poles) are all inside the unit circle
- [ ] Those whose poles are all inside the unit circle
- [ ] Any FIR system
- [ ] Any stable system

::: right
Right. The inverse's poles are the system's zeros, so they must be inside the circle: the system must be minimum phase.
:::

::: misses
- [2] The inverse's stability depends on the zeros, not the poles.
- [3] An FIR system with a zero outside the circle, like $1 - 2z^{-1}$, has an unstable causal inverse.
- [4] Stability of the system says nothing about where its zeros are.
:::
:::

::: check
kind: python
given: a = 0.3 | 0.6 | 0.9; D = 5 | 20; seed = 1 | 2

## Remove an echo. With `x = numpy.random.default_rng(seed).standard_normal(2000)`, the channel output is `y[n] = x[n] + a*x[n - D]` (zero before the start). Write `dereverb(y, a, D)` implementing the inverse recursion and set `err` to the largest absolute difference from `x`. Then add noise, `y2 = y + 0.01*numpy.random.default_rng(seed + 100).standard_normal(2000)`, invert it, and set `noise_gain`, the RMS of the error divided by the RMS of the added noise.

```python starter
import numpy as np
def dereverb(y, a, D):
    return y.copy()
err = noise_gain = 0.0
```

```python solution
import numpy as np
x = np.random.default_rng(seed).standard_normal(2000)
y = x.copy()
y[D:] += a * x[:-D]
def dereverb(y, a, D):
    w = np.zeros_like(y)
    for n in range(len(y)):
        w[n] = y[n] - (a * w[n - D] if n >= D else 0.0)
    return w
err = float(np.max(np.abs(dereverb(y, a, D) - x)))
nz = 0.01 * np.random.default_rng(seed + 100).standard_normal(2000)
e = dereverb(y + nz, a, D) - x
noise_gain = float(np.sqrt(np.mean(e**2)) / np.sqrt(np.mean(nz**2)))
```

```python tests
import numpy as np
x = np.random.default_rng(seed).standard_normal(2000)
y = x.copy(); y[D:] += a * x[:-D]
assert np.max(np.abs(dereverb(y, a, D) - x)) < 1e-9, "Without noise the inverse should recover x exactly."
nz = 0.01 * np.random.default_rng(seed + 100).standard_normal(2000)
e = dereverb(y + nz, a, D) - x
ref = np.sqrt(np.mean(e**2)) / np.sqrt(np.mean(nz**2))
assert abs(noise_gain - ref) < 1e-9 and abs(err) < 1e-9, "noise_gain is RMS error over RMS added noise."
assert abs(noise_gain - 1 / np.sqrt(1 - a**2)) < 0.15 / np.sqrt(1 - a**2), "For white noise the inverse's power gain is 1/(1 − a²)."
```

::: right
Right. The inverse is exact without noise, and its white-noise power gain is $1/(1 - a^2)$: the sum of the squared impulse response, $1 + a^2 + a^4 + \ldots$. Strong echoes cost noise.
:::
:::

::: explain
## A camera's motion blur is a known LTI filter, but dividing the blurred image's spectrum by the blur's spectrum gives a picture buried in speckle. Explain why, and how a regularized inverse helps.

::: model
A motion blur averages over a short line, so its frequency response is a sinc that passes through zero, and nearly zero, at many spatial frequencies. Dividing by it multiplies the image's spectrum by $1/H$, which is enormous at those frequencies. The image has little content there, but the sensor's noise has as much as anywhere, so the division amplifies the noise by huge factors and it dominates the result as speckle. A regularized inverse, $H^*/(|H|^2 + \lambda)$, behaves like $1/H$ where the blur passes the signal strongly, and where $|H|$ falls below about $\sqrt\lambda$ it stops trying to restore and turns the gain down. Choosing λ near the noise-to-signal power ratio gives the Wiener filter, which trades a little remaining blur for much less noise.
:::
:::

::: practice

::: check
given: a = 0.4 | 0.75 | 0.99
answer: 1/(1 - a)
tolerance: 0.5%

## What's the inverse's largest gain, as a ratio, for an echo of strength {a}?

::: misses
- [1 + a] That's the channel's peak.
- [any] $1/(1 - a)$.
:::
:::

::: check
given: a = 0.5 | 0.8 | 0.9
answer: 1/(1 - a^2)
tolerance: 0.5%

## What is the white-noise power gain of the echo inverse with $a$ = {a}?

::: misses
- [1/(1 - a)] Sum the squares of the impulse response: $1 + a^2 + a^4 + \ldots$.
- [any] $1/(1 - a^2)$.
:::
:::
:::
