Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 36 ยท Sampling and Z-transform

Aliasing, Anti-Aliasing and Practical Reconstruction

See how undersampling folds frequencies, compute alias frequencies, apply anti-alias filters with scipy.signal.decimate, and compare zero-order hold with ideal reconstruction.

When you sample too slowly, the repeated copies of the spectrum overlap, and high frequencies masquerade as low ones. This is aliasing. It is the reason wagon wheels appear to spin backwards in films, why unfiltered audio decimation sounds harsh, and why every serious analog-to-digital converter has a filter in front of it.

Why frequencies fold

Sampling a cosine of frequency f at fs gives x[n] = cos(2ฯ€ f n / fs). Adding any integer multiple of fs to f does not change those samples, because cos(2ฯ€ (f + k fs) n / fs) = cos(2ฯ€ f n / fs + 2ฯ€ k n) and k n is an integer. So the samples cannot tell f from f + k fs, or from -f + k fs. The system reports the alias in the range [0, fs/2].

To compute it, wrap f into [-fs/2, fs/2):

f_alias = | f - fs ยท round(f / fs) |.

A 30 Hz tone sampled at 40 Hz gives round(30/40) = 1 and an alias of |30 - 40| = 10 Hz. A 70 Hz tone also aliases to 10 Hz. They are indistinguishable once sampled.

Python Two different tones, identical samples

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 sine, the alias may also flip the sign (a phase reversal). That is why the wagon wheel appears to turn backward: the apparent rotation rate is the aliased one.

Preventing aliasing

Fix the problem before sampling: the anti-aliasing filter is an analog low-pass with cutoff near fs/2 that removes content above what the sampler can represent. After sampling it is too late, because the alias is indistinguishable from legitimate data.

When you reduce the sampling rate of an already-sampled signal (decimation), you do the same thing digitally: low-pass filter first, then keep every M-th sample. scipy.signal.decimate does both steps. In the example, a 2000 Hz recording contains a wanted 50 Hz tone and an unwanted 700 Hz tone. Keeping every 8th sample (new rate 250 Hz, Nyquist 125 Hz) without filtering folds the 700 Hz tone to 700 - 750 = -50 Hz, which lands on top of the wanted tone and corrupts it. With filtering, the 700 Hz tone is removed.

Python Decimation with and without a 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.

In the naive output the 700 Hz tone shows up at 50 Hz, exactly where the real tone is, so you can no longer separate them. The decimated result keeps only the genuine 50 Hz component.

Reconstruction in real converters

A digital-to-analog converter (DAC) cannot output ideal impulses or sincs. It produces a zero-order hold (ZOH): each sample value is held constant until the next one. The hold has the frequency response of a sinc, which droops at high frequencies (about -3.9 dB at fs/2) and leaves images of the spectrum at multiples of fs. An analog reconstruction filter after the DAC removes the images and, in high-end designs, a compensating digital filter flattens the droop.

Python Zero-order hold droop

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.

Oversampling DACs first interpolate the digital signal to a much higher rate. The images then sit far from the audio band, so a cheap, gentle analog filter is enough.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A 70 Hz sine is sampled at 100 Hz. At what frequency does it appear?

    round(70/100) = 1, so the alias is |70 - 100| = 30 Hz.
  2. 2. Where should an anti-aliasing filter be placed?

    Once frequencies fold onto lower ones they cannot be separated, so the content above fs/2 must be removed before sampling.
  3. 3. What does scipy.signal.decimate do?

    decimate applies an anti-aliasing filter and then keeps every M-th sample.
  4. 4. What does a zero-order hold in a DAC cause?

    Holding each sample multiplies the spectrum by a sinc, attenuating high frequencies and leaving images at multiples of fs.

Summary

  • Sampling cannot distinguish f, f + k fs and -f + k fs; frequencies fold into [0, fs/2].
  • The alias of f at rate fs is |f - fs round(f/fs)|.
  • Anti-aliasing filters must act before sampling or before downsampling.
  • Real DACs use a zero-order hold plus a reconstruction filter instead of ideal sinc interpolation.

Next: The Z-transform