---
title: Optimal equiripple FIR design
heading: The minimax criterion, weighted error, the alternation theorem, the Parks–McClellan algorithm and how long an optimal filter must be
eyebrow: S7 · Lesson 23 · Optimal equiripple FIR design
xp: 50
---

::: hook
A windowed design spends its ripple unevenly: the error is largest near the band edges and shrinks away from them, so most of the passband and stopband are better than they need to be, and that slack is paid for in taps. The best possible filter of a given length spreads its error evenly, touching the allowed limit again and again across every band. Parks and McClellan turned that idea into an algorithm in 1972, and it remains the standard way to design FIR filters: given band edges, ripple limits and a length, it returns the filter whose largest weighted error is as small as it can be.
:::

::: play
- The filter order M needed to meet a lowpass specification against its transition width Δω, for a Kaiser window design (dashed) and for an optimal equiripple design (solid), from each method's length formula.
- The stopband needs A dB of attenuation; the passband ripple is a ratio K times the stopband's δ.
- The equiripple design is always shorter, and the saving is largest when the passband can be looser than the stopband, which the window method can't exploit.
:::
:::

```sim plot
view: graph
x: d = 0.02..0.5
y: M = 0..300
slider: A = 30..100 = 60 dB
slider: K = 1..100 = 10 log
plot: (-10*log(K*10^(-A/10)) - 13)/(2.324*d*pi) | samples: 400 | label: equiripple order (Δω = dπ)
plot: (A - 8)/(2.285*d*pi) | samples: 400 | dashed | color: ch3 | label: Kaiser window order
```

::: predict
## A lowpass needs δ₁ = 0.01 in its passband, δ₂ = 0.001 in its stopband and a 0.2π transition. Kaiser's window needs M = 37. Roughly what order does an equiripple design need?

- [ ] About the same, 37
- [x] About 26 or 27
- [ ] About 12
- [ ] About 74

::: reveal
Kaiser's estimate for equiripple filters gives $M \approx \frac{-10\log(\delta_1\delta_2) - 13}{2.324\Delta\omega}$ = 37/1.460 = 25.3, so 26; in Oppenheim and Schafer's example, M = 26 just misses and M = 27 meets the specification. The window design must hold the tighter δ = 0.001 in both bands, while the equiripple design uses the looser passband allowance to save ten taps.
:::
:::

::: nameit
## The minimax criterion

For a Type I filter with $A_e(\omega) = \sum_{k=0}^{L}a_k\cos(k\omega)$, L = M/2, choose the coefficients to minimize the largest **weighted error**

$$E(\omega) = W(\omega)\left[H_d(\omega) - A_e(\omega)\right]$$

over the passband and stopband (the transition band is "don't care"). With W = 1/K in the passband and 1 in the stopband, $K = \delta_1/\delta_2$, the optimal filter has ripples exactly $\delta_1$ and $\delta_2$.

## The alternation theorem

$A_e$ is the unique best approximation if and only if E(ω) attains its maximum magnitude, with alternating signs, at **at least L + 2** frequencies in the bands. A lowpass optimum has L + 2 or L + 3 such extremal frequencies (the latter an "extraripple" filter), and the band edges $\omega_p$ and $\omega_s$ are always among them.

## The Parks–McClellan algorithm

The Remez exchange: guess L + 2 extremal frequencies, solve for the polynomial that alternates with equal error δ there, find where the actual error peaks, move the guesses to those peaks, and repeat until they stop moving. It converges in a few iterations to the optimum.

## How long it must be

$$M \approx \frac{-10\log(\delta_1\delta_2) - 13}{2.324\,\Delta\omega}$$

against the Kaiser window's $M = \frac{A - 8}{2.285\Delta\omega}$ with A set by the smaller δ. Passband ripple in dB relates to δ₁ by $R_p = 20\log\frac{1 + \delta_1}{1 - \delta_1}$.
:::

::: example
## Estimate the order for $\omega_p$ = 0.4π, $\omega_s$ = 0.6π, δ₁ = 0.01, δ₂ = 0.001, and compare with a Kaiser window.

::: solution
1. **Equiripple order.**
   $$\begin{aligned} M &= \frac{-10\log 10^{-5} - 13}{2.324 \times 0.2\pi} \\ &= \frac{37}{1.460} \\ &= 25.3 \end{aligned}$$
   so M ≈ 26.
