x[0]1.00x[1]0.71x[2]0.00x[3]−0.71↑4LPF1n = np.arange(-4, 36)2x = np.cos(2*np.pi*n/8)3xe = np.zeros(160); xe[::4] = x4q = np.arange(-16, 17)5h = np.sinc(q/4)*np.hamming(33)6y = np.convolve(xe, h, "valid")y[0]–y[1]–y[2]–y[3]–y[4]–y[5]–y[6]–y[7]–0000000000000000000
00.250.50.751-1-0.500.51t (ms)valueSAMPLES OVER TIMEold: every 125 µsnew: every 31.25 µs, 3 of 4 are 0largest error 0.003m = 16: y[16] = x[4] = −1.000m = 17: 8 of 33 taps meet datanumpy: y[1] = 0.983048121600.250.50.751frequency (kHz)amplitude · gain ÷ 4SPECTRUM (TONES)x, 8 kHzxeygain ÷ 4old limit 4 kHz7915images at 7, 9, 15 kHzeach line 0.25, was 1.00fc = 4 kHz1 kHz: 0.25 × 4 = 1.007 kHz image: 0.0005
Coloured parts: what the current step is about; everything else rests in whiteBlocks: old samples, the upsampler (↑4), the low-pass filter, the new samples and a Python code cardPlots: the samples over time and the spectrum (which tones the signal holds)Tokens ride the wires at one speed, so their spacing shows the sample rate; dashed tokens are inserted zerosA 1000 Hz tone at 8000 samples a second is raised by L = 4 to 32000: three zeros after each sample, then a 33-tap low-pass filter (cutoff 4 kHz, gain 4) removes the images and fills in the zeros.

The goal

  1. 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 interpolation filter

Doing it fast

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].