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

S7 · Lesson 51 · Project

Converting 32 kHz audio to 48 kHz with a polyphase 3/2 resampler, from the prototype filter to an efficient implementation verified against the direct method

Every time audio moves between a 44.1 kHz file, a 48 kHz interface and a 16 kHz voice link, a sample-rate converter runs. This project builds one for a rational ratio, 3/2, which takes 32 kHz audio to 48 kHz. You'll design the single lowpass filter that does both the interpolation and the anti-aliasing, write the obvious implementation, which stuffs zeros, filters at three times the rate and throws most of the results away, and then the polyphase version, which computes only the outputs that are kept and never touches a stuffed zero. The tests require the two to agree to rounding error and the converted tone to keep its pitch and level.

Predict

The direct 3/2 converter filters at 96 kHz and keeps every second output. What fraction of its multiplications are wasted?

Name it

The prototype

One lowpass serves both purposes: removing the images that upsampling by L creates (cutoff π/L) and preventing the aliasing that downsampling by M would cause (cutoff π/M). So its cutoff is π/max⁡(L,M), measured at the upsampled rate, and its gain is L, to restore the amplitude that zero stuffing divides by L. A Kaiser window with β = 8 gives about 80 dB of stopband.

The direct method

Insert L − 1 zeros after each input sample, convolve with h, keep every Mth output. Simple, and the reference against which the fast version is checked.

The polyphase method

The output sample m is y[m]=∑kh[k]v[mM−k], where v is the zero-stuffed input, nonzero only when mM−k is a multiple of L. With p=(mM)modL and b=⌊mM/L⌋, only the taps h[p+jL] meet real samples:

y[m]=∑jh[p+jL]x[b−j]

Each output uses one polyphase branch, N/L taps, chosen by the phase p, which cycles through L values. The cost is N/L multiplications per output, against N per upsampled sample for the direct method.

Worked example

A 96-tap prototype converts 32 kHz to 48 kHz. Compare the multiplications per output sample.

Show the solution
  1. Direct. The filter runs at 96 kHz, 96 multiplications per upsampled sample, and two upsampled samples are computed per kept output: 2×96=192per output
  2. Polyphase. Each output uses one branch of 96/3 = 32 taps: 32 per output, a sixth of the direct count.
  3. Per second. At 48,000 outputs per second: 32×48000≈1.5×106 multiplications per second for each audio channel.

Answer 192 multiplications per output directly, against 32 in polyphase form.

Worked example

Which taps does output m = 5 use in the 3/2 converter, and which input samples?

Show the solution
  1. Output 5. mM=10p=10mod3=1b=⌊10/3⌋=3 so taps h[1], h[4], h[7], … meet x[3], x[2], x[1], ….
  2. Output 6. Here mM = 12, p = 0 and b = 4: taps h[0], h[3], h[6], … with x[4], x[3], ….
  3. The phase cycle. The phase p runs 0, 2, 1, 0, 2, 1, …, cycling through all three branches.

Answer output 5 uses taps h[1], h[4], h[7], … on inputs x[3], x[2], x[1], ….

Check

Step 1. Write prototype(L, M, N, beta): the converter's lowpass, with cutoff π/max(L, M) and gain L.

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 resample_direct(x, L, M, h): zero-stuff, filter, keep every Mth sample.

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 resample_poly(x, L, M, h): the same result from only the taps that meet real samples.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does the polyphase converter give exactly the same output as the direct one, not an approximation?

Practice

Keep practicing

3 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.