---
title: Butterworth design lab
heading: From an order and a corner to poles, a response and capacitor values
eyebrow: C4 · Lesson 26 · Butterworth design lab
xp: 50
---

::: hook
Filter design software takes a specification and returns component values, and the steps in between aren't mysterious. A Butterworth filter's poles sit evenly spaced on a semicircle; the response follows from the poles by multiplying distances (lesson 18); and each pair of poles becomes one second-order active stage whose Q is set by the pair's angle. In this lab you'll write each of those steps in NumPy and end with the capacitor values for a cascade of Sallen-Key stages.
:::

::: play
- A fourth-order Butterworth filter's poles on the s-plane (in units where $\omega_c$ is the slider's radius): four of them, spaced evenly on a semicircle in the left half-plane, 45° apart.
- Higher orders put more poles on the same semicircle, so the ones at the ends crowd closer to the $j\omega$ axis, with higher Q.
- Each conjugate pair becomes one second-order stage, with $Q = \frac{1}{2\cos\theta}$ where θ is the pair's angle from the negative real axis.
:::
:::

```sim plot
view: splane
x: sigma = -1.5..0.5
y: omega = -1.2..1.2
slider: wc = 0.5..1 step 0.05 = 1
pole: wc*exp(j*pi*5/8) | label: Q = 1.31
pole: wc*exp(j*pi*7/8) | label: Q = 0.54
pole: wc*exp(j*pi*9/8)
pole: wc*exp(j*pi*11/8)
readout: angle of the high-Q pair from the negative real axis, ° = 67.5 | digits: 3
```

::: predict
## The poles of a fourth-order Butterworth filter come in two conjugate pairs. What Q does the pair nearer the $j\omega$ axis have?

- [ ] 0.5
- [ ] 0.707
- [x] About 1.31
- [ ] About 5

::: reveal
About 1.31. The four poles sit at 112.5°, 157.5°, 202.5° and 247.5°; the pair at ±112.5° is 67.5° from the negative real axis, so $Q = \frac{1}{2\cos 67.5°} = 1.31$. The other pair has Q = 0.54. Cascading the two stages gives the flat fourth-order response; neither stage alone is Butterworth.
:::
:::

::: nameit
## The poles

An order-$n$ Butterworth low-pass with corner $\omega_c$ has its poles at

$$p_k = \omega_c\,e^{j\pi(2k + n - 1)/2n} \qquad k = 1, \ldots, n$$

evenly spaced on the left half of a circle of radius $\omega_c$. Odd orders have one real pole at $-\omega_c$.

## The response

With unity DC gain,

$$H(j\omega) = \prod_k\frac{-p_k}{j\omega - p_k}$$

so in NumPy, start with an array of ones and multiply in one factor per pole. At $\omega_c$ every Butterworth filter is down exactly 3 dB.

## Stages

Pair each pole with its conjugate. A pair at distance $\omega_0$ from the origin and angle θ from the negative real axis is a second-order section with

$$\omega_0 = |p| \qquad Q = \frac{|p|}{-2\,\text{Re}(p)} = \frac{1}{2\cos\theta}$$

For a Butterworth filter every $\omega_0 = \omega_c$. With the unity-gain, equal-resistor Sallen-Key stage (lesson 13), $Q = \frac12\sqrt{C_1/C_2}$ and $\omega_0 = \frac{1}{R\sqrt{C_1C_2}}$, so

$$C_1 = \frac{2Q}{\omega_0R} \qquad C_2 = \frac{1}{2Q\omega_0R}$$

A real pole, for odd orders, is a plain RC section.
:::

::: example
## Find the stage capacitors for a fourth-order Butterworth low-pass at 1 kHz with R = 10 kΩ.

::: solution
1. **Scale factor.**
   $$\begin{aligned} \omega_c &= 6283\ \text{rad/s} \\ \omega_cR &= 6.283 \times 10^7 \end{aligned}$$
2. **Stage with Q = 0.541.**
   $$\begin{aligned} C_1 &= \frac{1.082}{6.283 \times 10^7} \\ &= 17.2\ \text{nF} \\ C_2 &= 14.7\ \text{nF} \end{aligned}$$
