IIR Biquad Designer
Design a Butterworth, Chebyshev or elliptic IIR filter as a cascade of second-order sections, see what it does in float32, Q31 and Q15, and copy CMSIS-DSP code that drops into firmware.
1 · Filter
2 · Order and edges
2 · Spec (minimum order)
3 · Ripple and attenuation
4 · Implementation
Result
Frequency response
Poles, zeros and sections
| # | b0, b1, b2 | a1, a2 | |p| | f₀ | Q |
|---|
Rows use the textbook sign, H(z) = (b0 + b1 z⁻¹ + b2 z⁻²) / (1 + a1 z⁻¹ + a2 z⁻²). Sections run top to bottom; scipy puts the poles nearest the unit circle last. The small dots are the Q15 poles.
Time response
Coefficient quantization check
The same cascade with its coefficients rounded the way each target stores them. Q15 and Q31 use one CMSIS postShift for the whole cascade.
| Format | postShift | Passband Δ | Stopband peak | Max |p| | Status |
|---|
Pole radius by section
| # | |p| double | |p| Q31 | |p| Q15 | Q15 Δ|p| | 1 − |p| |
|---|
From an analog prototype to biquads in firmware
The design follows the same chain as scipy.signal, and the coefficients match it to about 1e-12. An analog low-pass prototype with its cutoff at 1 rad/s is turned into the response you asked for (low-pass, high-pass, band-pass or band-stop). The bilinear transform then maps it to the z-plane. Because the bilinear transform squeezes the whole analog frequency axis into 0 … fs/2, the edges are pre-warped first so they land exactly where you set them:
What the edge frequency means depends on the family. Butterworth: the −3 dB point. Chebyshev I and elliptic: the passband edge, where the loss reaches Rp. Chebyshev II: the stopband edge, where the attenuation reaches Rs. With "minimum order from a spec" the tool runs scipy's buttord, cheb1ord, cheb2ord or ellipord on your pass and stop edges and designs at the order they return.
Why second-order sections
A single high-order polynomial puts all the poles in two long coefficient vectors, and rounding those coefficients moves the poles a long way. Splitting the filter into biquads keeps each pole pair in its own two coefficients. The pairing follows scipy's zpk2sos: start from the pole nearest the unit circle, give it the nearest zero, and put those sections last. That keeps the high-gain, high-Q sections at the end of the chain, where the earlier sections have already removed out-of-band energy.
CMSIS-DSP conventions
CMSIS adds the feedback terms, so the exported a1 and a2 have the opposite sign to the table above. This is the most common bug in hand-ported biquads. The filter usually still runs, but the poles are mirrored and the response is wrong. The fixed-point kernels need every coefficient in [−1, 1). The library scales the accumulator by 2^postShift, so the tool picks the smallest shift that fits every coefficient. A numerator of [1, 2, 1] needs postShift 2, because 2/2 = 1.0 is just outside Q15. The L∞ option rescales each section so that the gain from the input to its output peaks at 0 dB, which leaves headroom for the 16-bit state.
The quantization check
Each format's coefficients are rounded exactly as the target stores them, and the tool recomputes the response and the pole radii from the rounded values. Poles close to z = 1 are the sensitive ones. That happens with a low cutoff relative to the sample rate, with a high order, or with a narrow band. There, a Q15 step of 3e-5 in a1 or a2 can be a large fraction of the distance to the unit circle. The status turns serious when a pole moves by more than a quarter of its distance to the circle or the passband shifts by more than 1 dB. It turns critical when a pole reaches the circle. The usual fixes are float32, Q31, a lower sample rate (decimate first), or a lower order.
Limits
- Coefficient quantization only. Arithmetic round-off noise, overflow of the Q31 accumulator (it wraps), and limit cycles are not simulated. Scale the input for headroom, and test on the target.
- Bessel and other families are not included yet. The bilinear transform also bends a Bessel filter's flat group delay, so an FIR is the better route to linear phase.
- Results are engineering estimates. Verify the final coefficients on the target with a measured sweep before you rely on them.
References
- SciPy,
scipy.signal:iirfilter,buttap/cheb1ap/cheb2ap/ellipap,bilinear_zpk,zpk2sos,buttord/ellipord(BSD-3-Clause). This tool's design code is a JavaScript port of these routines, and its tests check it against scipy 1.18. - Arm, CMSIS-DSP library,
arm_biquad_cascade_df1_f32,_df2T_f32,_df1_q15,_df1_q31and their init functions, github.com/ARM-software/CMSIS-DSP (Apache-2.0). - A. V. Oppenheim, R. W. Schafer, Discrete-Time Signal Processing, 3rd ed., Pearson, 2010: bilinear transform, frequency warping, cascade structures.
- S. J. Orfanidis, "Lecture notes on elliptic filter design," Rutgers University, 2006: degree equation and Landen transformations (the method behind scipy's
ellipap). - M. Abramowitz, I. A. Stegun, Handbook of Mathematical Functions, §16.4 and §17.6: Jacobi elliptic functions and the arithmetic-geometric mean.
- L. B. Jackson, "On the interaction of roundoff noise and dynamic range in digital filters," Bell System Technical Journal 49(2), 1970: L∞ / L2 section scaling.
Filter misbehaving on the target?
Kyros builds signal chains end to end: the analog front end, the converter, and the fixed-point firmware that has to keep the filter stable at temperature and in production.
