In: Electrical Engineering
Design a linear phase, minimum-length, band-pass FIR digital filter in MATLAB to meet the specifications listed below. Use Rectangular Windowing (MATLAB function: fir1)
pass-band frequencies: f_p1 = 0.35, f_p2 = 0.65
stop-band frequencies: f_s1 = 0.10, f_s2 = 0.80
pass-band tolerance: d_p <= 0.1
stop-band tolerance: d_s <= 0.1
I am attempting to learn more about MATLAB and I am having trouble with specific filter design and it would be helpful to have an example.
Script:
clc;close all;clear all;
%Pass band and stop band edge frequencies
ws1=0.1;wp1=0.35;wp2=0.65;ws2=0.8;
tranwidth = min((wp1-ws1),(ws2-wp2));
%Cut off frequencies
wc1=(wp1+ws1)/2;
wc2=(wp2+ws2)/2;
wc=[wc1 wc2];
%For rectangular window , main lobe width is 4pi/N
N=round(4*pi/tranwidth);
M=N+1;n=0:1:M-1;
%Impulse response
hd=fir1(M-1,wc,'bandpass');
wR=rectwin(M)';
h=hd.*wR;
%Frequency response
w=0:0.01*pi:pi;
[H,w]=freqz(h,[1],w);
figure;
subplot(221)
stem(n,h)
title('Impulse response h(n)')
xlabel('n');grid;
ylabel('h(n)')
subplot(222)
plot(w/pi,abs(H),'b')
title('Magnitude response |H(w)|')
xlabel('w/pi');grid;
ylabel('|H(exp(jw)|')
subplot(223)
plot(w/pi,20*log10(abs(H)),'r')
title('Magnitude response in db ')
xlabel('w/pi');grid;
ylabel('|H(exp(jw)| in db')
subplot(224)
plot(w/pi,angle(H),'b')
title('Phase response ')
xlabel('w/pi');grid;
ylabel('<H(exp(jw)>')