x[0]0.000x[1]0.142x[2]0.281x[3]0.415y[0]–y[1]–y[2]–y[3]–↑160LPF↓1471import numpy as np2from scipy.signal import resample_poly3n = np.arange(44100)4x = np.sin(2*np.pi*1000*n/44100)5y = resample_poly(x, 160, 147)0000
00.10.20.30.40.500.51t (ms)valueTIMEx[n] every 22.68 µsnew instants every 20.83 µsy[m] every 20.83 µsy[1] 0.1281 · tone 0.1305len(y) = 4800002040608010000.51f (kHz)sizeSPECTRUMimages at 44.1k ± 1 kHz43.1 kHz image: −78.6 dBcut 22.05 · Nyquist out 24
Coloured parts: what the current step is about; everything else rests in whiteBlocks: input samples x[n], upsampler ↑160, low-pass filter, downsampler ↓147, output samples y[m] and a Python code cardPlots: the samples over time, and the spectrum at the fine rate with the filter's gainTokens on the wires: real samples, inserted zeros (dashed), smooth filtered values and kept outputsA 1 kHz tone sampled at 44100 Hz is upsampled by 160, low-pass filtered once at 22.05 kHz with gain 160, and downsampled by 147 to 48000 Hz. Integer decimation and interpolation each have their own lesson in this module; this lesson chains them.

Two rates, one ratio

  1. A music CD stores 44,100 samples per second. Professional video uses 48,000. To play a CD track in a video we need samples at new instants, and 48,000 / 44,100 = 1.0884 is not a whole number.

Up, filter, down

The result and the shortcut

The working

# step 1/10 · rates

input   fs = 44,100 Hz  (audio CD)
        one sample every 22.68 µs
output  fs = 48,000 Hz  (professional video)
        one sample every 20.83 µs

48000 / 44100 = 1.0884
not a whole number: we cannot just
repeat or drop samples

test signal: a 1 kHz tone, x[n] = sin(2π·1000·n / 44100)

The tone is a chosen test signal at full scale 1. The filter is the one scipy.signal.resample_poly designs by default; every value in the figure is computed from it and matches scipy 1.18.1. The token streams are not to scale: after the upsampler only a few of the 159 zeros per sample are drawn, and the spectrum shows 0 to 100 kHz of a fine grid that reaches 3.528 MHz.