---
title: Decimation and interpolation
heading: Changing a digital signal's sampling rate, decimation by keeping every Mth sample and the filter that must come first, interpolation by inserting zeros and the images it creates, rational rate changes such as 44.1 to 48 kHz, and polyphase filters that skip the work that would be thrown away
eyebrow: D5 · Lesson 9 · Decimation and interpolation
xp: 40
---

::: hook
A digital audio workstation mixes tracks recorded at 44.1 and 48 kHz, a software radio digitizes 20 MHz of spectrum and then needs only a 200 kHz slice of it, and a delta-sigma ADC samples at megahertz to deliver a few kilohertz of clean audio. All of them change sampling rates. Doing it is simple in principle: throw samples away, or insert new ones. Doing it right means respecting the sampling theorem at the new rate, which takes a low-pass filter, and doing it efficiently means never computing a sample you're about to discard.
:::

::: play
- The spectrum of a signal occupying 0 to B kHz, sampled at 48 kHz, and the copies that land on top of it if it's decimated by M with no filter: decimating moves the sampling rate to 48/M kHz, so copies appear at every multiple of 48/M.
- If B is below the new Nyquist frequency, 24/M kHz, the copies don't overlap the original. Above it they fold onto it: aliasing.
- That's why decimation starts with a low-pass filter at the new Nyquist frequency.
:::

```sim plot
view: graph
x: f = 0..24
y: S = 0..1.2
slider: B = 1..24 step 0.5 = 3
slider: M = 1..8 step 1 = 4
plot: (1 - f/B + abs(1 - f/B))/2 | samples: 600 | label: signal's spectrum (f in kHz)
plot: (1 - abs(f - 48/M)/B + abs(1 - abs(f - 48/M)/B))/2*step(M - 1.5) | samples: 600 | dashed | color: ch3 | label: copies after decimating by M
plot: (1 - abs(f - 96/M)/B + abs(1 - abs(f - 96/M)/B))/2*step(M - 2.5) | samples: 600 | dashed | color: ch3
plot: (1 - abs(f - 144/M)/B + abs(1 - abs(f - 144/M)/B))/2*step(M - 3.5) | samples: 600 | dashed | color: ch3
marker: x = 24/M | label: new Nyquist
readout: new sampling rate, kHz = 48/M | digits: 3
readout: widest band without aliasing, kHz = 24/M | digits: 3
```

::: predict
## A 48 kHz recording is decimated by 6 for an 8 kHz telephone link. What must the filter in front of the decimator do?

- [ ] Nothing: dropping samples can't create new frequencies
- [x] Remove everything above 4 kHz
- [ ] Remove everything above 24 kHz
- [ ] Remove everything below 8 kHz

::: reveal
The new rate is 8 kHz, so its Nyquist frequency is 4 kHz. Anything left above 4 kHz in the 48 kHz signal folds back into the 0 to 4 kHz band after decimation, where nothing can remove it. A digital low-pass at about 3.4 kHz goes first, then every sixth sample is kept.
:::
:::

::: nameit
## Decimation by M

Keep every Mth sample: the rate becomes $f_s/M$, with Nyquist frequency $f_s/2M$. To avoid aliasing, first low-pass filter to below $f_s/2M$.

## Interpolation by L

Insert L − 1 zeros between samples: the rate becomes $Lf_s$, but the spectrum now contains **images**, copies of the original band around every multiple of the old rate (a tone at $f_0$ reappears at $f_s - f_0$, $f_s + f_0$, ...). A low-pass filter at the old Nyquist frequency, with gain L, removes them and fills in the zeros with smooth values.

## Rational rates

Interpolating by L and then decimating by M changes the rate by L/M. From 44.1 kHz to 48 kHz is

$$\frac{48{,}000}{44{,}100} = \frac{160}{147}$$

with one filter, cutting off at the lower of the two Nyquist frequencies, between the steps.

## Polyphase filters

Filtering at the high rate and then discarding M − 1 of every M outputs wastes most of the work. A **polyphase** decimator splits the N-tap filter into M branches and computes only the outputs that are kept, so the cost falls from $Nf_s$ to $Nf_s/M$ multiplications per second. Interpolators likewise skip the multiplications by the inserted zeros.
:::

::: example
## A 20 MHz digitized band is decimated by 64 for a single channel. What's the new rate, and what can the channel's bandwidth be?

::: solution
1. **New rate.**
   $$\frac{20\ \text{MHz}}{64} = 312.5\ \text{kHz}$$
2. **Nyquist frequency.**
   $$\frac{312.5\ \text{kHz}}{2} = 156.25\ \text{kHz}$$
3. **Channel bandwidth.** After a sharp filter, a real signal up to about 150 kHz wide fits, or a complex baseband signal twice that.

**Answer:** the new rate is 312.5 kHz, room for a real channel about 150 kHz wide or a complex one twice that.
:::
:::

::: example
## A 2000-tap decimation filter runs at 48 kHz with M = 6. What does polyphase save?

::: solution
1. **Direct.**
   $$2000 \times 48\,000 = 96 \times 10^6$$
   multiplications per second.
2. **Polyphase.** Only one output in six is ever computed:
   $$\frac{96 \times 10^6}{6} = 16 \times 10^6$$

**Answer:** polyphase cuts the work from 96 million to 16 million multiplications per second.
:::
:::

