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.
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 , 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
| n | 1 kHz angle | 5 kHz angle, without full turns | Both values |
|---|---|---|---|
| 0 | 0° | 0° | 1 |
| 1 | 60° | 300° = −60° | 0.5 |
| 2 | 120° | 240° = −120° | −0.5 |
| 3 | 180° | 180° | −1 |
| 4 | 240° | 120° | −0.5 |
| 5 | 300° | 60° | 0.5 |
| 6 | 0° | 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 , 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:
Full turns change nothing, and the cosine is the same for the angles and . 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 frequency | Alias at Fs = 48 kS/s |
|---|---|
| 5 kHz | 5 kHz |
| 20 kHz | 20 kHz |
| 28 kHz | 20 kHz |
| 47 kHz | 1 kHz |
| 49 kHz | 1 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 , select for unambiguous reconstruction from an ideal complete sequence of samples. The limit 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 between measurements and the angle through which the point turns in this time for the 1 kHz and 7 kHz signals.
s µs. In this time, the 1 kHz point turns by , and the 7 kHz point turns by , which is almost a full turn. A rotation of counterclockwise takes the point to the same place as a rotation of clockwise.
Compare the horizontal coordinates of the two points (the sample values) at the moments .
The angles for 7 kHz are: , , . 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 match.
Will the next samples also match? Will a longer record at the same help you tell these cosines apart?
For 7 kHz, the angle at sample is . Whole turns do not change the position of the point, so it is always at the same place as the point with the angle — 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 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.