Skip to content
Tutorials Center
My learning

Topics

Lesson 27 of 38 ยท Multirate and Adaptive Filters

Decimation and Aliasing

Reduce the sampling rate of a signal safely. See what aliasing does when you simply drop samples, then use an anti-alias filter with scipy.signal.decimate.

Many systems need to change the sampling rate: a recording at 48 kHz must feed a speech model that expects 16 kHz, a software radio digitizes at megahertz rates but needs to analyze a narrow channel, or a sensor stream must be stored with fewer samples. Processing that works with more than one sampling rate is called multirate signal processing. The simplest operation is decimation: reducing the rate by an integer factor M.

Downsampling and why it is dangerous

Downsampling keeps every M-th sample: y[n] = x[nM]. The new sampling rate is fs / M. The catch is the Nyquist limit: after downsampling, only frequencies below fs / (2M) can be represented. Anything above that aliases, folding back into the lower band as a false component that cannot be told from a genuine one.

Decimation by M

  1. Filter
Low-pass at fs/(2M)
  1. Keep every M-th
Downsample
Result Rate is fs/M

Skip step 1 and aliasing corrupts the signal.

1 / 2
Python Aliasing from plain downsampling

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 180 Hz tone now appears at 70 Hz, where it looks like a real component. Once the samples are dropped nothing can undo this; the filter must come first.

The anti-alias filter

Before dropping samples, apply a low-pass filter with cutoff slightly below the new Nyquist frequency fs / (2M). It must attenuate everything above that to below the noise level of interest. The combination "filter, then keep every M-th sample" is decimation. scipy.signal.decimate does this with an IIR Chebyshev filter (default) or an FIR filter (ftype="fir").

Python Decimation with an anti-alias 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 40 Hz tone survives with amplitude near 1, while the 180 Hz tone is removed, so nothing shows up at the alias frequency of 70 Hz.

Doing it yourself

For learning, write the two steps explicitly: design a low-pass FIR, filter with it, then slice.

Python Filter then downsample by hand

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 1500 Hz tone would have folded to 500 Hz (the new Nyquist limit); the filter removed it first.

Choosing the filter

  • Passband edge: the highest frequency you want to keep.
  • Stopband edge: fs/M minus that edge. Components between the passband edge and fs/(2M) are allowed to alias only into frequencies you do not care about.
  • FIR gives linear phase and is easy to make efficient with polyphase structures.
  • IIR is cheaper per output but has nonlinear phase; decimate with the default IIR design is limited to factors of about 13 per stage (use multiple stages for bigger factors).
  • Multistage decimation (for example 64 = 4 x 4 x 4) is far cheaper than one large step because early stages run at the high rate but need only gentle filters.

Aliasing is not always a bug. Bandpass sampling deliberately undersamples a narrowband signal centered at a high frequency so that it aliases down to baseband. The band must be filtered and sit within a single Nyquist zone.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A signal sampled at 12 kHz is downsampled by 3 without filtering. Where does a 5 kHz tone appear?

    The new rate is 4 kHz, so the Nyquist limit is 2 kHz. A 5 kHz tone folds around the new sampling rate to |5 - 4| = 1 kHz.
  2. 2. What must happen before samples are discarded in decimation?

    Components above fs/(2M) would alias, so they must be removed first.
  3. 3. Why is multistage decimation often cheaper than a single big step?

    Splitting a large factor into small ones relaxes each filter's transition band and reduces the number of multiplications per second.
  4. 4. What is bandpass sampling?

    If the band lies within one Nyquist zone, aliasing moves it to a low frequency without loss of information.

Summary

  • Decimation by M means low-pass filtering, then keeping every M-th sample.
  • Without the filter, content above fs/(2M) aliases into the new band and cannot be removed.
  • scipy.signal.decimate automates the steps; large factors use several stages.
  • FIR filters give linear phase and efficient polyphase forms; IIR filters are cheaper but distort phase.

Next: Interpolation and Resampling