% This function illustrates the phenomenon of aliasing

function spectr_03
  
echo off, clc
clear all


% basic number of grid points;
N = 5;
dx = 2.0 * pi / N;

X = (0.0:dx:(N-1)*dx);

Y(1,:) = sin( X );
Y(2,:) = sin( (N + 1) * X );
Y(3,:) = sin( (2*N + 1) * X );
Y(4,:) = sin( (-N + 1) * X );


% plotting aliased sinusoids;
X2 = (0.0:0.01:2.0*pi);
figure(1); plot(X,sin(X),'-o',X2,sin((N+1)*X2),X2,sin((2*N+1)*X2));
legend('sin(x)','sin((N+1)*x)','sin((2*N+1)*x)');

figure(2); plot(X,sin(X),'-o',X2,sin((N+1)*X2),X2,sin((2*N+1)*X2),...
		X2,sin((3*N+1)*X2),X2,sin((4*N+1)*X2));
axis([1.0 2.0 -1.0 1.0]);
legend('sin(x)','sin((N+1)*x)','sin((2*N+1)*x)','sin((3*N+1)*x)','sin((4*N+1)*x)');
