C4 · Lesson 22 · Filter analysis lab
Frequency response from any transfer function, group delay, filter order for any specification, Sallen-Key design and noise bandwidth, in Python
Lessons 1 to 21 built filters from formulas: each response type had its own expression for gain, order, delay or noise bandwidth. A filter tool doesn't keep a separate formula for every case. It evaluates the transfer function as a ratio of polynomials in s, and gets everything else by numerical calculus: group delay by differentiating the phase, noise bandwidth by integrating the gain. In this lab you'll write those general tools and check them against the special formulas, then use them to size filters and design a Sallen-Key stage.
- The curves are the stopband attenuation of a Butterworth and a Chebyshev filter of the same order, from the passband edge out to ten times it, on a log frequency axis.
- The Chebyshev trades passband ripple for a much faster fall just past the edge. Raise the ripple and the gap widens; raise the order and both steepen.
- The readouts give each filter's attenuation at twice the edge. Step 3 turns a specification into the order each type needs.
Predict
A low-pass must lose at most 1 dB up to its passband edge and at least 40 dB at five times that frequency. Which needs fewer poles, a Butterworth or a Chebyshev?
The Chebyshev: order 3 (2.61 rounded up) against the Butterworth's 4 (3.28 rounded up). The Chebyshev spends the whole 1 dB allowance as ripple across the passband, and in return falls faster right past the edge. Step 3 computes both from the specification.
Name it
Transfer functions as polynomials
A filter's transfer function is a ratio of polynomials in s, . Setting and evaluating both polynomials (NumPy's polyval does it) gives H(f) at any frequency: magnitude in dB, , and phase from its angle.
Group delay numerically
Group delay is . Computed from an unwrapped phase on a fine grid with central differences, it matches the closed forms, such as for a first-order all-pass, to the grid's accuracy.
Order from a specification
For passband ripple dB, stopband attenuation dB, and stopband-to-passband frequency ratio x:
each rounded up. The Chebyshev's arccosh grows more slowly than a logarithm's denominator, which is why it needs fewer poles.
Sallen-Key
A unity-gain Sallen-Key low-pass has and . Its transfer function, , can be fed to the general tools to confirm both.
Noise bandwidth numerically
The equivalent noise bandwidth is , the width of a brick wall passing the same noise. Integrating numerically reproduces for one pole and = 1.111f₀ for a second-order Butterworth.
Worked example
A filter must stay within 1 dB to its edge and be 40 dB down at five times the edge. What order does each type need?
Show the solution
- The common ratio. The ratio inside both formulas is
- Butterworth.
- Chebyshev.
- A tighter specification. A tighter specification, 0.5 dB and 60 dB at twice the edge, needs 12 Butterworth poles but only 7 Chebyshev ones.
- When it pays. That's when the extra design effort of a Chebyshev, or an elliptic, pays.
Answer a Butterworth needs order 4 and a Chebyshev order 3.
Worked example
A unity-gain Sallen-Key stage has = 10 kΩ, = 22 nF and = 10 nF. Find f₀ and Q, and confirm them from its transfer function.
Show the solution
- Natural frequency.
- Q.
- The transfer function. It's , with
- Evaluate it at . At it gives |H| = 0.742 and a phase of exactly −90°, as a second-order low-pass has at its natural frequency: two independent checks.
Answer = 1073 Hz and Q = 0.742, confirmed by |H| = 0.742 and a −90° phase at 1073 Hz.
Worked example
Compute the noise bandwidths of first- and second-order Butterworth low-passes with a 1 kHz corner by numerical integration.
Show the solution
- One pole. For one pole,
- Integrate it. Integrating to a large multiple of , and adding the analytic tail beyond it, gives
- Two poles. For two poles, integrates to 1111 Hz.
- Any response. The numerical method doesn't care what the filter is: an elliptic filter with stopband ripple, or a measured response, integrates the same way. That's how converter datasheets quote noise for their digital filters.
Answer 1571 Hz for one pole and 1111 Hz for two.
Check
Step 1. Write freqresp(num, den, f) returning (mag_db, phase_deg) arrays for (coefficient lists, highest power first) at frequencies f.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 2. Write group_delay(num, den, f) returning the group delay in seconds at frequencies f, from a central difference of the unwrapped phase on a fine grid around each point.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 3. Write orders(rp, rs, x) returning (n_butterworth, n_chebyshev) as integers, the smallest orders that meet passband ripple rp dB and stopband attenuation rs dB at frequency ratio x.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 4. Write sallen_key(R1, R2, C1, C2) returning (f0, Q) from the formulas, and sk_check(R1, R2, C1, C2) returning (|H|, phase_deg) at f0 from the transfer function .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 5. Write enbw(order, f0) returning the noise bandwidth of a Butterworth low-pass, , by integrating numerically from 0 to 1000f₀ and adding the tail beyond analytically.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A low-pass may ripple 1 dB in its passband and must be 40 dB down at 4 times its edge.
(a)
What Butterworth order does that take, before rounding up?
(b)
And a Chebyshev?
Check
A unity-gain Sallen-Key low-pass has = 4.7 kΩ, = 10 nF and = 4.7 nF.
(a)
What's f₀?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
(b)
What's Q?
Check
What's the noise bandwidth of an order-2 Butterworth low-pass with a 1 kHz corner?
Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.
Check
A first-order all-pass has τ = 1 ms. What's its group delay at ω = 0.5/τ?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Explain why
Why do filter tools compute group delay and noise bandwidth numerically instead of using formulas?
Formulas exist only for idealized cases: a single pole, a Butterworth of a given order, a first-order all-pass. A real filter design mixes sections, uses rounded component values, or comes from a measurement, and its transfer function doesn't match any textbook form exactly. But every linear filter's response can be evaluated at any frequency from its transfer function, and group delay and noise bandwidth are just a derivative and an integral of that response. Computing them numerically works for every filter at once, and checking the numbers against the known formulas on simple cases is how you trust the tool on the complicated ones.
Practice
Keep practicing
6 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.