







































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








































































Name: SOLUTION
Section:
7.1 DESIGN OF IIR FILTERS
Project 7.1 Estimation of IIR Filter Order
Answers:
From the problem statement of Q7.1, we have FT = 40 kHz, Fp = 4 kHz, Fs =8 kHz,
Rp = 0.5 dB,and Rs =40 dB.
Q7.1 The normalized passband edge angular frequency Wp is –
3
3
p p T
π π^ × π ω = = = = π ×
Wp= = =
The normalized stopband edge angular frequency Ws is –
3
3
s s T
π π^ × π ω = = = = π ×
s 0.
Ws= = =
The desired passband ripple Rp is - 0.5 dB
The desired stopband ripple Rs is – 40 dB
(1) Using these values and buttord we get the lowest order for a Butterworth lowpass filter
to be – the correct call is [N, Wn] = buttord(0.2,0.4,0.5,40). This gives
(2) Using these values and cheb1ord we get the lowest order for a Type 1 Chebyshev
lowpass filter to be - the correct call is
[N, Wn] = cheb1ord(0.2,0.4,0.5,40). This gives N=5.
(3) Using these values and cheb2ord we get the lowest order for a Type 2 Chebyshev
lowpass filter to be - the correct call is
[N, Wn] = cheb2ord(0.2,0.4,0.5,40). This gives N=5.
The corresponding normalized passband edge frequency Wn is - 0.4000, or ω n =0.4000. π
(4) Using these values and ellipord we get the lowest order for an elliptic lowpass filter to
be - the correct call is [N, Wn] = ellipord(0.2,0.4,0.5,40). This gives
N=4 and Wn = 0.2000 or ω n = 0.2000π.
From the above results we observe that the Elliptic filter has the lowest order meeting the
specifications.
Q7.2 The normalized passband edge angular frequency Wp is –
3
3
p p T
π π^ × π ω = = = = π ×
Wp= = =
The normalized stopband edge angular frequency Ws is –
3
3
s s T
π^ π^ × ω = = = π ×
s 0.
Ws= = =
The desired passband ripple Rp is – 1.0 dB.
The desired stopband ripple Rs is – 50 dB.
(1) Using these values and buttord we get the lowest order for a Butterworth highpass filter
to be – the correct call is [N, Wn] = buttord(Wp,Ws,Rp,Rs). This gives
The corresponding normalized passband edge frequency Wn is – Wn = 0.5646, or
(2) Using these values and cheb1ord we get the lowest order for a Type 1 Chebyshev
highpass filter to be – the correct call is [N,Wn] = cheb1ord(Wp,Ws,Rp,Rs).
This gives N=5.
Ws2= = =
Ws = [Ws1 Ws2] = [0.3000 0.7000]
The desired passband ripple Rp is – 0.4 dB.
The desired stopband ripple Rs is – 50 dB.
(1) Using these values and buttord we get the lowest order for a Butterworth bandpass
filter to be – the correct call is [N,Wn] = buttord(Wp,Ws,Rp,Rs) =
buttord([0.4000 0.6000],[0.3000 0.7000],0.4,50), which gives
Order = 2N = 18.
The corresponding normalized passband edge frequency Wn is –
Wn = [0.3835 0.6165], or
(2) Using these values and cheb1ord we get the lowest order for a Type 1 Chebyshev
bandpass filter to be – the correct call is [N,Wn] = cheb1ord(Wp,Ws,Rp,Rs) =
cheb1ord([0.40000 0.6000],[0.3000 0.7000],0.4,50), which gives
Order = 2N = 12.
The corresponding normalized passband edge frequency Wn is –
Wn = [0.4000 0.6000], or
(3) Using these values and cheb2ord we get the lowest order for a Type 2 Chebyshev
bandpass filter to be – the correct call is [N,Wn] = cheb2ord(Wp,Ws,Rp,Rs) =
cheb2ord([0.4000 0.6000],[0.3000 0.7000],0.4,50), which gives
Order = 2N = 12.
The corresponding normalized passband edge frequency Wn is –
Wn = [0.3000 0.7000], or
(4) Using these values and ellipord we get the lowest order for an elliptic bandpass filter
to be – the correct call is [N,Wn] = ellipord(Wp,Ws,Rp,Rs) =
ellipord([0.4000 0.6000],[0.3000 0.7000],0.4,50), which gives
Order = 2N = 8.
The corresponding normalized passband edge frequency Wn is –
Wn = [0.4000 0.6000], or
From the above results we observe that the Elliptic filter has the lowest order meeting the
specifications.
Q7.4 The normalized passband edge angular frequency Wp is –
3 , ,1 (^3)
p p
π π × ω = = = π ×
p
Wp1= = =
3
3
, ,
p p
π π × ω = = = π ×
Wp2= = =
Wp = [Wp1 Wp2] = [0.3500 0.7500]
The normalized stopband edge angular frequency Ws is –
3 , ,1 (^3)
s s
π^ π^ × ω = = = π ×
Ws1= = =
3
3
, ,
s s
π π × ω = = = π ×
Ws2= = =
Ws = [Ws1 Ws2] = [0.4500 0.6500]
The desired passband ripple Rp is – Rp = 0.6 dB.
The desired stopband ripple Rs is – Rs = 45 dB.
From the above results we observe that the Elliptic filter has the lowest order meeting the
specifications.
Project 7.2 IIR Filter Design
A copy of Program P7_1 is given below:
% Program P7_
% Design of a Butterworth Bandstop Digital Filter
Ws = [0.4 0.6]; Wp = [0.2 0.8]; Rp = 0.4; Rs = 50; % Estimate the Filter Order
[N1, Wn1] = buttord(Wp, Ws, Rp, Rs);
% Design the Filter
[num,den] = butter(N1,Wn1,'stop'); % Display the transfer function
disp('Numerator Coefficients are ');disp(num);
disp('Denominator Coefficients are ');disp(den);
% Compute the gain response [g, w] = gain(num,den);
% Plot the gain response
plot(w/pi,g);grid
axis([0 1 -60 5]); xlabel('\omega /\pi'); ylabel('Gain in dB');
title('Gain Response of a Butterworth Bandstop Filter');
Answers:
Q7.5 The coefficients of the Butterworth bandstop transfer function generated by running Program
P7_1 are as follows:
Numerator Coefficients are
Columns 1 through 9 0.0493 0.0000 0.2465 0.0000 0.4930 0.0000 0.4930 0.0000 0.
Columns 10 through 11
0.0 0.
Denominator Coefficients are
Columns 1 through 9
1.0000 0.0000 -0.0850 0.0000 0.6360 0.0000 -0.0288 0.0000 0.
Columns 10 through 11
0.0000 -0.
The exact expression for the transfer function is – 2 4 6 8 10
2 4 6 8 10
z z z z z H z z z z z z
− − − − −
− − − − −
The filter specifications are: ω p 1 = 0.2π , ω s 1 = 0.4π , ω s 2 = 0.6π , ω (^) p 2 = 0.8π ,
Rp = 0.4 dB,and Rs =50 dB.
The gain response of the filter as designed is given below:
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
ω /π
Gain in dB
Gain Response of a Butterworth Bandstop Filter
From the plot we conclude that the design MEETS the specifications.
The plot of the unwrapped phase response and the group delay response of this filter is given
below:
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
3
4
5
6
7
8
9
10
ω /π
Group Delay (sec)
Group Delay of a Butterworth Bandstop Filter
Here is the modified version of Program P7_1 to answer Q7.6:
% Program Q7_
% Design of a Chebyshev Type 1 Lowpass Digital Filter
% meeting the design specification given in Q7.1. % - Print out the numerator and denominator coefficients
% for the transfer function.
% - Compute and plot the gain function.
% - Compute and plot the unwrapped phase response. % - Compute and plot the group delay.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Design spec as given in Q7.1.
FT = 4010^3; % sampling freq Fp = 410^3; % analog passband edge freq
Fs = 8*10^3; % analog stopband edge freq
Rp = 0.5; % max passband ripple, dB
Rs = 40; % min stopband attenuation, dB % Convert spec to normalized digital frequencies
omega_p = 2piFp/FT;
Wp = 2*Fp/FT; % omega_p/pi
omega_s = 2piFs/FT; Ws = 2*Fs/FT; % omega_s/pi
% Estimate the Filter Order
[N, Wn] = cheb1ord(Wp, Ws, Rp, Rs); % Design the Filter
[num,den] = cheby1(N,Rp,Wn);
% Display the transfer function
disp('Numerator Coefficients are ');disp(num); disp('Denominator Coefficients are ');disp(den);
% Compute the gain response
[g, w] = gain(num,den);
% Plot the gain response figure(1);
plot(w/pi,g);grid;
axis([0 1 -60 5]);
xlabel('\omega /\pi'); ylabel('Gain in dB'); title('Gain Response of a Type 1 Chebyshev Lowpass Filter');
% Find and plot the phase
figure(2);
w2 = 0:pi/511:pi; Hz = freqz(num,den,w2);
Phase = unwrap(angle(Hz));
plot(w2/pi,Phase);grid;
xlabel('\omega /\pi'); ylabel('Unwrapped Phase (rad)'); title('Unwrapped Phase Response of a Type 1 Chebyshev Lowpass Filter');
% Find and plot the group delay
figure(3);
GR = grpdelay(num,den,w2); plot(w2/pi,GR);grid;
xlabel('\omega /\pi'); ylabel('Group Delay (sec)');
title('Group Delay of a Type 1 Chebyshev Lowpass Filter');
The plot of the unwrapped phase response and the group delay response of this filter is given below:
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
ω /π
Unwrapped Phase (rad)
Unwrapped Phase Response of a Type 1 Chebyshev Lowpass Filter
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
5
10
15
20
ω /π
Group Delay (sec)
Group Delay of a Type 1 Chebyshev Lowpass Filter
Here is the modified version of Program P7_1 for answering question Q7.7:
% Program Q7_ % Design of a Chebyshev Type 2 Highpass Digital Filter
% meeting the design specification given in Q7.2.
% - Print out the numerator and denominator coefficients
% for the transfer function. % - Compute and plot the gain function.
% - Compute and plot the unwrapped phase response.
% - Compute and plot the group delay.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Design spec as given in Q7.2.
FT = 3.50*10^3; % sampling freq
Fp = 1.05*10^3; % analog passband edge freq
Fs = 0.60*10^3; % analog stopband edge freq Rp = 1.0; % max passband ripple, dB
Rs = 50; % min stopband attenuation, dB
% Convert spec to normalized digital frequencies
omega_p = 2piFp/FT; Wp = 2*Fp/FT; % omega_p/pi
omega_s = 2piFs/FT;
Ws = 2*Fs/FT; % omega_s/pi
% Estimate the Filter Order [N, Wn] = cheb2ord(Wp, Ws, Rp, Rs);
% Design the Filter
[num,den] = cheby2(N,Rs,Wn,'high'); % Display the transfer function
disp('Numerator Coefficients are ');disp(num);
disp('Denominator Coefficients are ');disp(den);
% Compute the gain response [g, w] = gain(num,den);
% Plot the gain response
figure(1);
axis([0 1 -60 5]); % Add lines to the plot to help determine if the spec was met.
hold on;
tmpY = -60:65/511:5;
tmpX = ones(1,length(tmpY))*Wp; plot(tmpX,tmpY,'r-'); % vertical line at passband edge freq
tmpX = ones(1,length(tmpY))*Ws;
plot(tmpX,tmpY,'g-'); % vertical line at stopband edge freq
tmpY = ones(1,length(w))*(-Rp); plot(w/pi,tmpY,'r-'); % horizontal line at Rp
tmpY = ones(1,length(w))*(-Rs);
plot(w/pi,tmpY,'g-'); % horizontal line at Rs
% now plot the gain plot(w/pi,g);grid;
xlabel('\omega /\pi'); ylabel('Gain in dB');
title('Gain Response of a Type 2 Chebyshev Highpass Filter');
hold off; % Find and plot the phase
figure(2);
w2 = 0:pi/511:pi; Hz = freqz(num,den,w2);
Phase = unwrap(angle(Hz));
plot(w2/pi,Phase);grid;
xlabel('\omega /\pi'); ylabel('Unwrapped Phase (rad)'); title('Unwrapped Phase Response of a Type 2 Chebyshev Highpass Filter');
The plot of the unwrapped phase response and the group delay response of this filter is given below:
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
1
2
3
4
5
6
7
ω /π
Unwrapped Phase (rad)
Unwrapped Phase Response of a Type 2 Chebyshev Highpass Filter
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
1
2
3
4
5
6
ω /π
Group Delay (sec)
Group Delay of a Type 2 Chebyshev Highpass Filter
Here is the modified version of Program P7_1 for answering question Q7.8:
% Program Q7_
% Design of an Elliptic Bandpass Digital Filter
% meeting the design specification given in Q7.3.
% - Print out the numerator and denominator coefficients % for the transfer function.
% - Compute and plot the gain function.
% - Compute and plot the unwrapped phase response.
% - Compute and plot the group delay. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Design spec as given in Q7.3.
FT = 7.0010^3; % sampling freq Fp1 = 1.410^3; % analog lower passband edge freq
Fp2 = 2.1*10^3; % analog upper passband edge freq
Fs1 = 1.05*10^3; % analog lower stopband edge freq
Fs2 = 2.45*10^3; % analog upper stopband edge freq Rp = 0.4; % max passband ripple, dB
Rs = 50; % min stopband attenuation, dB
% Convert spec to normalized digital frequencies
omega_p1 = 2piFp1/FT; Wp1 = 2*Fp1/FT; % omega_p1/pi
omega_p2 = 2piFp2/FT;
Wp2 = 2*Fp2/FT; % omega_p2/pi
Wp = [Wp1 Wp2]; omega_s1 = 2piFs1/FT;
Ws1 = 2*Fs1/FT; % omega_s1/pi
omega_s2 = 2piFs2/FT;
Ws2 = 2*Fs2/FT; % omega_s2/pi Ws = [Ws1 Ws2];
% Estimate the Filter Order
[N, Wn] = ellipord(Wp, Ws, Rp, Rs);
% Design the Filter [num,den] = ellip(N,Rp,Rs,Wn);
% Display the transfer function
disp('Numerator Coefficients are ');disp(num); disp('Denominator Coefficients are ');disp(den);
% Compute the gain response
[g, w] = gain(num,den);
% Plot the gain response figure(1);
axis([0 1 -60 5]);
% Add lines to the plot to help determine if the spec was met.
hold on; tmpY = -60:65/511:5;
tmpX = ones(1,length(tmpY))*Wp1;
plot(tmpX,tmpY,'r-'); % vertical line at passband edge freq
tmpX = ones(1,length(tmpY))*Wp2; plot(tmpX,tmpY,'r-'); % vertical line at passband edge freq
tmpX = ones(1,length(tmpY))*Ws1;
plot(tmpX,tmpY,'g-'); % vertical line at stopband edge freq
tmpX = ones(1,length(tmpY))*Ws2; plot(tmpX,tmpY,'g-'); % vertical line at stopband edge freq
tmpY = ones(1,length(w))*(-Rp);
plot(w/pi,tmpY,'r-'); % horizontal line at Rp
tmpY = ones(1,length(w))*(-Rs); plot(w/pi,tmpY,'g-'); % horizontal line at Rs
% now plot the gain
plot(w/pi,g);grid;
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
ω /π
Gain in dB
Gain Response of an Elliptic Bandpass Filter
From the plot we conclude that the design MEETS the specifications.
The plot of the unwrapped phase response and the group delay response of this filter is given
below:
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
2
4
6
ω /π
Unwrapped Phase (rad)
Unwrapped Phase Response of an Elliptic Bandpass Filter
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
5
10
15
20
25
ω /π
Group Delay (sec)
Group Delay of an Elliptic Bandpass Filter
7.2 DESIGN OF FIR FILTERS
Project 7.3 Gibb's Phenomenon
Answers:
Q7.9 The MATLAB program generating the impulse response, truncated to 81 samples, of a zero-
phase ideal lowpass filter with a cutoff at ωc = 0.4π and plotting its magnitude response is
given below: NOTE: this program does all four lengths.
% Program Q7_ % Investigate Gibbs phenomena for a FIR lowpass filter as
% asked for in Q7.9.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n = -40:40; % this gives us a length of 81 hn_81 = 0.4 * sinc(0.4*n); % the length-81 impulse response
omega = 0:pi/1023:pi; % radian frequency vector
W = omega/pi; % Matlab normalized freq vector
Hz_81 = abs(freqz(hn_81,1,omega)); % 1024 samles of |H(e^jw)| figure(1);
plot(W,Hz_81); grid;
xlabel('\omega /\pi'); ylabel('|H(e^{j\omega})|');
title('Magnitude Response for Length=81'); % Reduce length to 61 and repeat
hn_61 = hn_81(11:71);