Omega_c = pi/4;
N = 10;
k = 0:(2*N)
h = (Omega_c / pi) * sinc((k - N)*Omega_c / pi);
stem(h)
stem(k,h)
% make sure you specify the correct x axis
% compare the above two plots to see the difference
plot(abs(fft(h)))
winc = 2*pi/length(h)
plot(0:winc:(2*pi-winc),abs(fft(h)))
% to make the cutoff sharper, use a longer window
% i.e. larger N
N = 20
k = 0:(2*N)
h = (Omega_c / pi) * sinc((k - N)*Omega_c / pi);
winc = 2*pi/length(h);
plot(0:winc:(2*pi-winc),abs(fft(h)))
plot(0:winc:(2*pi-winc),log10(abs(fft(h))))
plot(0:winc:(2*pi-winc),abs(fft(h)))
plot(0:winc:(2*pi-winc),log10(abs(fft(h))))
% you can use a semilog plot to show how much high frequencies are
% being suppressed - the linear plot doesn't show as well
% can we create a high pass filter?
stem(k,h)
% create the shifted delta function
delta = zeros(1,41);
delta
delta(20) = 1
% REMEMBER THAT MATLAB INDEXING STARTS AT 1 - so the above is wrong
delta = zeros(1,41);
delta(21) = 1; % this corresponds to k = 20
stem(k,delta)
h_highpass = delta - h;
stem(h_highpass)
stem(k,h_highpass)
plot(0:winc:(2*pi-winc),abs(fft(h_highpass)))
% example signal: square wave
z = [ones(1,8) zeros(1,8)];
z = [z z z z z z z z z z];
stem(z)
stem(conv(z,h_highpass))
stem(conv(z,h))
% start from scratch with a different N and Omega_c
N = 10;
Omega_c = pi/2;
k = 0:(2*N)
delta = zeros(1,2*N+1);
delta(N+1) = 1
stem(k,delta)
% note that the deta function is centered around N in the above plot
h = Omega_c/pi * sinc((k-N)*Omega_c/pi);
h_highpass = delta - h;
plot(0:winc:(2*pi-winc),abs(fft(h_highpass)))
winc = 2*pi/length(h);
plot(0:winc:(2*pi-winc),abs(fft(h_highpass)))
% remember that the discrete time fourier transform is periodic with period 2 pi
% to recover the fft from -pi to pi, use fftshift
plot((-1*pi):winc:(pi-winc),fftshift(abs(fft(h_highpass))))
% filter coefficients
stem(k,h_highpass)
stem(k,h)
plot(0:winc:(2*pi-winc),abs(fft(h_highpass)))
sum(h_highpass)
sum(h)
% to create a banddpass filter, we can cascade a lowpass and a highpass
% bandpass with low cutoff = pi/4, high cutoff = pi/2
% first create the hpf with cutoff pi/4
N = 20;
Omega_c = pi/4
k = 0:(2*N)
delta = zeros(1,41)l;
delta = zeros(1,41);
delta(21) = 1;
h = Omega_c/pi * sinc((k-N)*Omega_c/pi);
h_highpass = delta - h;
winc = 2*pi/length(h);
plot(0:winc:(2*pi-winc),abs(fft(h_highpass)))
% now create the lpf with cutoff pi/2
Omega_c = pi/2;
h = Omega_c/pi * sinc((k-N)*Omega_c/pi);
h_lowpass = h;
plot(0:winc:(2*pi-winc),abs(fft(h_lowpass)))
% finally, cascade the filters
h_bandpass = conv(h_lowpass,h_highpass)
stem(0:80,h_bandpass)
winc = 2*pi/length(h_bandpass);
plot(0:winc:(2*pi-winc),abs(fft(h_bandpass)))
plot((-pi):winc:(pi-winc),fftshift(abs(fft(h_bandpass))))
% second method: start with a LPF and shift it in frequency
Omega_CL = pi/4;
Omega_CH = pi/2;
Omega_C = (Omega_CH - Omega_CL)/2;
N
k
h = Omega_c/pi * sinc((k-N)*Omega_c/pi);
h_lowpass = h;
h_bandpass = h_lowpass .* cos((Omega_CH + Omega_CL)*k/2);
h_bandpass = h_lowpass .* cos((Omega_CH + Omega_CL)*(k-N)/2);
stem(k,h_bandpass)
winc = 2*pi/length(h_bandpass);
plot(0:winc:(2*pi-winc),abs(fft(h_bandpass)))
