S7 · Lesson 15 · Multirate lab
Polyphase decimators and interpolators checked against direct filtering, and a windowed halfband design, in Python
Lessons 7 to 11 claimed that a polyphase decimator gives exactly the same output as filtering at the high rate and throwing samples away, that a polyphase interpolator equals zero-stuffing then filtering, and that a halfband filter has half its taps exactly zero and a response of exactly ½ at π/2. This lab writes each one out and checks it to rounding error, so the efficient versions can be trusted.
- The curve is the magnitude response of a 23-tap halfband lowpass designed by windowing a half-band sinc with a Hamming window.
- It passes exactly ½ at ω = π/2, and its response is antisymmetric about that point: .
- Every tap an even distance from the center, except the center itself, is exactly zero.
Predict
A 13-tap FIR decimates 60 samples by 3, once directly (filter everything, keep every third output) and once in polyphase form. How closely do the outputs agree?
The polyphase form splits h into and computes only the outputs that survive downsampling, from the same products. In double precision the two agree to about 9 × 10⁻¹⁶.
Name it
What the lab computes
- Decimation by M: direct, computed for all n and kept at n = mM; polyphase, the same sum split as .
- Interpolation by L: direct, zero-stuff then filter; polyphase, output sample n = mL + p uses only subfilter p: .
- Halfband design: with , c = (N − 1)/2 and a Hamming window; for N = 4K − 1 the taps at even nonzero offsets from c vanish exactly.
Check
Write decim_direct(x, h, M) and decim_poly(x, h, M): an FIR decimator computed both ways (zero initial state; output m corresponds to input index mM).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write interp_direct(x, h, L) (zero-stuff by L, then filter) and interp_poly(x, h, L) (each output n = mL + p from subfilter p).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write halfband(N): the Hamming-windowed half-band sinc of odd length N (center value ½), and response(h, w): |H(e^{jω})|.
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 a polyphase implementation exactly equivalent to filtering at the high rate, rather than an approximation?
A decimator only keeps every Mth output of its filter, and each of those outputs is a fixed sum of products of filter taps with input samples. Grouping the taps by their index modulo M, the polyphase components, and the input samples correspondingly, gives exactly the same products, just added in a different order; the outputs that would be discarded are simply never computed. The noble identities guarantee this rearrangement is exact for any filter. The only difference in practice is rounding, since floating-point addition in a different order can differ in the last bit.