C425 of 30
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

C4 · Lesson 25 · Code lab

From specification to component values, checked numerically

Designing a filter goes in two directions. First, from a specification (a corner frequency and a Q) to component values. Then back: compute the circuit's actual response from those values and check that it meets the specification. Writing both directions in code catches algebra slips and makes it easy to try standard component values and see how far they move the result.

Play

  • The plot is the response of an equal-resistor Sallen-Key low-pass (lesson 13) built from R, C1 and C2.
  • Set R, C1 and C2 for a 1 kHz Butterworth. Then try the nearest standard values and see how much the response moves.

Predict

For an equal-resistor Sallen-Key low-pass with Q = 2, how much larger must C1 be than C2?

Name it

The design procedure in code

Specification to values (equal resistors, unity gain):

import numpy as np
f0, Q, C2 = 1000.0, 0.707, 10e-9
C1 = 4 * Q**2 * C2
R = 1 / (2 * np.pi * f0 * np.sqrt(C1 * C2))

Values to response. With s=j2πf:

H=1s2R2C1C2+2sRC2+1
f = np.logspace(1, 5, 2000)
s = 1j * 2 * np.pi * f
H = 1 / (s**2 * R**2 * C1 * C2 + s * 2 * R * C2 + 1)
gain_db = 20 * np.log10(np.abs(H))

Checking. The peak of gain_db should be 20log10⁡Q1−1/4Q2 for Q>0.707 (0 dB, at DC, below that). The −3 dB point equals f0 only for the Butterworth Q of 0.707.

Standard values. Rounding to the E12 series moves f0 and Q by a few percent; recomputing the response from the rounded values shows by how much.

Worked example

Run the specification-to-values step by hand for f0 = 1 kHz, Q = 0.707 and C2 = 10 nF.

Show the solution
  1. Find C1. C1=4Q2C2=4×0.4998×10nF=20.0nF
  2. Find R. Here C1C2 = 14.1 nF: R=12πf0C1C2=12π×1000×14.1×10−9=11.3kΩ

Answer C1 = 20.0 nF and R = 11.3 kΩ.

Worked example

What gain does that filter have at 2 kHz?

Show the solution
  1. Denominator at 2f0. D=1−4+j20.707=−3+2.83j
  2. Gain. |H|=19+8.00=0.243 which is −12.3 dB.
  3. Check. That's the second-order Butterworth value, 10log10⁡(1+24)

Answer 0.243, or −12.3 dB.

Check

Design an equal-resistor, unity-gain Sallen-Key low-pass with f0 = 1000 Hz and Q = 0.707, using C2 = 10 nF. Set C1 and R.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

For a second-order low-pass with f0 = 1 kHz and Q = 2, compute H on 4000 log-spaced frequencies from 10 Hz to 100 kHz and set peak_db to the largest gain in dB.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why is it worth computing a filter's response from its final component values, rather than trusting the design formulas?

Practice

Keep practicing

5 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.