∿ LEARN DSPFrom signal to HF transceiver
Lab / lesson

Aliasing: different signals, same samples

Why sampling can make different frequencies impossible to tell apart.

← Sine wave and samples

First — two rotations

In the previous lesson, we recorded the horizontal coordinate of a point on a circle. Now take two cosines with amplitude 1 and initial phase 0: 1 kHz and 5 kHz. We measure both at Fs = 6 kS/s.

In the time between two samples:

  • the 1 kHz point moves through 60°;
  • the 5 kHz point moves through 300°, almost a full turn.

Both turn in the same direction. After the first step, one point is at the top right, and the other is at the bottom right. Their positions are different, but the horizontal coordinate is the same: 0.5. This coordinate is the value that we record.

1 kHz · green point5 kHz · orange point
1 kHz−1+160°Value: 0.5005 kHz−1+1300°Value: 0.500
Sample n = 1: both values are 0.500

With “Only the sampling instants” on, move the slider from 0 to 6. At each step, the values are the same. The total angle shows that the fast point really makes more turns.

Now turn off this checkbox and set the slider to 0.50. Its scale is in intervals between samples: this is 0.5Ts0.5T_s, the middle between samples 0 and 1, not 0.5 seconds. The values become approximately +0.866 and −0.866. The signals are different; we simply did not observe them at this moment.

What stays in the array

n1 kHz angle5 kHz angle, without full turnsBoth values
00°0°1
160°300° = −60°0.5
2120°240° = −120°−0.5
3180°180°−1
4240°120°−0.5
5300°60°0.5
60°0°1

In both cases, memory contains the same sequence. From it, you cannot find which of the two signals was at the input. This ambiguity is aliasing. We call 1 kHz the low-frequency alias of the 5 kHz signal: at the selected FsF_s, its samples cannot be told apart from the samples of 5 kHz.

The analog signal itself did not become slow: its samples and the samples of the slow signal are the same.

Why this works for every sample index

Here 5 kHz = Fs − 1 kHz. For an integer n:

cos⁡(2πFs−fFsn)=cos⁡(2πn−2πfFsn)=cos⁡(2πfFsn).\cos\left(2\pi\frac{F_s-f}{F_s}n\right) =\cos\left(2\pi n-2\pi\frac{f}{F_s}n\right) =\cos\left(2\pi\frac{f}{F_s}n\right).

Full turns 2πn2\pi n change nothing, and the cosine is the same for the angles +θ+\theta and −θ-\theta. The equality is true for all integer n. This is why a record ten times longer does not help: the new samples are also the same.

This equality applies to our cosines with zero phase. When a frequency with an arbitrary initial phase folds, the equivalent cosine has a phase with the opposite sign. Two arbitrary signals with frequencies f and Fs−f do not have to match sample for sample.

Back to 48 kS/s

The mechanism is the same: 47 kHz = 48 kHz − 1 kHz. At each step, we get 352.5° against 7.5°. After we remove full turns, this is −7.5° against +7.5° — the same horizontal coordinate.

For our cosines, we can fold frequencies into the band from 0 to Fs/2:

Input frequencyAlias at Fs = 48 kS/s
5 kHz5 kHz
20 kHz20 kHz
28 kHz20 kHz
47 kHz1 kHz
49 kHz1 kHz

Lab: check that the samples match

The experiment script plots continuous reference curves and samples for 1/5 kHz at Fs = 6 kS/s. Then it checks the pair 1/47 kHz at Fs = 48 kS/s.

uv run labs/01/02-aliasing.py --show

The key part:

fs = 6_000
n = np.arange(60)
t = n / fs
slow = np.cos(2 * np.pi * 1_000 * t)
fast = np.cos(2 * np.pi * 5_000 * t)
print(np.max(np.abs(slow - fast)))

You get a number near zero: the small remainder comes from float64 calculations. Try to increase the number of samples. Then, separately, change Fs from 6000 to 8000. Predict in which experiment the equality stays. The script itself first checks the initial conditions, so it is easier to make your own changes in the code part above.

How not to lose the information you need

If all frequencies of a real signal are in the band from 0 to BB, select Fs>2BF_s>2B for unambiguous reconstruction from an ideal complete sequence of samples. The limit Fs/2F_s/2 is the Nyquist frequency. The assumption about the band is important: before sampling, the signal must not contain unknown components outside this band.

Before a real analog-to-digital converter (ADC), we put an anti-aliasing filter (an analog low-pass filter that prevents aliasing). It attenuates the frequencies that could alias into the useful band. Because the filter roll-off is not infinitely steep, you need a margin between the useful band and Fs/2.

If 47 kHz is already recorded as 1 kHz, a digital filter after the ADC cannot tell it apart from a real useful 1 kHz tone. When you decrease Fs digitally, you also need a filter before you remove samples. We discuss this in the part about changing the sample rate (multirate DSP).

Self-check

At Fs = 8 kS/s, we compare cosines at 1 kHz and 7 kHz, both with zero initial phase.

Find the interval Ts=1/FsT_s=1/F_s between measurements and the angle Δθ=360∘f/Fs\Delta\theta=360^\circ f/F_s through which the point turns in this time for the 1 kHz and 7 kHz signals.

Explanation

Ts=1/8000T_s=1/8000 s =125=125 µs. In this time, the 1 kHz point turns by 45∘45^\circ, and the 7 kHz point turns by 315∘315^\circ, which is almost a full turn. A rotation of 315∘315^\circ counterclockwise takes the point to the same place as a rotation of 45∘45^\circ clockwise.

Compare the horizontal coordinates of the two points (the sample values) at the moments n=0,1,2n=0,1,2.

Explanation

The angles for 7 kHz are: 0∘0^\circ, 315∘315^\circ, 630∘=270∘+360∘630^\circ=270^\circ+360^\circ. The 1 kHz and 7 kHz points are mirror images of each other about the horizontal axis. Mirror points have the same horizontal coordinate, so the samples 1, 0.707, 01,\ 0.707,\ 0 match.

Will the next samples also match? Will a longer record at the same FsF_s help you tell these cosines apart?

Explanation

For 7 kHz, the angle at sample nn is 315∘n=360∘n−45∘n315^\circ n=360^\circ n-45^\circ n. Whole turns do not change the position of the point, so it is always at the same place as the point with the angle −45∘n-45^\circ n — the mirror image of the 1 kHz point. The sample sequences are fully the same. A longer record adds new numbers that also match, but no new information. You can tell the signals apart only if you change FsF_s or remove 7 kHz before sampling.

First answer with the circle, then check in Python. After this, we examine what occurs exactly at Fs/2 and why “two samples per period” is a dangerous simplification.

Next lesson: The Nyquist frequency: where the phase goes.