Visualizing aliasing in Matlab I am trying to verify for myself that aliasing actually makes it impossible to distinguish the "real" and the aliased frequency. What I have done it set the sampling rate to 20 Hz and created two sine wave with 2 Hz and 18 Hz. As far as I understand the 18 Hz signal should alias to a 2 Hz signal when the sampling rate is 20 Hz.

Matlab code:

t = [0:0.05:1];      //20Hz sampling
a = sin(2*pi*2*t);   //2Hz sine wave
b = sin(2*pi*18*t);  //18Hz sine wave
plot(t, a);
hold on;
plot(t, b, 'red');


The plot looks like this:



I can see that both sine waves are equal, but 180 degrees out of phase. I wonder if there is something to it or if it's just Matlab drawing through the points in opposite ways?
I think you should plot something like:

t = [0:0.05:1];      %20Hz sampling
a = sin(2*pi*2*t);   %2Hz sine wave
b = sin(2*pi*18*t);  %18Hz sine wave
plot(t, a, 'bo');
hold on;
plot(t, b, 'ro');

T = [0:0.001:1];     %1000Hz sampling frequency
A = sin(2*pi*2*T);
B = sin(2*pi*18*T);
% plot for 1000Hz sampling frequency
plot(T, A, 'b');
plot(T, B, 'r');

legend({'2Hz @ 20 Hz f_s', '18Hz @ 20 Hz f_s', '2Hz @ 1000 Hz f_s', '18Hz @ 1000 Hz f_s'})


That allows to understand which exact samples of your sinusoids you are taken at a given sampling frequency: