% Side roll-off characteristics of rectangular and Hann windows %emol

clc %emol
clearvars %emol
close all %emol

f1=9; f2=14; fs=50; 
T=15.6; % to see some windowing effect (even for a large T %emol)

t=0:1/fs:T-1/fs; 
x=1*sin(2*pi*f1*t)+0.001*sin(2*pi*f2*t);
N=length(x);
whan=hanning(N); 
xh=x.*whan';
X=fft(x); 
Xh=fft(xh);
f=fs*(0:N-1)/N;

figure(1)
plot(f(1:N/2+1),20*log10(abs(X(1:N/2+1)/fs/T)),'b-'); %emol
axis([0 25 -180 0])
xlabel('Frequency (Hz)'); ylabel('Modulus (dB)')
hold on
plot(f(1:N/2+1),20*log10(sqrt(8/3)*abs(Xh(1:N/2+1)/fs/T)),'r:')
legend('rect','hann') %emol
hold off
grid on %emol