Skip to content
~/home/alelouis

Visualizing frequency aliasing

Have you ever wondered why car wheels appear to go backward, or even stop, in video footages ? Me too, I think it was one of those first questions that stuck in my head for hours when I was a child.

You may have guessed, we will talk about aliasing today !

Aliasing is a phenomenon that arise in the discrete world. Specifically, the process of sampling (anything : audio, video, images...) involves a distortion of the original process in its discrete representation. As a quick note, one should distinguish between temporal aliasing, which arises from sampling in time, from spatial aliasing which distorts spatially sampled inputs (e.g. the pixels from a camera).

Because it's vastly easier to write a blog post with visual examples and animations, we'll explore visual temporal aliasing (the reverse wheel analog effect I was talking about).

We need a wheel, or a fan, or anything that rotates.

I'm really to lazy to go outside, mount a camera on my car and record real footage of wheels on this Sunday morning. Instead, I will code a fan animation using parameteric curves.
Starting from a complex exponential spanning $[0, 2\pi]$, I adjust its module to be a faster cosine. This gives us a fan-like aspect, enough to see rotation effects.

t = linspace(0, 2*pi, 1000)
phi = exp(2j*pi*f*time)
s = phi*exp(1j*t)*abs(cos(2*t))

The $\phi$ variable represents another complex exponential of angle $2\pi f t_{time}$, which evolves with time and which frequency is defined by $f=0.1 \text{Hz}$, this is what makes the whole shape rotate.

Rendering at a framerate (or sampling rate) of $60 \text{Hz}$, we get the following observation.

Figure $1$: Hooray, it's rotating !

I also indicate by a yellow circle the origin of the fan in order to not get confused (even if we will).

Make it run backwards, that's what we paid for.

All right. Next, we'll sweep the rotating frequency of this beautiful fan from $0.1 \text{Hz}$ to $59.5 \text{Hz}$, near sampling rate then. This is what happens:

Figure $2$: Hooray, it's rotating backwards!

Whoo, things are going fast, we can't nearly follow anything, but the end part is of our interest.

We started from an anti-clockwise rotation (of exactly $0.1 \text{Hz}$) to a clockwise rotation (of exactly $0.5 \text{Hz}$). Below is depicted the actual frequency profile applied to the fan. Notice it doesn't reach $60$, the asymptote is located at $59.5$.

Figure $3$: Fan frequency profile

Maybe you know, or not (doesn't matter), that some famous swedish guy name Harry Nyquist (or maybe was it Shannon, or Whittaker, well some smart dude over there) stated that you can't represent faithfully (without aliasing) signals of frequency $f$ without sampling at least at $2f$ (it was told the other way around but it all means the same).

As an example, suppose you have a fan (coincidental here) running at $0.1 \text{Hz}$, insert-smart-dude-name-here explained that in order to sample the phenomenon temporally without aliasing, one should at least sample to $0.2 \text{Hz}$.

No trouble, I told you earlier that the sampling rate was $60 \text{Hz}$, so we are way higher than needed.

But I swept the frequency, until $59.5 \text{Hz}$, oops...

Way higher than I was allowed to: if our sampling rate is of $60 \text{Hz}$ and that has to be the double of our maximum frequency, I should not go over $30 \text{Hz}$ otherwise there would be... aliasing !

That's why we see a clockwise rotation at the end, we actually observing the effect of aliasing because we stepped over the Nyquist frequency (here $30 \text{Hz}$).

Figure $4$: Getting aliased

The dotted line is the actual frequency we are seeing for the end half of the animation, being the aliased version of the greater, true, frequency. We are constrained to see everything in the yellow area: between $-F_s/2$ and $F_s/2$.

See the discontinuity at precisely $F_s/2 = 30 \text{Hz}$ ? This is where the frequency jumps to negative frequencies, or in more common terms: the fan apparent motion changes direction ! Also, near $F_s=60\text{Hz}$, the frequency goes back to $0 \text{Hz}$, the fan would appear still, even if moving.

You probably saw videos on the internet of flying helicopters with pales being still: this is the same case. If the speed of rotation of the pales is a near-perfect multiple of the camera frame rate, the pales won't move. Another way to look at it is to think that between each frame, the pales have the time to rotate multiple times and land perfectly in the right position of the next frame (modulo the symmetry of the pales that can lower this number down and still achieve the same effect).

More ?

But why stop at $F_s$, we can go higher still. I will repeat the sweep profile 3 times going up to $180 \text{Hz}$. There is no way we can see those frequencies, all of them will be aliased back to the yellow area.

Figure $5$: You can't escape !

We are stuck, every higher frequency gets inevitably aliased to the yellow area. This is aliasing, so where does it come from ? I will try to give an intuitive explanation in the next section.

Dirac, welp.

Real signals, or fans, do not have sampling frequency: they are continuous time signals. When sampling, one mathematical operation that can be used to describe the effect is the multiplication of the continuous signal by a Dirac comb. A Dirac comb is simply an infinite number of Dirac delta functions evenly spaced. The effect of such spatial multiplication on the frequency content of the signal can be intuited following the convolution theorem that states the multiplication / convolution duality.

Multiplication in {time, frequency} domain means convolution in {frequency, time}.

By multiplying by a Dirac comb in the temporal domain, we are convoluting by the Fourier transform of that Dirac comb (another Dirac comb, different) in the frequency domain.

$$\text{FT}[P_{T}]=\frac{1}{T} P_{1/T}$$

Convoluting by a Dirac comb is the same as making a signal periodic, copying the frequency content at each Dirac delta. As an example, I plotted below the Dirac comb illustrating a sampling frequency of $10 \text{Hz}$, so with sampling period of $0.1 \text{s}$. Below it, its Fourier Transform: another Dirac comb, here with period $1/T = 10 \text{Hz}$

Figure $6$: Time and frequency Dirac comb

As a final illustration I will show the best mental model I have for aliasing.

  • First, think about the true signal: it consist in visualizing the true frequency as a vertical bar (or shape) at a given frequency, simple. (top plot)
  • Next, the sampled signal: for each multiple of $F_s$, consider that the new origin and place the true frequency in respect to it. (bottom plot)
Figure $7$: Aliasing mental model

The bar which lies between $-F_s/2$ and $F_s/2$ is the aliased frequency observed.

End words.

Writing this post felt like answering the questions for my younger me, it was a pleasant feeling that I might reiterate in the future.

Get back to top