2. **Kaiser order.** Kaiser must meet 0.001 everywhere, so A = 60:
   $$\begin{aligned} M &= \frac{52}{1.436} \\ &= 36.2 \end{aligned}$$
   so 37.
3. **Compare.** The equiripple filter needs about 10 fewer multiplications per sample.
4. **Weight.** With weight K = 10, the stopband error counts ten times as much as the passband's.

**Answer:** about M = 26 for equiripple, against M = 37 for a Kaiser window.
:::
:::

::: example
## A specification gives 0.1 dB of passband ripple. What δ₁ is that?

::: solution
1. **Ripple as a ratio.**
   $$\begin{aligned} \frac{1 + \delta_1}{1 - \delta_1} &= 10^{0.1/20} \\ &= 1.01158 \end{aligned}$$
2. **Solve for δ₁.**
   $$\begin{aligned} \delta_1 &= \frac{1.01158 - 1}{1.01158 + 1} \\ &= 0.00576 \end{aligned}$$
3. **Weight.** Paired with 60 dB in the stopband (δ₂ = 0.001), the weight is K = 5.76.

**Answer:** δ₁ = 0.00576.
:::
:::

::: example
## A filter may ripple by 0.87 dB in its passband (δ₁ = 0.05) but needs 80 dB of rejection (δ₂ = 10⁻⁴), with a 0.05π transition. Compare equiripple and Kaiser lengths.

::: solution
1. **Product of the ripples.** $\delta_1\delta_2 = 5 \times 10^{-6}$, so
   $$-10\log_{10}(5 \times 10^{-6}) = 53.0$$
2. **Equiripple.**
   $$\begin{aligned} M &\approx \frac{53.0 - 13}{2.324 \times 0.05\pi} \\ &= \frac{53.0 - 13}{0.365} \\ &= 110 \end{aligned}$$
3. **Kaiser.** Kaiser has to use the smaller δ in both bands:
   $$\begin{aligned} M &= \frac{80 - 8}{2.285 \times 0.05\pi} \\ &= 201 \end{aligned}$$
4. **Compare.** Because the window method can't loosen the passband, the optimal design needs barely half the taps when the two tolerances differ this much.

**Answer:** about 110 for equiripple against 201 for Kaiser.
:::
:::

::: check
given: a = 0.01 | 0.05 | 0.1; b = 0.001 | 0.0001; d = 0.05 | 0.1 | 0.2
answer: (-10*log(a*b) - 13)/(2.324*d*pi)
tolerance: 0.5%

## An equiripple lowpass needs δ₁ = {a}, δ₂ = {b} and a {d}π transition. What order does Kaiser's estimate give?

::: right
Right. $\frac{-10\log(\delta_1\delta_2) - 13}{2.324\Delta\omega}$ = {answer}.
:::

::: misses
- [(-10*log(a*b) - 13)/(2.324*d)] Use Δω in radians.
- [any] Not yet. Kaiser's formula for equiripple filters.
:::
:::

::: check
given: a = 0.01 | 0.05 | 0.1; b = 0.001 | 0.0001; d = 0.05 | 0.1 | 0.2
answer: (-20*log(b) - 8)/(2.285*d*pi) - (-10*log(a*b) - 13)/(2.324*d*pi)
tolerance: 0.5%

## For the same specification, how many more orders does a Kaiser window design need (both before rounding)?

::: right
Right. {answer}: the window must meet δ₂ in both bands.
:::

::: misses
- [any] Not yet. Kaiser window M with A = −20 log δ₂, minus the equiripple estimate.
:::
:::

::: check
given: R = 0.05 | 0.1 | 0.5 | 1
answer: (10^(R/20) - 1)/(10^(R/20) + 1)
tolerance: 0.5%

## A passband may ripple by {R} dB peak to peak. What's δ₁?

::: right
Right. From $R_p = 20\log\frac{1 + \delta_1}{1 - \delta_1}$: δ₁ = {answer}.
:::

::: misses
- [10^(R/20) - 1] That treats the ripple as one-sided; it spans 1 − δ₁ to 1 + δ₁.
- [any] Not yet. Solve $\frac{1 + \delta_1}{1 - \delta_1} = 10^{R_p/20}$.
:::
:::

::: check
given: M = 20 | 36 | 60
answer: M/2 + 2
tolerance: 0

## An optimal Type I lowpass has order M = {M}. At least how many alternation frequencies does its error have?

::: right
Right. L + 2 with L = M/2: {answer}.
:::

