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

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?

Name it

Transfer functions as polynomials

A filter's transfer function is a ratio of polynomials in s, H(s)=b0sm+⋯+bma0sn+⋯+an. Setting s=j2πf and evaluating both polynomials (NumPy's polyval does it) gives H(f) at any frequency: magnitude in dB, 20log⁡|H|, and phase from its angle.

Group delay numerically

Group delay is τg=−dϕdω. Computed from an unwrapped phase on a fine grid with central differences, it matches the closed forms, such as 2τ1+(ωτ)2 for a first-order all-pass, to the grid's accuracy.

Order from a specification

For passband ripple rp dB, stopband attenuation rs dB, and stopband-to-passband frequency ratio x:

nButterworth=log⁡10rs/10−110rp/10−12log⁡x,nChebyshev=arccosh10rs/10−110rp/10−1arccoshx,

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 f0=12πR1R2C1C2 and Q=R1R2C1C2C2(R1+R2). Its transfer function, 1R1R2C1C2s2+C2(R1+R2)s+1, can be fed to the general tools to confirm both.

Noise bandwidth numerically

The equivalent noise bandwidth is 1|H(0)|2∫0∞|H(f)|2df, the width of a brick wall passing the same noise. Integrating numerically reproduces π2f0 for one pole and π22f0 = 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
  1. The common ratio. The ratio inside both formulas is 104−1100.1−1=3.86×104
  2. Butterworth. n=log⁡(3.86×104)2log⁡5=3.28→4
  3. Chebyshev. n=arccosh3.86×104arccosh5=5.972.29=2.61→3
  4. 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.
  5. 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 R1=R2 = 10 kΩ, C1 = 22 nF and C2 = 10 nF. Find f₀ and Q, and confirm them from its transfer function.

Show the solution
  1. Natural frequency. f0=12π108×2.2×10−16=1073Hz
  2. Q. Q=108×2.2×10−1610−8×2×104=0.742
  3. The transfer function. It's H=1/D, with D=(2.2×10−8)s2+(2×10−4)s+1
  4. Evaluate it at f0. At j2π×1073 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 f0 = 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
  1. One pole. For one pole, |H|2=11+(f/f0)2
  2. Integrate it. Integrating to a large multiple of f0, and adding the analytic tail beyond it, gives Bn=1571Hz=π2f0
  3. Two poles. For two poles, |H|2=11+(f/f0)4 integrates to 1111 Hz.
  4. 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 H(s)=num(s)den(s) (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 1R1R2C1C2s2+C2(R1+R2)s+1.

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, |H|2=11+(f/f0)2n, 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 R1=R2 = 4.7 kΩ, C1 = 10 nF and C2 = 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?

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.