3. **Stage with Q = 1.307.**
   $$\begin{aligned} C_1 &= 41.6\ \text{nF} \\ C_2 &= 6.09\ \text{nF} \end{aligned}$$

**Answer:** 17.2 nF and 14.7 nF for the Q = 0.541 stage, and 41.6 nF and 6.09 nF for the Q = 1.307 stage.
:::
:::

::: example
## How far down is that fourth-order filter at 10 kHz?

::: solution
1. **Attenuation at 10 kHz.**
   $$\begin{aligned} A &= 10\log_{10}(1 + 10^8) \\ &= 80\ \text{dB} \end{aligned}$$
2. **Check with the pole product.** The pole product gives exactly that too: 80 dB per decade, a decade above the corner.

**Answer:** 80 dB down.
:::
:::

::: check
given: n = 3 | 4 | 6; k = 1 | 2
answer: arg(exp(j*pi*(2*k + n - 1)/(2*n)))*180/pi
unit: °
tolerance: 0.5%

## At what angle (measured from the positive real axis) is pole k = {k} of an order-{n} Butterworth filter?

::: right
Right. $\frac{(2k + n - 1)\pi}{2n}$ = {answer}.
:::

::: misses
- [any] Not yet. $p_k = e^{j\pi(2k + n - 1)/2n}$.
:::
:::

::: check
given: n = 2 | 4 | 6 | 8
answer: 1/(2*sin(pi/(2*n)))
tolerance: 0.5%

## What is the highest stage Q in an order-{n} Butterworth filter?

::: right
Right. The pair nearest the $j\omega$ axis is $\frac{\pi}{2n}$ from it, so $Q = \frac{1}{2\sin(\pi/2n)}$ = {answer}.
:::

::: misses
- [any] Not yet. The pole pair closest to the $j\omega$ axis has the highest Q.
:::
:::

::: check
given: Q = 0.541 | 0.707 | 1.307; fc = 1 | 5; R = 4.7 | 10
answer: 2*Q/(2*pi*fc*1000*R*1000)*1e9
unit: nF
tolerance: 0.5%

## An equal-resistor unity-gain Sallen-Key stage needs Q = {Q} at {fc} kHz with R = {R} kΩ. What is $C_1$?

::: right
Right. $\frac{2Q}{\omega_0R}$ = {answer}.
:::

::: misses
- [1/(2*Q*2*pi*fc*1000*R*1000)*1e9] That's $C_2$.
- [any] Not yet. $C_1 = 2Q/(\omega_0R)$.
:::
:::

::: check
given: Q = 0.541 | 1.307 | 2.5; fc = 1 | 5; R = 4.7 | 10
answer: 1/(2*Q*2*pi*fc*1000*R*1000)*1e9
unit: nF
tolerance: 0.5%

## For the same stage (Q = {Q}, {fc} kHz, R = {R} kΩ), what is $C_2$?

::: right
Right. $\frac{1}{2Q\omega_0R}$ = {answer}.
:::

::: misses
- [any] Not yet. $C_2 = 1/(2Q\omega_0R)$.
:::
:::

::: check
kind: python

## Write `butter_poles(n, wc)` returning the n complex poles of a Butterworth low-pass with corner `wc` (rad/s), and `response(poles, f)` returning the complex $H$ at the frequencies `f` (Hz, an array), with unity DC gain.

```python starter
import numpy as np

def butter_poles(n, wc):
    return -wc * np.ones(n, dtype=complex)

def response(poles, f):
    s = 2j * np.pi * np.asarray(f, dtype=float)
    H = np.ones_like(s)
    for p in poles:
        H = H * (-p) / (s - p)
    return H
```

```python solution
import numpy as np

def butter_poles(n, wc):
    k = np.arange(1, n + 1)
    return wc * np.exp(1j * np.pi * (2 * k + n - 1) / (2 * n))

def response(poles, f):
    s = 2j * np.pi * np.asarray(f, dtype=float)
    H = np.ones_like(s)
    for p in poles:
        H = H * (-p) / (s - p)
    return H
```