::: misses
- [M + 2] L is M/2, the number of cosine terms beyond the constant.
- [M/2 + 3] That's an extraripple filter's count, the most it can have.
- [any] Not yet. The alternation theorem: at least L + 2.
:::
:::

::: check
given: a = 0.005 | 0.01 | 0.1; b = 0.001 | 0.0001
answer: a/b
tolerance: 0.5%

## A design needs δ₁ = {a} and δ₂ = {b}. What passband-to-stopband ripple ratio K does the weighting use?

::: right
Right. K = δ₁/δ₂ = {answer}, so stopband errors count K times as much.
:::

::: misses
- [b/a] K is the passband ripple over the stopband ripple.
- [any] Not yet. $K = \delta_1/\delta_2$.
:::
:::

::: check
given: b = 0.01 | 0.001 | 0.00001
answer: -20*log(b)
unit: dB
tolerance: 0.05

## What stopband attenuation does δ₂ = {b} mean?

::: right
Right. $-20\log\delta_2$ = {answer} dB.
:::

::: misses
- [-10*log(b)] δ is an amplitude: use 20 log.
- [any] Not yet. $A = -20\log\delta_2$.
:::
:::

::: check
kind: parts
given: R = 0.1 | 0.5 | 1; A = 50 | 70; d = 0.05 | 0.1

## A lowpass may ripple {R} dB peak to peak in its passband, must reject {A} dB, and has a {d}π transition.

::: part
answer: (10^(R/20) - 1)/(10^(R/20) + 1)
tolerance: 0.5%

### What is δ₁?

::: misses
- [any] Solve $R_p = 20\log_{10}\frac{1 + \delta_1}{1 - \delta_1}$.
:::
:::

::: part
answer: (-10*log((10^(R/20) - 1)/(10^(R/20) + 1)*10^(-A/20)) - 13)/(2.324*d*pi)
tolerance: 0.5%

### What equiripple order does Kaiser's estimate give?

::: misses
- [any] $\frac{-10\log(\delta_1\delta_2) - 13}{2.324\Delta\omega}$ with $\delta_2 = 10^{-A/20}$.
:::
:::
:::

::: check
kind: derivation
vars: a = 0.01..0.1, b = 0.00001..0.009, d = 0.05..1

## A lowpass has ripples a (passband) and b (stopband, b < a) and transition width d rad.

::: step
answer: (-10*log(a*b) - 13)/(2.324*d)

### What equiripple order does the estimate give?
:::

::: step
answer: -20*log(b)

### What attenuation must a Kaiser window meet?
:::

::: step
answer: (-20*log(b) - 8)/(2.285*d)

### What order does the Kaiser window need?
:::

::: right
Right. The optimal design uses both tolerances; the window uses only the tighter one.
:::
:::

::: explain
## Why is an equiripple filter shorter than a windowed filter that meets the same specification?

::: model
A windowed design's error is largest next to the band edges and dies away across each band, so far from the edges it's much smaller than the specification allows. Those unused margins are wasted capacity: they represent degrees of freedom in the coefficients spent on being better than necessary. The optimal design spreads the error evenly, pressing against the limit at many frequencies in each band, so every coefficient is working to meet the specification. It can also give different bands different tolerances through the weighting, while a window forces the same ripple in both. For the same specification it therefore needs fewer coefficients, typically 20 to 30% fewer.
:::
:::

::: practice

::: check
given: a = 0.02 | 0.1; b = 0.001 | 0.00001; d = 0.08 | 0.15
answer: (-10*log(a*b) - 13)/(2.324*d*pi)
tolerance: 0.5%

## Equiripple order: δ₁ {a}, δ₂ {b}, transition {d}π?

::: misses
- [any] $\frac{-10\log(\delta_1\delta_2) - 13}{2.324\Delta\omega}$.
:::
:::

::: check
given: R = 0.1 | 0.2 | 0.5 | 1 | 2 | 3
answer: (10^(R/20) - 1)/(10^(R/20) + 1)
tolerance: 0.5%

## δ₁ for {R} dB of ripple?

::: misses
- [any] $(10^{R/20} - 1)/(10^{R/20} + 1)$.
:::
:::

::: check
given: M = 10 | 16 | 24 | 30 | 50 | 64
answer: M/2 + 2
tolerance: 0

## Minimum alternations for Type I, M = {M}?

::: misses
- [any] M/2 + 2.
:::
:::
:::
