In: Electrical Engineering
Q7.1 The normalized passband edge angular frequency
Wp is - 0.2
The normalized stopband edge angular frequency Ws is -
0.4
The desired passband ripple Rp is - 0.5 dB
The desired stopband ripple Rs is - 40 dB
In Matlab:
Q7.X1 Design a fixed window FIR filter satisfying the specifications in Q7.1. Plot the magnitude and phase responses. Also include magnified plots of passband and stopband showing how well the filter satisfies the design specifications.
Code:
clc;close all;clear all;
Wp =0.2*pi
Ws =0.4*pi
Wc=(Wp+Ws)/2;
%To achieve the stop band attenuation 40 db, hamming window should
be selected.
N=(8*pi/(Ws-Wp));%from the main lobe width of hamming window
N=N+2;%correction in order for achieving 40db stop band
attenuation
wh=hamming(N+1)';
hd=fir1(N,Wc/pi);
h=hd.*wh
w=0:pi/1000:pi
H=freqz(h,1,w)
figure;
subplot(221)
plot(w/pi,20*log10(abs(H)),'LineWidth',3,'m')
xlabel('w X pi');grid;
ylabel('|H(exp(jw)|')
title('Magnitude response')
subplot(222)
plot(w/pi,angle(H),'LineWidth',3,'r')
xlabel('w X pi');grid;
ylabel('<H(exp(jw)>')
title('Phase response')
subplot(223)
plot(w/pi,20*log10(abs(H)),'LineWidth',3,'b')
xlabel('w X pi');grid;
ylabel('|H(exp(jw)|')
title('Magnitude response')
xlim([0.15,0.25])
ylim([-2 ,2])
subplot(224)
plot(w/pi,20*log10(abs(H)),'LineWidth',3,'g')
xlabel('w X pi');grid;
ylabel('|H(exp(jw)|')
title('Magnitude response')
xlim([0.4,0.5])
ylim([-100 -30])
%stop band attenuation achieved from the design
Hdb=20*log10(abs(H))
Sdb=Hdb(find(w==0.4*pi))
Pdb=Hdb(find(w==0.2*pi))
Command window:
Sdb = -39.074
Pdb = -0.10788