% Amplitude spectrum of harmonic signals %emol
% (complex Fourier coefficients)         %emol
% Demonstration of aliasing              %emol

clc %emol
clearvars %emol
close all %emol

fs=100; 
T=10; 
t=0:(1/fs):T-1/fs; % why 1/fs? what is it? %emol
p1=20; p2=80; p3=120; % is fs all right? %emol
x1=sin(2*pi*p1*t);
x2=sin(2*pi*p2*t);
x3=sin(2*pi*p3*t);

N=length(t);
X1=fft(x1); 
X2=fft(x2); 
X3=fft(x3);
f=(fs/N)*(0:N-1); % why fs/N? what is it? %emol

% Note that there is no filtering on x1, x2 and x3 before the fft.

figure(1); 
plot(f,abs(X1)/(fs*T),'b-') % why (fs*T)? what is it? %emol
xlabel('Frequency (Hz)'); ylabel('Modulus')
axis([0 100 0 0.55])
grid on

figure(2); 
plot(f,abs(X2)/(fs*T),'b-')
xlabel('Frequency (Hz)'); ylabel('Modulus')
axis([0 100 0 0.55])
grid on

figure(3); 
plot(f,abs(X3)/(fs*T),'b-')
xlabel('Frequency (Hz)'); ylabel('Modulus')
axis([0 100 0 0.55])
grid on