```python tests
import numpy as np
for n in (2, 3, 4, 5):
    p = butter_poles(n, 1.0)
    assert len(p) == n, "Return n poles."
    assert np.allclose(abs(p), 1), "Every pole lies on the circle of radius ωc."
    assert np.all(p.real < 0), "All poles must be in the left half-plane."
    g = abs(response(p, [1 / (2 * np.pi)]))[0]
    assert abs(g - 1 / np.sqrt(2)) < 1e-9, f"At the corner an order-{n} Butterworth is down 3 dB; got {g:.6f}."
p = butter_poles(4, 2 * np.pi * 1000)
g = 20 * np.log10(abs(response(p, [10000])))[0]
assert abs(g + 80) < 1e-5, f"A fourth-order filter is 80 dB down a decade above its corner; got {g:.4f}."
```

::: right
Right. The starter's four poles all at $-\omega_c$ make a cascade of identical RC sections: −12 dB at the corner instead of −3 dB, the soft knee lesson 7 described.
:::
:::

::: check
kind: python

## Write `sallen_key(n, fc, R)` for even `n`: return a list of `(C1, C2)` pairs in farads, one per equal-resistor unity-gain Sallen-Key stage, in order of increasing Q.

```python starter
import numpy as np

def butter_poles(n, wc):
    k = np.arange(1, n + 1)
    return wc * np.exp(1j * np.pi * (2 * k + n - 1) / (2 * n))

def sallen_key(n, fc, R):
    wc = 2 * np.pi * fc
    return [(np.sqrt(2) / (wc * R), 1 / (np.sqrt(2) * wc * R))] * (n // 2)
```

```python solution
import numpy as np

def butter_poles(n, wc):
    k = np.arange(1, n + 1)
    return wc * np.exp(1j * np.pi * (2 * k + n - 1) / (2 * n))

def sallen_key(n, fc, R):
    wc = 2 * np.pi * fc
    upper = [p for p in butter_poles(n, wc) if p.imag > 1e-9 * wc]
    Qs = sorted(abs(p) / (-2 * p.real) for p in upper)
    return [(2 * Q / (wc * R), 1 / (2 * Q * wc * R)) for Q in Qs]
```

```python tests
import numpy as np
st = sallen_key(4, 1000, 1e4)
assert len(st) == 2, "A fourth-order filter has two second-order stages."
assert np.allclose(np.array(st) * 1e9, [[17.2268069, 14.7039994], [41.5891909, 6.09059599]], rtol=1e-6), f"Expected (17.23, 14.70) nF and (41.59, 6.09) nF; got {np.array(st) * 1e9}."
st = sallen_key(6, 2000, 4.7e3)
assert np.allclose(np.array(st) * 1e9, [[17.529, 16.354], [23.945, 11.972], [65.418, 4.382]], rtol=1e-3), f"Sixth order at 2 kHz with 4.7 kΩ: got {np.array(st) * 1e9}."
```

::: right
Right. The starter used Q = 0.707 for every stage, which gives a cascade of identical second-order Butterworth sections: not a fourth-order Butterworth. Each stage needs its own Q.
:::
:::

::: explain
## Why can't a fourth-order Butterworth filter be made by cascading two second-order Butterworth stages?

::: model
A second-order Butterworth stage has its two poles at ±45° from the negative real axis, Q = 0.707. Cascading two of them puts four poles at those same two angles. A fourth-order Butterworth needs its four poles spread evenly around the semicircle, at 22.5° and 67.5° from the axis, which means one stage of low Q and one of higher Q. With the poles doubled up at 45°, the response is −6 dB at the corner and droops before it, not the maximally flat shape.
:::
:::

::: practice

::: check
given: n = 3 | 5 | 7
answer: -1
tolerance: 0.001

## An odd-order ({n}) Butterworth filter normalized to ωc = 1 has one real pole. Where is it?

::: misses
- [any] At $-\omega_c$.
:::
:::

::: check
given: Q = 0.6 | 1 | 2
answer: acos(1/(2*Q))*180/pi
unit: °
tolerance: 0.5%

## A pole pair has Q = {Q}. How far, in degrees, is it from the negative real axis?

::: misses
- [any] $\cos\theta = 1/(2Q)$.
:::
:::

::: check
given: n = 2 | 4 | 6 | 8 | 10 | 12
answer: n/2
tolerance: 0.5%

## How many second-order stages does an order-{n} filter need?

::: misses
- [any] One per pole pair.
:::
:::
:::
