---
title: Wiener filters
heading: Estimating a signal from noisy observations, the scalar estimator, the noncausal Wiener filter in frequency, FIR Wiener filters from the Wiener–Hopf equations, and the minimum mean-square error
eyebrow: S7 · Lesson 36 · Wiener filters
xp: 50
---

::: hook
A signal buried in noise can't be recovered exactly, but it can be estimated as well as any linear filter possibly allows, once the signal's and the noise's statistics are known. Norbert Wiener worked this out during the Second World War for predicting aircraft positions from noisy radar. The answer is intuitive in the frequency domain: pass each frequency in proportion to how much of it is signal rather than noise. It underlies noise reduction, channel equalization and deblurring, and its finite-length version is the target that the adaptive filters of the next lesson converge to.
:::

::: play
- The noncausal Wiener filter $H(\omega) = \frac{P_{ss}(\omega)}{P_{ss}(\omega) + P_{nn}(\omega)}$ for a lowpass AR(1) signal (pole a, unit variance) in white noise, against frequency, with the signal-to-noise ratio set by the noise variance.
- Where the signal is strong the filter passes almost everything; where noise dominates it attenuates, without ever cutting completely.
- With a = 0.9 and equal signal and noise power, the gain is 0.95 at DC and 0.05 at π.
:::
:::

```sim plot
view: graph
x: w = 0..3.1416
y: H = 0..1.05
slider: a = 0..0.98 = 0.9
slider: n = 0.01..10 = 1 log
plot: ((1 - a^2)/(1 - 2*a*cos(w) + a^2))/((1 - a^2)/(1 - 2*a*cos(w) + a^2) + n) | samples: 600 | label: Wiener gain H(ω)
readout: gain at DC = ((1 + a)/(1 - a))/((1 + a)/(1 - a) + n)
readout: overall SNR, dB = 10*log(1/n)
```

::: predict
## A signal of variance 4 is observed in independent noise of variance 1, with no correlation between samples to exploit. What's the best linear estimate of the signal from one observation?

- [ ] The observation itself
- [x] 0.8 times the observation
- [ ] 0.25 times the observation
- [ ] Zero

::: reveal
0.8 times it. Scaling by $h = \sigma_s^2/(\sigma_s^2 + \sigma_n^2)$ shrinks the estimate toward the mean in proportion to how much of the observation is likely to be noise. The mean-square error falls from 1 (using the raw observation) to 4 × 1/5 = 0.8. Shrinking a little more or less would make it worse.
:::
:::

::: nameit
## The problem

Observe x[n] = s[n] + v[n], with s and v zero-mean, uncorrelated, of known autocorrelations, and find the linear filter h minimizing $E\{|s[n] - \hat{s}[n]|^2\}$. The **orthogonality principle**: the error must be uncorrelated with every observation the filter uses.

## Scalar and noncausal solutions

- One observation, no correlation: $h = \frac{\sigma_s^2}{\sigma_s^2 + \sigma_v^2}$, error $\frac{\sigma_s^2\sigma_v^2}{\sigma_s^2 + \sigma_v^2}$.
- Using all past and future samples (noncausal, or offline):

$$H(\omega) = \frac{P_{ss}(\omega)}{P_{ss}(\omega) + P_{vv}(\omega)}$$

a gain between 0 and 1 at each frequency, set by that frequency's signal-to-noise ratio S: $H = \frac{S}{1 + S}$.

## FIR Wiener filters

A P-tap filter $\hat{s}[n] = \sum_{k=0}^{P-1}h[k]x[n - k]$ satisfies the **Wiener–Hopf equations**

$$\sum_{k=0}^{P-1}h[k]\phi_{xx}[i - k] = \phi_{sx}[i], \quad i = 0, \dots, P - 1$$

with $\phi_{xx} = \phi_{ss} + \phi_{vv}$ and $\phi_{sx} = \phi_{ss}$ for uncorrelated noise. The minimum error is $\phi_{ss}[0] - \sum_kh[k]\phi_{sx}[k]$. The matrix is Toeplitz, so Levinson-type recursions solve it fast.
:::

::: example
## A unit-variance AR(1) signal with a = 0.9 is observed in unit-variance white noise. Find the two-tap FIR Wiener filter and its error.

::: solution
1. **Correlations.** With $\phi_{ss}[m] = 0.9^{|m|}$:
   $$\phi_{xx} = [2,\ 0.9], \quad \phi_{sx} = [1,\ 0.9]$$
