bartlett(20)
plot(abs(fft(ans)))
% do a low pass filter with a Bartlett window
Omega_c = pi/2;
k = 0:(2*N);
N = 20;
k = 0:(2*N);
h = Omega_c / pi * sinc((k-N)*Omega_c / pi);
h = h .* bartlett(N);
winc = 2*pi/length(h);
plot(0:winc:(2*pi-winc),abs(fft(h)))
% now let's compare bartlett to rectangular and ideal
h_bartlett = h;
h = Omega_c / pi * sinc((k-N)*Omega_c / pi);
h_rect = h;
plot(0:winc:(2*pi-winc),abs(fft(h_bartlett)), 0:winc:(2*pi-winc),abs(fft(h_rect)))
h_ideal = ((0:winc:(2*pi-winc)) <= (pi/2));
plot(0:winc:(2*pi-winc),abs(fft(h_bartlett)), 0:winc:(2*pi-winc),abs(fft(h_rect)),0:winc:(2*pi-winc),h_ideal)
plot(hamming(20))
plot(0:40,hamming(20),0:40,bartlett(20))
plot(0:winc:(2*pi-winc),abs(fft(h_bartlett)), 0:winc:(2*pi-winc),abs(fft(h_rect)),0:winc:(2*pi-winc),h_ideal)
% now let's compare bartlett, hamming, rectangular, and ideal
h = Omega_c / pi * sinc((k-N)*Omega_c / pi);
h = h .* hamming(N);
clf
hold on
plot(0:winc:(2*pi-winc),h_ideal,'b-')
plot(0:winc:(2*pi-winc),abs(fft(h_bartlett)),'g-')
plot(0:winc:(2*pi-winc),abs(fft(h_rect)),'r-')
plot(0:winc:(2*pi-winc),abs(fft(h_hamming)),'k--')
% blue = ideal, green = bartlett, red = rectangle, black dash = hamming
