% low pass filters
% pick a cutoff frequency of pi/4
Omega_c = pi/4
N = 10
k = 0:(2*N)
sinc
sinc(0.1)
% use sinc.m to provide the sinc function, if your matlab doesn't have it built in
h = (Omega_c / pi) * sinc((k-N)*Omega_c / pi);
h
h = (Omega_c / pi) * sinc((k-N)*Omega_c / pi);
h
plot(h)
stem(h)
stem(0:(2*N),h)
plot(fft(h))
plot(abs(fft(h)))
% the correct omega axis for the fft plot
winc = 2*pi/length(h)
plot(0:winc:(2*pi-winc),abs(fft(h)))
Omega_c
grid on
% z is going to be a square wave
z = [ones(1,8) zeros(1,8)]
z = [z z z z z z z z z z];
plot(z)
axis
axis([0 160 -1 2])
plot(abs(fft(z)))
wincz = 2*pi/length(z);
plot(0:wincz:(2*pi - wincz),abs(fft(z)))
hold on
plot(0:winc:(2*pi-winc),abs(fft(h)))
y = conv(z,h);
plot(y)
clf
% note: the above command clears the figure and turns hold off
y = conv(z,h);
plot(y)
% think about a cutoff frequency that would capture more than one sinusoid
clf
plot(0:wincz:(2*pi - wincz),abs(fft(z)))
% re-do the filter with Omega_c = 1.6
Omega_c = 1.6
h = (Omega_c / pi) * sinc((k-N)*Omega_c / pi);
plot(h)
stem(h)
plot(0:winc:(2*pi-winc),abs(fft(h)))
hold on
plot(0:wincz:(2*pi - wincz),abs(fft(z)))
clf
y = conv(z,h);
plot(y)
clf
% what happens when you change N?
plot(0:winc:(2*pi-winc),abs(fft(h)))
N2 = 20
k2 = 0:(2*N2)
h2 = (Omega_c / pi) * sinc((k2-N2)*Omega_c / pi);
clf
plot(0:winc:(2*pi-winc),abs(fft(h)))
hold on
winc2 = 2*pi/length(h2);
plot(0:winc2:(2*pi-winc2),abs(fft(h2)))
clf
stem(h)
stem(h2)
N3 = 5
k3 = 0:(2*N3)
h3 = (Omega_c / pi) * sinc((k3-N3)*Omega_c / pi);
winc3 = 2*pi/length(h3);
clf
plot(0:winc:(2*pi-winc),abs(fft(h)),0:winc2:(2*pi-winc2),abs(fft(h2)),0:winc3:(2*pi-winc3),abs(fft(h3)))