2. **Normal equations.**
   $$\begin{aligned} 2h_0 + 0.9h_1 &= 1 \\ 0.9h_0 + 2h_1 &= 0.9 \end{aligned}$$
3. **Solve.** $h_0$ = 0.373 and $h_1$ = 0.282.
4. **Error.**
   $$\begin{aligned} E &= 1 - (0.373 + 0.9 \times 0.282) \\ &= 0.373 \end{aligned}$$
   against 0.5 for the best scalar estimate and 1 for the raw observation.

**Answer:** $h_0$ = 0.373 and $h_1$ = 0.282, with a mean squared error of 0.373.
:::
:::

::: example
## For the same signal and noise, what does the noncausal Wiener filter do at DC and at π?

::: solution
1. **Signal spectrum.**
   $$P_{ss}(\omega) = \frac{0.19}{1 - 1.8\cos\omega + 0.81}$$
   That's 19 at DC and 0.0526 at π.
2. **At DC.** With unit noise density:
   $$\begin{aligned} H(0) &= \frac{19}{20} \\ &= 0.95 \end{aligned}$$
3. **At π.**
   $$\begin{aligned} H(\pi) &= \frac{0.0526}{1.0526} \\ &= 0.05 \end{aligned}$$
4. **Shape.** The filter is a lowpass that follows the signal's spectrum, keeping where the signal is and cutting where only noise is.

**Answer:** it passes 0.95 at DC and 0.05 at π.
:::
:::

::: example
## A noise-reduction system applies the noncausal Wiener gain in each frequency band. What gain does it apply where the band's SNR is 20 dB, 0 dB and −10 dB?

::: solution
1. **Wiener gain.** With S the band's SNR as a ratio:
   $$H = \frac{S}{1 + S}$$
2. **At 20 dB.**
   $$\begin{aligned} H &= \frac{100}{101} \\ &= 0.990 \end{aligned}$$
   which is −0.09 dB.
3. **At 0 dB.**
   $$\begin{aligned} H &= \frac{1}{2} \\ &= 0.5 \end{aligned}$$
   which is −6.0 dB.
4. **At −10 dB.**
   $$\begin{aligned} H &= \frac{0.1}{1.1} \\ &= 0.091 \end{aligned}$$
   which is −20.8 dB.
5. **What it means.** Clean bands pass almost untouched and noise-dominated ones are cut hard; the musical artifacts of such systems come from these gains fluctuating as the band SNR estimates wander.

**Answer:** gains of 0.990 (−0.09 dB) at 20 dB SNR, 0.5 (−6.0 dB) at 0 dB and 0.091 (−20.8 dB) at −10 dB.
:::
:::

::: check
given: s = 1 | 4 | 9; v = 0.5 | 1 | 3
answer: s/(s + v)
tolerance: 0.5%

## A signal of variance {s} is observed in uncorrelated noise of variance {v}. What scalar gain gives the best linear estimate?

::: right
Right. $\sigma_s^2/(\sigma_s^2 + \sigma_v^2)$ = {answer}.
:::

::: misses
- [s/v] That's the SNR; the gain is SNR/(1 + SNR).
- [any] Not yet. Minimize $E\{(s - hx)^2\}$.
:::
:::

::: check
given: s = 1 | 4 | 9; v = 0.5 | 1 | 3
answer: s*v/(s + v)
tolerance: 0.5%

## What mean-square error does that estimate achieve?

::: right
Right. $\sigma_s^2\sigma_v^2/(\sigma_s^2 + \sigma_v^2)$ = {answer}.
:::

::: misses
- [v] That's the error of the raw observation; shrinking it does better.
- [any] Not yet. $\sigma_s^2(1 - h)$.
:::
:::

::: check
given: S = -10 | -3 | 6 | 20
answer: 10^(S/10)/(1 + 10^(S/10))
tolerance: 0.5%

## At one frequency the signal-to-noise ratio is {S} dB. What gain does the noncausal Wiener filter apply there?

::: right
Right. S/(1 + S) = {answer}.
:::

::: misses
- [10^(S/20)/(1 + 10^(S/20))] Use the power ratio, $10^{S/10}$.
- [any] Not yet. $H = P_{ss}/(P_{ss} + P_{vv})$.
:::
:::

::: check
given: a = 0.5 | 0.8 | 0.95; n = 0.5 | 1 | 4; w = 0 | 1 | 3.1416
answer: ((1 - a^2)/(1 - 2*a*cos(w) + a^2))/((1 - a^2)/(1 - 2*a*cos(w) + a^2) + n)
tolerance: 0.5%

