N = 31;
NFFT = 2^14;
f = [0:NFFT-1]/NFFT - 0.5;

figure();
x = cos(2*pi*0.25*[0:N-1].');
w = rectwin(N);
X = 20*log10(abs(fftshift(fft(x.*w,NFFT))));
W = 20*log10(abs(fftshift(fft(w,NFFT))));
subplot(211);
plot(f,W,'LineWidth',2); hold on;
subplot(212);
plot(f,X,'LineWidth',2); hold on;

w = hamming(N);
X = 20*log10(abs(fftshift(fft(x.*w,NFFT))));
W = 20*log10(abs(fftshift(fft(w,NFFT))));
subplot(211);
plot(f,W,'LineWidth',2); hold off; ylim([-50 30]);
grid on;
subplot(212);
plot(f,X,'LineWidth',2); hold off; ylim([-50 30]);
grid on;

xlabel('Frequency [Cycles/Sample]','FontSize',16);
shg;


figure();
N = 15;
x = sinc(0.5*[-N:N].');
w = rectwin(2*N+1);
X = 20*log10(abs(fftshift(fft(x.*w,NFFT))));
W = 20*log10(abs(fftshift(fft(w,NFFT))));
subplot(211);
plot(f,W,'LineWidth',2); hold on;
subplot(212);
plot(f,X,'LineWidth',2); hold on;

w = hamming(2*N+1);
X = 20*log10(abs(fftshift(fft(x.*w,NFFT))));
W = 20*log10(abs(fftshift(fft(w,NFFT))));
subplot(211);
plot(f,W,'LineWidth',2); hold off; ylim([-80 30]);
grid on;
subplot(212);
plot(f,X,'LineWidth',2); hold off; ylim([-80 30]);
grid on;

xlabel('Frequency [Cycles/Sample]','FontSize',16);
shg;
