The goal
A 1 kHz tone was sampled at 8 kHz: 8 samples per cycle. We want the same tone at 32 kHz, 4 times as many samples, for example to feed a faster DAC. Interpolation by L = 4 does it digitally.
Zeros and images
The upsampler, written ↑4, passes each sample on and then sends 3 zeros. So xe[m] = x[m/4] when m is a multiple of 4, and 0 otherwise. Same token speed, 4 times as many tokens: 32 kHz.
A sampled spectrum repeats every 8 kHz. At the new rate we can see up to 16 kHz, so besides the 1 kHz tone there are copies at 7, 9, 15 kHz. These copies are called images. They are the fast wiggles the zeros add.
Three of every 4 numbers are now zero. As tones, xe is the 1 kHz tone plus its 3 images, each 1/L as tall: 0.25 instead of 1.00. xe has a quarter of the power, split equally over 4 lines.
The interpolation filter
Keep 0 to 4 kHz, the band the old samples could hold, and remove the rest. The cutoff is the old Nyquist frequency, fs/2 = 4 kHz, or π/L radians per sample. The filter runs at the new rate.
In its passband the filter's gain is about L = 4, so the 1 kHz line grows from 0.25 back to 1.00. At 7 kHz the gain is only 0.0019, so that image shrinks to 0.0005: 67 dB below the tone.
Out come 32000 samples a second that follow the tone. y[1] = 0.983, and the true tone at that instant is cos(2π/32) = 0.981. Over a whole cycle the largest error is 0.003.
Here h[0] = 1, and h is 0 at every other multiple of 4. Lined up at m = 16, it meets just one non-zero input, so y[16] = x[4] = −1.000 exactly. Only the 3 new values between old samples are computed.
Doing it fast
To make y[17] the 33 taps line up with 33 inputs, but only 8 are not zero. Skipping zeros splits h into 4 small filters. In general that is 8.25 multiplications per output, not 33. Here phase 0 is a plain copy, so just 6.
With numpy: make zeros, copy x into every 4th slot, then convolve with the windowed sinc. Mode "valid" keeps only full overlaps, so y[0] lines up with x[0]. scipy.signal.resample_poly(x, 4, 1) does the same job, polyphase, with a Kaiser window, so its numbers differ slightly.
The working
# step 1/10 · goal old rate fs = 8000 Hz (Ts = 125 µs) new rate L·fs = 32000 Hz factor L = 4 x[n] = cos(2π·1000·n/8000) = cos(2πn/8) x[0] = 1.000 x[1] = 0.707 x[2] = 0.000 x[3] = −0.707 the recipe (two stages): 1. put L−1 zeros between samples 2. low-pass filter, gain L
The tone, rates and filter are a chosen example: a 1000 Hz tone at 8000 samples a second, raised by L = 4 to 32000. The filter is a 33-tap windowed sinc (Hamming window). Every number and curve is computed from this model: real DFTs and real convolution. The tokens move in slow motion and the filter's delay is left out of the motion: the centred filter needs 16 future samples, so a real-time version gives each output 16 samples (0.5 ms) late. The tone is treated as endless, so the figure shows the steady state; np.arange(-4, 36) in the code gives the filter the 4 old samples it needs before x[0].