## A unit-variance AR(1) signal (a = {a}) is in white noise of density {n}. What's the noncausal Wiener gain at ω = {w}?

::: right
Right. $P_{ss}/(P_{ss} + P_{vv})$ = {answer}.
:::

::: misses
- [any] Not yet. $P_{ss}(\omega) = (1 - a^2)/|1 - ae^{-j\omega}|^2$.
:::
:::

::: check
given: a = 0.6 | 0.9; v = 0.5 | 1 | 2
answer: ((1 + v) - a*a)/((1 + v)^2 - a*a)
tolerance: 0.5%

## A unit-variance AR(1) signal (a = {a}) is in white noise of variance {v}. What's $h_0$ of the two-tap FIR Wiener filter?

::: right
Right. Solving $(1 + v)h_0 + ah_1 = 1$, $ah_0 + (1 + v)h_1 = a$: $h_0$ = {answer}.
:::

::: misses
- [1/(1 + v)] That's the one-tap filter.
- [any] Not yet. Solve the 2 × 2 Wiener–Hopf system.
:::
:::

::: check
given: s = 1 | 4; v = 1 | 2 | 5
answer: 10*log(v/(s*v/(s + v)))
unit: dB
tolerance: 0.05

## By how much does the scalar Wiener estimate lower the mean-square error compared with the raw observation, for signal variance {s} and noise variance {v}?

::: right
Right. From $\sigma_v^2$ to $\sigma_s^2\sigma_v^2/(\sigma_s^2 + \sigma_v^2)$: {answer} dB.
:::

::: misses
- [any] Not yet. Ratio of the raw error to the Wiener error, in dB.
:::
:::

::: check
kind: parts
given: S = -15 | -5 | 5 | 15

## A frequency band has an SNR of {S} dB.

::: part
answer: 10^(S/10)/(1 + 10^(S/10))
tolerance: 0.5%

### What gain does the noncausal Wiener filter apply?

::: misses
- [10^(S/20)/(1 + 10^(S/20))] Use the power ratio, $10^{S/10}$.
- [any] $S/(1 + S)$ with S as a power ratio.
:::
:::

::: part
answer: 20*log(10^(S/10)/(1 + 10^(S/10)))
unit: dB
tolerance: 0.5%

### What is that in decibels?

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

::: check
kind: derivation
vars: s = 0.01..100, v = 0.01..100

## A scalar signal of variance s is observed in uncorrelated noise of variance v.

::: step
answer: s/(s + v)

### What is the Wiener gain?
:::

::: step
answer: s*v/(s + v)

### What mean-square error does it leave?
:::

::: step
answer: s/(s + v)

### What fraction of the raw observation's error (v) is that?
:::

::: right
Right. The estimate always beats both the raw observation (error v) and the prior guess of zero (error s).
:::
:::

::: explain
## Why does the Wiener filter never completely remove a frequency, even where the noise is much stronger than the signal?

::: model
At each frequency the filter chooses the gain that minimizes the expected squared error between its output and the true signal. Cutting a frequency entirely guarantees an error equal to all of the signal there, while passing it fully lets all the noise through. The best compromise is to pass the fraction $P_{ss}/(P_{ss} + P_{vv})$: wherever there's any signal at all, passing a little of the observation reduces the error more than it adds noise. The gain only reaches zero where the signal truly has no power. The filter is cautious in proportion to the evidence, which is exactly what minimizing mean-square error demands.
:::
:::

::: practice

::: check
given: s = 2 | 10; v = 1 | 4
answer: s/(s + v)
tolerance: 0.5%

## Scalar Wiener gain: σ_s² {s}, σ_v² {v}?

::: misses
- [any] $\sigma_s^2/(\sigma_s^2 + \sigma_v^2)$.
:::
:::

::: check
given: S = -10 | -3 | 0 | 3 | 6 | 10 | 20
answer: 10^(S/10)/(1 + 10^(S/10))
tolerance: 0.5%

## Wiener gain at {S} dB SNR?

::: misses
- [any] S/(1 + S).
:::
:::

::: check
given: a = 0.7 | 0.95; v = 0.5 | 2
answer: ((1 + v) - a*a)/((1 + v)^2 - a*a)
tolerance: 0.5%

## Two-tap $h_0$: AR(1) a {a}, noise {v}?

::: misses
- [any] Solve Wiener–Hopf.
:::
:::
:::
