Aliasing and the discrete-time Fourier transform10

Posted by Steve Eddins,

Many of you were onto me immediately last week. I asked you to estimate the frequency of the sampled cosine signal below, and readers quickly chimed in to guess that this question was really a teaser about aliasing.

As it happened, I started with a 1 rad/second cosine, , :

t = linspace(-2.3*pi, 2.3*pi, 800);
alpha = 1;
x_c = cos(alpha * t);
plot(t, x_c, 'k')

And I sampled that signal to get with so that .

T = 1;
n = -7:7;
nt = n * T;
x = cos(alpha*n*T);
hold on
plot(nt, x, 'ok')
hold off

But I could have started with a completely different frequency and still ended up with exactly the same samples. For example, let's see what happens when we try :

alpha_2 = 2*pi - 1;
x2_c = cos(alpha_2 * t);
plot(t, x2_c, 'k')

x2 = cos(alpha_2 * n * T);
hold on
plot(nt, x2, 'ok')
hold off

The two sets of samples are the same (within floating-point round-off error):

max(abs(x - x2))
ans =

1.1657e-015



Let's look at this phenomenon in terms of the relationship between the continuous-time Fourier transform and the discrete-time Fourier transform (DTFT). Below is the continuous-time Fourier transform of .

The DTFT is a collection of copies of the continuous-time Fourier transform, spaced apart by the sampling frequency, and with the frequency axis scaled so that the sampling frequency becomes . Here's the DTFT of .

Now has a higher frequency as you can see in the plot of its continuous-time Fourier transform:

But when you make a bunch of copies of spaced apart by the sampling frequency, you find that the DTFT of is exactly the same as the DTFT of .

Usually only a single period of the DTFT is plotted:

In other words, when you use a sampling rate of , the frequencies 1 and are indistinguishable. This is called aliasing. In general, the continuous-time frequency is indistinguishable from any other frequency of the form , where is an integer.

So far we've talked about the continuous-time Fourier transform, the discrete-time Fourier transform, their relationship, and a little bit about aliasing. Next time we'll bring the discrete Fourier transform (DFT) into the discussion. That's what the MATLAB function fft actually computes.

Get the MATLAB code

Published with MATLAB® 7.9

Dave S. replied on : 1 of 10

Hi Steve,

First let me say I really appreciate and enjoy you explaining the Fourier transforms, wish they would have taught us this in Math in such a detail.

I’m at a loss with the way you described the alaising problem. I have come to know it as a problem, which occurs when the sampling rate of your discreet signal is not at least twice the amount of the highest exisiting frequency. But I can’t see how this fits in with the alaising you discribed above. Would you be so kind and explain that alaising thing next time you got time?

Greetings from Germany

Steve replied on : 2 of 10

Dave—Very good question. Yes, I will explain that in another blog post.

Chandrakanth R. Terupally replied on : 3 of 10

Dave,

Its actually simple to relate what you have learnt with that Steve blogged. Here it is how: the two frequencies were 1 and 2pi-1 which is 1 & 5.28 rad/s. Now remember what sampling theorem says – that freq of sampling Fs must be at least twice that of the highest frequency in the signal, right? Steve’s example didn’t honour sampling theorem as Fs was only 1 rad/s (T=1) and hence ended up with aliasing effect.

Anand replied on : 4 of 10

how should i see the aliasing effect??
with my code i cant see overlapping of spectrums??
code:

clear all;
f1=10;F1=100;f2=90;F2=100;
for n=1:50,
x1(n)=10*sin(2*pi*n*f1/F1);
fr1(n)=n/25*F1/2;
end
y1=fft(x1,50);
plot(fr1,abs(y1));
xlabel('frequency in Hz');
ylabel('Amplitude');
figure;
for n=1:50,
x2(n)=10*sin(2*pi*n*f2/F1);
fr2(n)=n/25*F1/2;
end
y2=fft(x2,50);
plot(fr2,abs(y2));
xlabel('frequency in Hz');

Steve replied on : 5 of 10

Anand—You should only plot to 50 Hz (half the sampling frequency). In your second plot, the 90 Hz signal has been aliased to 10 Hz.

I’d also like to suggest some simplifications to your code. You don’t need those loops to create your signals x1 and x2.

n = 0:49;
x1 = 10*sin(2*pi*n*f1/F1);
x2 = 10*sin(2*pi*n*f2/F1);


Also, I suggest that you not use “clear all”. If you want to clear your base workspace variables, just use “clear”.

Steve replied on : 7 of 10