Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 38 ยท Multirate and Adaptive Filters

Interpolation and Rational Resampling

Increase a sampling rate by zero insertion and image filtering, then combine interpolation and decimation to change rates by a ratio such as 44.1 to 48 kHz.

Decimation lowers the sampling rate. Interpolation (upsampling) raises it by an integer factor L. You need it to match devices that run at different rates, to smooth a plot, to prepare for a digital-to-analog converter with an oversampling stage, or as one half of rational resampling (changing the rate by L/M, for example from 44.1 kHz to 48 kHz). The idea is simple but the filter is important.

Step 1: insert zeros

Upsampling by L puts L - 1 zeros between every pair of samples:

y[n] = x[n/L] if n is a multiple of L, else 0.

This does not create new information. In the frequency domain it creates images: copies of the original spectrum centered at multiples of the old sampling rate. They sit inside the new, wider band, and they are not wanted.

Python Zero insertion creates images

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You see the original 100 Hz tone plus images at fs - 100, fs + 100 and so on up to the new Nyquist at 2000 Hz.

Step 2: filter out the images

A low-pass filter with cutoff fs/2 (the old Nyquist frequency) removes the images. It also needs a gain of L to compensate for the energy lost by inserting zeros. The result is a smooth, higher-rate signal.

Interpolation by L

  1. Insert zeros
L-1 zeros between samples
  1. Low-pass
Cutoff at the old Nyquist, gain L
Result Rate is L times higher

The filter is also called an interpolation or anti-imaging filter.

1 / 2
Python Interpolation with an FIR anti-imaging filter

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The reconstructed signal matches the true 100 Hz sine closely and the 900 Hz image is nearly gone.

Rational resampling

To change the rate by a ratio L/M: first upsample by L, then filter once (with cutoff min(fs/2, fs_new/2) relative to the high rate), then downsample by M. One filter serves both roles, which is why the order matters: interpolation first keeps the signal intact, then decimation after the shared filter.

For 44.1 kHz to 48 kHz, the ratio is 160/147 (since 48000 / 44100 = 160 / 147). scipy.signal.resample_poly implements this efficiently with a polyphase filter (see polyphase structures), and signal.resample does it with the FFT (assuming the signal is periodic).

Python Resampling 44.1 kHz to 48 kHz

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Simple interpolators

Zero insertion plus an ideal low-pass is the gold standard. Cheaper alternatives are special cases:

  • Zero-order hold: repeat each sample L times (a boxcar filter). Crude, produces images and a staircase.
  • Linear interpolation: a triangular filter. Smoother, still audible artifacts on audio.
  • Cubic or spline interpolation: better for plots and images, but they are not true band-limited interpolators.
  • Sinc (windowed) interpolation: the high-quality choice for audio and measurement.
Python Comparing interpolation quality

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For a signal with energy at 35% of the sampling rate (well above the bandwidth where cheap interpolators work), the band-limited method wins by a large factor.

Practical advice

  • Interpolation can only create a signal consistent with the original band; it cannot invent detail.
  • Always check the filter's passband edge: a very steep filter close to fs/2 rings; a gentler one rolls off high frequencies.
  • Upsampling by L then filtering at the high rate is wasteful: most inputs to the filter are zeros. The next lesson shows how polyphase decomposition avoids that waste.
  • For streaming audio use resample_poly on blocks and carry filter state, or use a dedicated resampler library.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does zero insertion do to the spectrum?

    Inserting zeros compresses the time axis, repeating the spectrum L times across the wider band.
  2. 2. What gain should the anti-imaging filter have in a zero-insertion interpolator?

    Zero insertion divides the amplitude by L in the passband, so the filter gain L restores the original amplitude.
  3. 3. Resample from 22.05 kHz to 32 kHz. Which ratio L/M do you use?

    32000 / 22050 reduces to 640 / 441: upsample by 640 and downsample by 441, with one shared filter.
  4. 4. Why is a zero-order hold a poor interpolator?

    A boxcar filter has weak attenuation above the old Nyquist frequency, so the images are not removed.

Summary

  • Upsampling inserts zeros and creates spectral images; a low-pass filter with gain L removes them.
  • Rational resampling by L/M is upsample, filter once, downsample; resample_poly does it efficiently.
  • Band-limited (sinc-like) interpolation beats hold, linear and spline methods for signals with high-frequency content.
  • Polyphase filter structures avoid multiplying by the inserted zeros.

Next: Polyphase Filters and CIC Decimators