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

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: H(ω)+H(π−ω)=1.
  • 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?

Name it

What the lab computes

  • Decimation by M: direct, y[m]=∑kh[k]x[mM−k] computed for all n and kept at n = mM; polyphase, the same sum split as ∑p=0M−1∑jh[p+jM]x[mM−p−jM].
  • Interpolation by L: direct, zero-stuff then filter; polyphase, output sample n = mL + p uses only subfilter p: y[mL+p]=∑jh[p+jL]x[m−j].
  • Halfband design: h[n]=sin⁡(π(n−c)/2)π(n−c)w[n] with h[c]=12, 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?