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

clc %emol
clearvars %emol
close all %emol

f1=10; f2=20; f3=21; fs=60; 
T=0.6; % try different values: 0.6, 0.8, 1.0, 1.5, 2, 2.5, 3, 4

t=0:(1/fs):T-1/fs; 
x=2*sin(2*pi*f1*t)+2*sin(2*pi*f2*t)+2*sin(2*pi*f3*t);
N=length(x);
whan=hanning(N);
x=x.*whan';
% wham=hamming(N); %emol
% x=x.*wham'; %emol
X=fft(x);
f=(fs/N)*(0:N-1);

Xz=fft([x zeros(1,2000-N)]); % zero padding
Nz=length(Xz);
fz=(fs/Nz)*(0:Nz-1);

figure(1)
stem(f(1:N/2+1),sqrt(8/3)*abs(X(1:N/2+1)/(fs*T)),'r:') % sqrt(8/3)? %emol
axis([0 30 0 1.2])
xlabel('Frequency (Hz)'); ylabel('Modulus')
hold on
plot(fz(1:Nz/2+1),sqrt(8/3)*abs(Xz(1:Nz/2+1)/(fs*T)),'b-') %emol
hold off; 
grid on