% eda06_03
% example of aliasing

% set up time
N=50;
Dt=1;
tmin=0.0;
tmax = tmin+Dt*(N-1);
t = tmin + Dt*[0:N-1]';

% nyquist frequencies
Nf=N/2+1;
fmax = 1/(2*Dt);
Df = fmax/(N/2);
f = Df*[0:Nf-1]';
Nw=Nf;
wmax = 2*pi*fmax;
Dw = wmax/(N/2);
w = Dw*[0:Nw-1]';

% low frequency oscillation
w1= 2*Dw;
w1
d1 = cos( w1*t );

% high frequency oscillation
w2= (2+N)*Dw;
w2
d2 = cos( w2*t );

% set up higher sample rate time
N=500;
Dt=0.1;
tmin=0.0;
tmax = tmin+Dt*(N-1);
t3 = tmin + Dt*[0:N-1]';
d3 = cos( w2*t3 );

figure(1);
clf;
subplot(2,1,1);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax/2, -2, 2] );
plot(t, d1, 'k-','LineWidth',2);
plot(t, d1, 'ko','LineWidth',2);
plot([tmin, tmax]', [0, 0]', 'k-');
xlabel('time, t');
ylabel('d1(t)');

subplot(2,1,2);
set(gca,'LineWidth',2);
hold on;
axis( [tmin, tmax/2, -2, 2] );
plot(t, d2, 'k-','LineWidth',2);
plot(t, d2, 'ko','LineWidth',2);
plot(t3, d3, 'k:','LineWidth',2');
plot([tmin, tmax]', [0, 0]', 'k-','LineWidth',2);
xlabel('time, t');
ylabel('d2(t)');