::: example
## 48 kHz audio is interpolated by 4 to 192 kHz. Where do the images of a 10 kHz tone land, and what must the filter do?

::: solution
1. **Where images come from.** Inserting zeros copies the spectrum around multiples of 48 kHz.
2. **Images in the new band.** Within 0 to 96 kHz the tone appears on each side of 48 kHz and just below 96 kHz:
   $$\begin{aligned} 48 - 10 &= 38\ \text{kHz} \\ 48 + 10 &= 58\ \text{kHz} \\ 96 - 10 &= 86\ \text{kHz} \end{aligned}$$
3. **The filter.** A low-pass at the new rate with its cutoff near 24 kHz removes them, leaving only the 10 kHz tone at the higher rate.

**Answer:** the images land at 38, 58 and 86 kHz, and a low-pass near 24 kHz at the new rate removes them.
:::
:::

::: check
given: s = 48 | 96 | 192; M = 2 | 4 | 6
answer: s/(2*M)
unit: kHz
tolerance: 0.5%

## A {s} kHz signal is decimated by {M}. Above what frequency must it be filtered out first?

::: right
Right. $f_s/2M$ = {answer} kHz.
:::

::: misses
- [s/M] That's the new sampling rate; the limit is half of it.
- [any] Not yet. The new Nyquist frequency.
:::
:::

::: check
given: s = 8 | 16 | 44.1; L = 2 | 3 | 4; f = 1 | 3
answer: s - f
unit: kHz
tolerance: 0.5%

## A {f} kHz tone sampled at {s} kHz is interpolated by {L} with zeros inserted. At what frequency is its first image?

::: right
Right. $f_s - f_0$ = {answer} kHz, which the interpolation filter must remove.
:::

::: misses
- [s + f] That's the second image; the first is just below the old rate.
- [L*s - f] That's the last image below the new rate; the first comes at the old rate minus the tone.
- [any] Not yet. Images sit around multiples of the old rate.
:::
:::

::: check
given: s = 44.1 | 48 | 32; L = 160 | 3 | 5; M = 147 | 2 | 4
answer: s*L/M
unit: kHz
tolerance: 0.5%

## A {s} kHz signal is interpolated by {L} and decimated by {M}. What's the new rate?

::: right
Right. $f_sL/M$ = {answer} kHz.
:::

::: misses
- [s*M/L] Interpolating multiplies the rate; decimating divides it.
- [any] Not yet. Up by L, down by M.
:::
:::

::: check
given: N = 200 | 1000 | 4000; s = 48 | 192; M = 4 | 8 | 16
answer: N*s*1000/M/1e6
tolerance: 0.5%

## A {N}-tap polyphase decimator runs at {s} kHz input with M = {M}. How many million multiplications per second does it need?

::: right
Right. $Nf_s/M$ = {answer} million per second.
:::

::: misses
- [N*s*1000/1e6] That's filtering every input sample; polyphase computes only the kept outputs.
- [any] Not yet. Taps times output rate.
:::
:::

::: check
kind: parts
given: fs = 20 | 61.44; M = 16 | 64; B = 0.2 | 0.5

## A {fs} MHz signal is decimated by {M}.

::: part
answer: fs/M
unit: MHz
tolerance: 0.5%

### What is the new rate?

::: misses
- [any] $f_s/M$.
:::
:::

::: part
answer: fs/M/2
unit: MHz
tolerance: 0.5%

### What bandwidth can survive without aliasing?

::: misses
- [any] Half the new rate.
:::
:::
:::

::: check
kind: parts
given: N = 500 | 2000; M = 4 | 6 | 8; fs = 48 | 96

## An {N}-tap decimation filter at {fs} kHz decimates by {M}.

::: part
answer: N*fs*1000/1e6
tolerance: 0.5%

### How many million multiplies a second does it take, computed directly at the input rate?

::: misses
- [any] Taps × input rate.
:::
:::

::: part
answer: N*fs*1000/M/1e6
tolerance: 0.5%

### And in polyphase form, in millions a second?

::: misses
- [any] Only every Mth output is computed.
:::
:::
:::

::: explain
## Why must a decimator filter before it discards samples?

::: model
Keeping only every Mth sample lowers the sampling rate by M, and with it the highest frequency the samples can represent. Any content in the original signal between the new Nyquist frequency and the old one doesn't disappear when samples are dropped: it produces exactly the same sample values as some lower frequency, so it folds down on top of the wanted band. Once the samples are dropped, the folded content can't be separated from the real signal. Low-pass filtering first removes everything above the new Nyquist frequency while the higher rate can still represent it, so nothing is left to fold.
:::
:::

::: practice

::: check
given: s = 1 | 100000; M = 2 | 3 | 4 | 5 | 8 | 10 | 16 | 32 | 64 | 100
answer: s/(2*M)
unit: kHz
tolerance: 0.5%

## Filter limit before decimating {s} kHz by {M}?

::: misses
- [any] $f_s/2M$.
:::
:::

::: check
given: s = 8 | 192; L = 1 | 2 | 3 | 4 | 5 | 6; M = 1 | 2 | 3 | 4 | 5 | 7
answer: s*L/M
unit: kHz
tolerance: 0.5%

## New rate: {s} kHz, up by {L}, down by {M}?

::: misses
- [any] $f_sL/M$.
:::
:::
:::
