Frequency Sampling
Objective
Objective of this experiment is to design a Low pass, High pass, band pass and Band stop filters using Frequency Sampling Technique and plot the magnitude and phase response of the filter for various values of N
Low Pass filter design
Let us first design a low pass filter for the cutoff frequency of 0.5*pi rad/sample of order 7. Observe the change in magnitude response by changing the Order N for various values.
CODE
N=7;
wc = 0.5*pi;
%Low pass Filter design
k =0:(2*pi/N):(2*pi);
k_valid = k <= wc;
k_index =find(k_valid ==1);
K=0:length(k_index)-1;
% Write the reset of the code below
H=exp(-1i*(N-1)*pi.*(K)/N);
for n=0:N-1
realpart=real(H(2:end).*exp(1i.*2*pi.*K(2:end)*n/N));
h1(n+1)=(1/N)*(H(1)+2.*sum(realpart));
end
subplot(211)
[H,W]=freqz(h1,1);
plot(W,abs(H));
set(gca,'XTick',0:pi/2:pi)
set(gca,'XTickLabel',{'0','\pi/2','\pi'})
xlabel('\omega')
ylabel('H(e^j^\omega)')
title('Magnitude Response')
grid on;
subplot(212)
plot(W,angle(H));
set(gca,'XTick',0:pi/2:pi)
set(gca,'XTickLabel',{'0','\pi/2','\pi'})
xlabel('\omega')
ylabel('\theta(e^j^\omega)')
title('Phase Response')
grid on;
% produce the graph as shown in the output section
OUTPUT
Now you should design the HP, BP and BS filters by modifying the above code accordingly