%% Freq resp of FIR filter
% number of points in FIR filter is M+1
M=16;
% cutoff frequency of lowpass
wc=pi/4;
% freq vector
w=[-pi:0.01:pi]';
% FR computation using cosine formula
Hjw=(wc/pi)*ones(length(w),1);
for k=0:M/2-1
   Hjw=Hjw+2*sin((k-M/2)*wc)/((k-M/2)*pi)*(0.54+0.46*cos(2*pi*(k-M/2)/M))*cos(w*(M/2-k));
end
% Ideal lowpass
Hlp=zeros(length(w),1);
for k=1:length(w)
 if (abs(w(k)) < wc)
    Hlp(k)=1;
 end
end
%plot frequency response
plot(w,abs(Hjw),w,Hlp);
