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, and .
- Set R, and 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 be than ?
16 times: . High Q needs a large capacitor ratio, which is one reason equal-resistor designs are used mainly for modest Qs; above a Q of a few, other topologies are easier to build accurately.
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 :
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 for (0 dB, at DC, below that). The −3 dB point equals only for the Butterworth Q of 0.707.
Standard values. Rounding to the E12 series moves 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 = 1 kHz, Q = 0.707 and = 10 nF.
Show the solution
- Find .
- Find R. Here = 14.1 nF:
Answer = 20.0 nF and R = 11.3 kΩ.
Worked example
What gain does that filter have at 2 kHz?
Show the solution
- Denominator at .
- Gain. which is −12.3 dB.
- Check. That's the second-order Butterworth value,
Answer 0.243, or −12.3 dB.
Check
Design an equal-resistor, unity-gain Sallen-Key low-pass with = 1000 Hz and Q = 0.707, using = 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 = 1 kHz and Q = 2, compute 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?
The design formulas give ideal values, but real parts come in standard values with tolerances, and the formulas themselves can be misapplied. Computing the response from the values actually chosen shows the corner frequency, Q, peaking and attenuation the circuit will really have. It catches algebra mistakes, shows how much rounding to standard values moved the response, and confirms the specification is still met before anything is built.
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.