Interpolation: raising the sample rate
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
The Decimation lesson lowered a sample rate; this one raises it. Take a 1000 Hz tone sampled at 8 kHz and make it 32 kHz digitally, in two stages: put 3 zeros after every sample, then low-pass filter. Watch the zeros create images in the spectrum, see why the filter's cutoff is the old Nyquist frequency and its gain is L, check that the old samples pass through untouched, and learn the polyphase trick that skips the zeros and does 4 times less work. It builds on the lessons on the DTFT, windowed FIR filters (FIR design by windowing) and DACs and reconstruction.
The goal: four times as many samples
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.
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 goal: four times as many samples
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.
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 LStage 1: three zeros after each sample
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.
xe[m] = x[m/L] if m = 0, ±L, ±2L ... = 0 otherwise m : 0 1 2 3 4 5 6 7 8 xe : 1.000 0 0 0 0.707 0 0 0 0.000 new sample spacing Ts/L = 31.25 µs the zeros carry no information yetThe spectrum now shows images
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.
DTFT of the expander output: Xe(e^jω) = X(e^jωL) the old spectrum, squeezed by L = 4 in hertz (new Nyquist 16 kHz): tone 1 kHz images 8 − 1 = 7 kHz 8 + 1 = 9 kHz 16 − 1 = 15 kHz DFT: 128 samples, bins every 250 HzEach line is a quarter as tall
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 comb 1, 0, 0, 0, 1, 0, 0, 0 ... = (1/L)·Σ e^{j2πrm/L}, r = 0..L−1 so xe[m] = x[m/L] × comb = 4 copies of the tone, each × 1/4 DFT amplitudes (one-sided): x : 1 kHz -> 1.00 xe : 1, 7, 9, 15 kHz -> 0.25, 0.25, 0.25, 0.25Stage 2: a low-pass 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.
ideal interpolation filter (new rate): gain L = 4 for |ω| < π/L gain 0 for π/L < |ω| ≤ π π/L <-> 16 kHz / 4 = 4 kHz ideal h[m] = sinc(m/L) (endless) real h[q] = sinc(q/4)·hamming, q = −16..16 33 taps plot: gain ÷ 4, so 1.0 = gain 4 |H| at 4 kHz = 2.00 (half of 4)Gain L puts the height back
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.
|H| at 1 kHz = 4.008 |H| at 7 kHz = 0.0019 |H| at 9 kHz = 0.0035 |H| at 15 kHz = 0.0025 output lines: 1 kHz 0.25 × 4.008 = 1.00 7 kHz 0.25 × 0.0019 = 0.0005 ratio -67 dB why L: each line of xe is 1/L as tall (power 1/L²); gain L restores the amplitudeThe zeros are filled in
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.
y[m] = Σ h[q]·xe[m − q], q = −16..16 m y[m] cos(2πm/32) 0 1.000 1.000 1 0.983 0.981 2 0.926 0.924 3 0.833 0.831 4 0.707 0.707 5 0.557 0.556 6 0.384 0.383 7 0.195 0.195 largest |error| over a cycle: 0.003 centred filter shown; a causal one gives the same values 16 samples (0.5 ms) laterOld samples pass straight through
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.
h[q] = sinc(q/4)·w: h[0] = 1 h[±4] = h[±8] = ... = 0 (sinc(±1), sinc(±2) ...) y[4n] = x[n]·h[0] = x[n] y[0] = 1.000 x[0] = 1.000 y[4] = 0.707 x[1] = 0.707 y[16] = −1.000 x[4] = −1.000 a filter like this is called a Nyquist (L-th band) filterSkip the zeros: polyphase
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.
phase r = m mod 4: taps q with (m − q) a multiple of 4 r = 0: 9 taps (-16, -12, -8, -4, 0, 4, 8, 12, 16) r = 1: 8 taps (-15, -11, -7, -3, 1, 5, 9, 13) r = 2: 8 taps (-14, -10, -6, -2, 2, 6, 10, 14) r = 3: 8 taps (-13, -9, -5, -1, 3, 7, 11, 15) any 33-tap filter: 9 + 8 + 8 + 8 = 33 per 4 outputs = 8.25 per output, ÷ 4 vs 33 this Nyquist filter: phase 0 taps are 0 except h[0] = 1, so y[4n] = x[n] (a copy) 0 + 8 + 8 + 8 = 24 per 4 outputs = 6 per output, ÷ 5.5 vs 33 the 4 sub-filters run at the OLD rateInterpolation in Python
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.
import numpy as np # Python 3 + numpy n = np.arange(-4, 36) x = np.cos(2*np.pi*n/8) xe = np.zeros(160); xe[::4] = x q = np.arange(-16, 17) h = np.sinc(q/4)*np.hamming(33) y = np.convolve(xe, h, "valid") >>> len(y) # 160 − 33 + 1 128 >>> y[:8].round(3) array([1. , 0.983, 0.926, 0.833, 0.707, 0.557, 0.384, 0.195]) (n starts at −4 so the filter sees 4 old samples before x[0])
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01A signal at 8 kHz is interpolated by L = 4. How many zeros does the expander put after each sample, and what is the new rate?
L − 1 = 3 zeros after each sample give L = 4 numbers where there was 1, so the rate becomes 4 × 8 kHz = 32 kHz.
02After zero-stuffing a 1 kHz tone from 8 kHz to 32 kHz, where are the images below the new Nyquist frequency of 16 kHz?
Xe(e^jω) = X(e^jωL): the old spectrum, which repeats every 8 kHz, is now visible up to 16 kHz. The tone shows up at 8 − 1, 8 + 1 and 16 − 1 kHz as well as at 1 kHz.
03Which interpolation filter is right for L = 4 (frequencies in radians per sample at the new rate)?
The cutoff π/L keeps exactly the band the old samples held (0 to 4 kHz here). The zeros leave each line 1/L as tall (0.25 instead of 1), so a gain of L restores the size.
04The filter here is h[q] = sinc(q/4) times a window. Why do the old samples come out unchanged at m = 0, 4, 8, ...?
sinc(k) = 0 for every whole number k ≠ 0. Lined up on an old sample, every other non-zero input meets a zero tap, so y[4n] = x[n]: y[16] = x[4] = −1.000.
05A 33-tap interpolation filter for L = 4. About how many multiplications per output does a polyphase version need?
Only taps that meet a non-zero input count: 9, 8, 8, 8 taps for the four output phases, 8.25 on average, 4 times fewer than 33. That is the general count. For a Nyquist filter like this lesson's, phase 0 is a plain copy, so it drops to 6.
المسرد
- Interpolation (by L)
- Raising a sample rate by a whole number L digitally: expander, then low-pass filter. Also called upsampling.
- Expander (↑L)
- Puts L − 1 zeros after every sample: xe[m] = x[m/L] when m is a multiple of L, and 0 otherwise.
- Image
- A copy of the signal's spectrum that zero-stuffing makes visible, at k·fs ± f for the old rate fs.
- Interpolation (anti-imaging) filter
- The low-pass filter after the expander: cutoff π/L, the old Nyquist frequency, and passband gain L. It removes the images and fills in the zeros.
- Windowed sinc
- An FIR filter made by cutting the ideal sinc response to a finite length and tapering it with a window, here Hamming.
- Nyquist (L-th band) filter
- A filter whose taps are zero at every non-zero multiple of L, so the old samples pass through unchanged.
- Polyphase filter
- The interpolation filter split into L small sub-filters, one per output phase, that skip the inserted zeros: about L times fewer multiplications (fewer still for a Nyquist filter, whose copy phase needs none).
الملاحظات والمصادر
- 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].
- A. V. Oppenheim, R. W. Schafer, J. R. Buck, Discrete-Time Signal Processing, 2nd ed., Prentice Hall 1999, §4.6.2 Increasing the sampling rate by an integer factor (required text on MIT OCW 6.341 readings)
- MIT OpenCourseWare 6.341 Discrete-Time Signal Processing: lecture 5 Sampling rate conversion, lectures 10-11 Multirate systems and polyphase structures
- A. V. Oppenheim, A. S. Willsky, S. H. Nawab, Signals and Systems, 2nd ed., Pearson (§7.5 sampling of discrete-time signals)
- MIT OpenCourseWare 6.003 Signals and Systems (D. Freeman, Fall 2011)
- Upsampling (Wikipedia): zero-stuffing, images, the interpolation filter and polyphase
- SciPy documentation: scipy.signal.upfirdn (polyphase: avoids multiplying by the inserted zeros)
- SciPy documentation: scipy.signal.resample_poly
- NumPy documentation: numpy.sinc (normalized sinc)
- NumPy documentation: numpy.hamming
- NumPy documentation: numpy.convolve (mode 'valid')
اختبار يتاح بعد الخطوة الأخيرة.