0% found this document useful (0 votes)
5 views

DSP Lab Spring 23 Exp-12

The document is a laboratory manual for IIR filter design in a Digital Signal Processing course at the National University of Computer and Emerging Sciences, Islamabad. It outlines the learning objectives, required equipment, and provides detailed explanations of IIR filter basics, design methods using Butterworth and Chebyshev analog filters, and relevant MATLAB functions for implementation. The manual serves as a guide for students to understand the design and application of digital filters in signal processing.

Uploaded by

fakhar_fast
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

DSP Lab Spring 23 Exp-12

The document is a laboratory manual for IIR filter design in a Digital Signal Processing course at the National University of Computer and Emerging Sciences, Islamabad. It outlines the learning objectives, required equipment, and provides detailed explanations of IIR filter basics, design methods using Butterworth and Chebyshev analog filters, and relevant MATLAB functions for implementation. The manual serves as a guide for students to understand the design and application of digital filters in signal processing.

Uploaded by

fakhar_fast
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

DIGITAL SIGNAL PROCESSING LAB

(EL-3031)
LABORATORY MANUAL

IIR Filter Design

(LAB # 12)
Student Name: ______________________________________________

Roll No: ________________ Section: ____

Date performed: _____________, 2023

____________________________________________________________________________________________________________________________________________________________

NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES, ISLAMABAD

Prepared by: Engr. Muhammad Asim


Last Edited by: Engr. Muhammad Asim, Mar 29, 2016
Verified by: Dr. Shahzad Saleem, Dr. Farhan Khalid Updated: Spring 2023
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________
Lab # 12: IIR Filter Design
Learning Objectives
a. To design IIR digital filter using Butterworth analog filter
b. To design IIR digital filter using Chebyshev (Type I and II) analog filter
Equipment Required
1. PC
2. Matlab
1. Introduction
Filters are frequency selective network and are used for signal separation and restoration.
Filters can be classified into:
Analog filters- Realized by R, C and active devices, they are cheap, fast and large dynamic range, but
poor performance.
Digital filters- Realized by digital system like memory, adder and multipliers; they have better
performance in low frequency as well as high frequency operation.
There are two types of filters: IIR (Infinite Impulse Response) and FIR (Finite Impulse Response)
Ideal frequency response of filters:

_____________________________________________________________________________________________
Page 2 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________

Practical frequency response of filters:

Ideal frequency response of digital filters:

a. IIR Filter Basics:


IIR digital filters which can be realized and characterized by the recursive equation,

where h[k] is the impulse response of the filter, bk and ak are the filter coefficients of the filter,
and x[n] and y[n] are the input and output to the filter. The transfer function for the IIR filter is,

_____________________________________________________________________________________________
Page 3 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________

The transfer function of the IIR filter, H(z) can be represented as

Where K is the gain, z1, z2 ….are the zeros and p1, p2 ….are the poles of the transfer function,
H(z).

b. IIR filter design through analog filters:


IIR filters are generally designed by first designing its analog counterparts and then
transforming it to digital filters. This method is preferred as analog filter design procedures like
Butterworth and Chebyshev.
In case of IIR filter design, the most common practice is to convert the digital filter
specifications into analog low pass prototype filter specifications. Then to transform it into the
desired digital filter transfer function H(z) by
a) Impulse invariant.
b) Bilinear transformation.
Here we will consider only Bilinear Transformation.

Bilinear Transformation
Bilinear transformation is much more important and useful than Impulse Invariant
Transformation method, especially in high pass, band pass and stop filters. The method is
derived by approximating the first order differential equation with a difference equation.
This transformation maps the analog transfer function, H(s) from the s-plane onto the
discrete transfer function, H(z) in the z-plane. The entire jΩ axis in the s-plane is mapped
onto the z-plane. The left half s-plane is mapped inside the unit circle and the right half s-
plane is mapped outside the unit circle in the z-plane.

The mapping formulae is

Relation between Analog and Digital Frequencies:

MATLAB Functions:
BILINEAR Bilinear transformation with optional frequency prewarping.
[Zd,Pd,Kd] = BILINEAR(Z,P,K,Fs) converts the s-domain transfer function specified by Z, P, and
K to a z-transform discrete equivalent obtained from the bilinear transformation: where column
_____________________________________________________________________________________________
Page 4 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________
vectors Z and P specify the zeros and poles, scalar K specifies the gain, and Fs is the sample
frequency in Hz.
[NUMd,DENd] = BILINEAR(NUM,DEN,Fs), where NUM and DEN are row vectors containing
numerator and denominator transfer function coefficients, NUM(s)/DEN(s),
in descending powers of s, transforms to z-transform coefficients NUMd(z)/DENd(z).

c. Butterworth Approximation
The magnitude response of a practical low pass filter, Where δ is gain and ω is frequency
in radians/sec

The magnitude response of Butterworth low pass filter,

The low pass Butterworth filter is characterized by the following magnitude squared
magnitude response,

where N is the order of the filter, Ω is analog frequency in radians; ΩC is 3dB cut-off
frequency in radians.

_____________________________________________________________________________________________
Page 5 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________

The advantage of this approximation is flat response over stop band and pass band. The
disadvantage is wide transition band.
The transfer function of the filter is:
For N is even

For N is odd

The coefficients bk and ck are given by

and ck=1
The parameter Bk can be obtained from:
for N is even

for N is odd

MATLAB functions:
1) BUTTORD Butterworth filter order selection.
[N, Wn] = BUTTORD(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital
Butterworth filter that loses no more than Rp dB in the passband and has at least Rs dB
of attenuation in the stopband.
Wp and Ws are the passband and stopband edge frequencies normalized from 0 to 1
(where 1 corresponds to pi radians/sample). For example,
Lowpass: Wp = .1, Ws = .2
Highpass: Wp = .2, Ws = .1
_____________________________________________________________________________________________
Page 6 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________
Bandpass: Wp = [.2 .7], Ws = [.1 .8]
Bandstop: Wp = [.1 .8], Ws = [.2 .7]
BUTTORD also returns Wn, the Butterworth natural frequency (or, the "3 dB frequency")
to use with BUTTER to achieve the specifications.
[N, Wn] = BUTTORD(Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in
which case Wp and Ws are in radians/second.
When Rp is chosen as 3 dB, the Wn in BUTTER is equal to Wp in BUTTORD.

2) BUTTER Butterworth digital and analog filter design.


[B,A] = BUTTER(N,Wn) designs an Nth order lowpass digital Butterworth filter and
returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator).
The coefficients are listed in descending powers of z. The cutoff frequency Wn must be 0.0
< Wn < 1.0, with 1.0 corresponding to half the sample rate.
If Wn is a two-element vector, Wn = [W1 W2], BUTTER returns an order 2N bandpass
filter with passband W1 < W < W2.
[B,A] = BUTTER(N,Wn,'high') designs a highpass filter.
[B,A] = BUTTER(N,Wn,'low') designs a lowpass filter.
[B,A] = BUTTER(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2].
When used with three left-hand arguments, as in [Z,P,K] = BUTTER(...), the zeros and poles are
returned in length N column vectors Z and P, and the gain in scalar K.BUTTER(N,Wn,'s'),
BUTTER(N,Wn,'high','s') and BUTTER(N,Wn,'stop','s') design analog Butterworth filters. In this
case, Wn is in [rad/s] and it can be greater than 1.0.

d. Chebyshev Approximation
The Butterworth approximation, which is monotonic in both the pass band and stopband, gives
us a magnitude response which exceeds the specifications for the pass band ripple. The
problem is that the order of the filter will be high. Usually, we can tolerate some amount of
ripple, and it would be advantageous to have a trade-off between the ripple and the filter order,
so that we can obtain a filter which meets the specifications and has a lower order than its
Butterworth counterpart. For this we use the Chebychev approximation. The characteristic of
Chebyshev approximation is that it minimizes the error between the idealized and the actual
filter over the range of filter allowing some ripples in pass band.
 Type I, with equal ripple in the pass band, monotonic in the stop band.
 Type II, with equal ripple in the stop band, monotonic in the pass band

Magnitude response of Type-I filter:

Magnitude response of Type-II filters:

_____________________________________________________________________________________________
Page 7 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________

Type I Chebyshev Filter is characterized by the magnitude squared response is given by

Where is a Chebyshev polynomial which exhibits equal ripple in the pass band, N is the
order of the polynomial as well as that of the filter, and ɛ determines the pass band ripple, which in
decibels is given by,
Chebyshev polynomial is given by

The expression for filter parameter ɛ is given by

The order of the filter

Assume

The transfer function H(s) is similar to Butterworth filter, but the coefficients bk and ck is given by

The parameter yN is given by

The parameter Bk can be obtained from:


For N is even

_____________________________________________________________________________________________
Page 8 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________
For N is odd

Type II Chebyshev Filter is characterized by the magnitude squared response is given by

Chebyshev polynomial is give as Type-II


The filter parameter ɛ is given by

The order N of the filter

All other parameters are similar to Type-I filter.


MATLAB functions:
1) CHEB1ORD Chebyshev Type I filter order selection.
[N, Wp] = CHEB1ORD(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital
Chebyshev Type I filter that loses no more than Rp dB in the passband and has at leastRs dB of attenuation
in the stopband. Wp and Ws are the passband and stopband edgefrequencies normalized from 0 to 1 (where 1
corresponds to pi radians/sample). For example,
Lowpass: Wp = .1, Ws = .2
Highpass: Wp = .2, Ws = .1
Bandpass: Wp = [.2 .7], Ws = [.1 .8]
Bandstop: Wp = [.1 .8], Ws = [.2 .7]
CHEB1ORD also returns Wp, the Chebyshev natural frequency to use with CHEBY1 to achieve the
specifications.
[N, Wp] = CHEB1ORD(Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in which case Wp
and Ws are in radians/second.

2) CHEB2ORD Chebyshev Type II filter order selection.


[N, Ws] = CHEB2ORD(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital
Chebyshev Type II filter that loses no more than Rp dB in the passband and has at least Rs dB of attenuation
in the stopband. Wp and Ws are the passband and stopband edge frequencies normalized from 0 to 1 (where
1 corresponds to pi radians/sample). For example,
Lowpass: Wp = .1, Ws = .2
Highpass: Wp = .2, Ws = .1
Bandpass: Wp = [.2 .7], Ws = [.1 .8]
Bandstop: Wp = [.1 .8], Ws = [.2 .7]
CHEB2ORD also returns Wst, the Chebyshev natural frequency to use with CHEBY2 to achieve the
specifications.
[N, Ws] = CHEB2ORD(Wp, Ws, Rp, Rs, 's') does the computation for an analog filter,
_____________________________________________________________________________________________
Page 9 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________
in which case Wp and Ws are in radians/second.

3) CHEBY1 Chebyshev Type I digital and analog filter design.


[B,A] = CHEBY1(N,R,Wp) designs an Nth order lowpass digital Chebyshev filter with R decibels of peak-to-
peak ripple in the passband. CHEBY1 returns the filter coefficients in length N+1 vectors B (numerator) and
A (denominator). The passband-edge frequency Wp must be 0.0 < Wp < 1.0, with 1.0 corresponding to half
the sample rate.
Use R=0.5 as a starting point, if you are unsure about choosing R.
If Wp is a two-element vector, Wp = [W1 W2], CHEBY1 returns an order 2N bandpass filter with passband
W1 < W < W2.
[B,A] = CHEBY1(N,R,Wp,'high') designs a highpass filter.
[B,A] = CHEBY1(N,R,Wp,'low') designs a lowpass filter.
[B,A] = CHEBY1(N,R,Wp,'stop') is a bandstop filter if Wp = [W1 W2].
When used with three left-hand arguments, as in [Z,P,K] = CHEBY1(...), the zeros and poles are returned in
length N column vectors Z and P, and the gain in scalar K.
CHEBY1(N,R,Wp,'s'), CHEBY1(N,R,Wp,'high','s') and CHEBY1(N,R,Wp,'stop','s') design analog Chebyshev
Type I filters. In this case, Wp is in [rad/s] and it can be greater than 1.0.

4) CHEBY2 Chebyshev Type II digital and analog filter design.


[B,A] = CHEBY2(N,R,Wst) designs an Nth order lowpass digital Chebyshev filter with the stopband ripple
R decibels down and stopband-edge frequency Wst. CHEBY2 returns the filter coefficients in length
N+1vectors B (numerator) and A (denominator).
The stopband-edge frequency Wst must be 0.0 < Wst < 1.0, with 1.0 corresponding to half the sample rate.
Use R = 20 as a starting point, if you are unsure about choosing R.
If Wst is a two-element vector, Wst = [W1 W2], CHEBY2 returns an order 2N bandpass filter with passband
W1 < W < W2.
[B,A] = CHEBY2(N,R,Wst,'high') designs a highpass filter.
[B,A] = CHEBY2(N,R,Wst,'low') designs a lowpass filter.
[B,A] = CHEBY2(N,R,Wst,'stop') is a bandstop filter if Wst = [W1 W2].
When used with three left-hand arguments, as in [Z,P,K] = CHEBY2(...), the zeros and poles are returned in
length N column vectors Z and P, and the gain in scalar K.
CHEBY2(N,R,Wst,'s'), CHEBY2(N,R,Wst,'high','s') and CHEBY2(N,R,Wst,'stop','s') design analog Chebyshev
Type II filters. In this case, Wst is in [rad/s] and it can be greater than 1.0.

2. Procedure
Step1: Get the digital filter specifications ( δ p δ s ω p ωs )
Step2: Convert to analog filter specifications with bilinear transformation.
Step3: Design analog transfer function Ha(s)
2 1−z−1
Step4: Transfer Ha(s) to H(z) since s= T ( −1
)
1+ z

Analog Butterworth approximation


1. Start
2. Enter pass band ripple a1 and stop band ripple a2 in dB
3. Enter pass band edge and stop band edge frequencies (fp and fs) in Hz (or in nnormalized form
in radians)
4. Enter sampling frequency in samples/second
5. Check the entered values are correct
6. Normalize the frequencies and compute analog frequencies (Ωp and Ωs)

_____________________________________________________________________________________________
Page 10 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________
Find orders and cut-off frequencies of the analog filters using buttord( ) function and display the
values for verification
8. Compute the transfer functions in s-domain using butter( )
9. Transform the transfer functions to z-domain by impinvar( ) and bilinear( )
10. Compute the frequency responses of each type using freqz( ) function
11. Plot the each magnitude and phase responses
12. Stop
MATLAB
%Butterworth filter
clc;
clear all;
close all;
disp('IIR filter design using Butterworth Approximation');
%Inputs
ftype=input('Enter filter type (LPF, HPF, BPF or BSF): ');
switch ftype
case 'LPF'
fp=input('Enter pass band frequency fp in Hz ');
fs=input('Enter stop band frequency fs in Hz ');
%Error message
if fp<=0
error('Pass band edge must be larger than zero');
end
if fs<=fp
error('Stop band edge must be larger than pass band edge');
end
case 'HPF'
fp=input('Enter pass band frequency fp in Hz ');
fs=input('Enter stop band frequency fs in Hz ');
%Error message
if fs<=0
error('Pass band edge must be larger than 0');
end
if fs>=fp
error('Stop band edge must be smaller than pass band edge');
end
case 'BPF'
fs=input('Enter stop band frequencies fs1 and fs2 (fs2 >fs1) in Hz ');
fp=input('Enter pass band frequencies fp1 and fs2 (fp1 >fs1 and fp2<fp2) in Hz ');
if (fp(1) || fp(2))<=0
error('Pass band edge must be larger than 0');
end
if fp(1)<=fs(1)
error('Pass band edge must be larger than stop band edge');
end
if fp(2)>=fs(2)
error('Pass band edge must be smaller than stop band edge');
end
case 'BSF'
fs=input('Enter stop band frequencies fs1 and fs2 (fs2 >fs1) in Hz ');
fp=input('Enter pass band frequencies fp1 and fs2 (fp1 < fs1 and fp2 > fs2) in Hz ');
if (fs(1) || fs(2))<=0
error('Stop band edge must be larger than zero');
_____________________________________________________________________________________________
Page 11 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________
end
if fs(1)<=fp(1)
error('Stop band edge must be larger than pass band edge');
end
if fs(2)>=fp(2)
error('Stop band edge must be smaller than pass band edge');
end
end
Fs=input('Enter sampling frequency F in samples/sec ');
a1=input('Enter pass band ripple in dB ');
a2=input('Enter stop band ripple in dB ');
%conversion and normalization of frequencies
%pi radians/second
wp=2*fp/Fs;
ws=2*fs/Fs;
%conversion of frequency for transformation
trans=input('Enter transformation type (IIT or BT): ');
switch trans
case 'IIT'
%Analog frequencies by IIT
Wp=wp*Fs*pi;
Ws=ws*Fs*pi;
case 'BT'
%Analog frequencies by BT
Wp=2*Fs*tan(wp*pi/2);
Ws=2*Fs*tan(ws*pi/2);
end
%Order and cut-off frequencies of filter
[N,Wc]=buttord(Wp,Ws,a1,a2,'s');
%Analog Filter response
switch ftype
case 'LPF'
[b,a]=butter(N,Wc,'s');
case 'HPF'
[b,a]=butter(N,Wc,'high','s');
case 'BPF'
[b,a]=butter(N,Wc,'bandpass','s');
case 'BSF'
[b,a]=butter(N,Wc,'stop','s');
end
%Transformation, Digital filter response & Frequency response
switch trans
case 'IIT'
[bz,az]=impinvar(b,a,Fs);
[H,f]=freqz(bz,az,512,Fs);
case 'BT'
[bz,az]=bilinear(b,a,Fs);
[H,f]=freqz(bz,az,512,Fs);
end
%display N and H(z)
disp('Order of the filter is:');
disp(N);
disp('Filter coefficients are:');
disp('a');

_____________________________________________________________________________________________
Page 12 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________
disp(az);
disp('b');
disp(bz);
%Plotting responses
subplot(2,1,1);
plot(f,abs(H));
xlabel('f in Hz');
ylabel('|H(w)|');
title(['Magnitude response of IIR ',ftype,' filter with Butterworth approximation using ',trans]);
grid on;
subplot(2,1,2);
plot(f,angle(H));
xlabel('f in Hz');
ylabel('Phase of H(w)');
title(['Phase response of IIR ',ftype,' filter with Butterworth approximation using ',trans]);
grid on;

Analog Chebyshev approximation


1. Start
2. Enter pass band ripple a1 and stop band ripple a2 in dB
3. Enter pass band edge and stop band edge frequencies (fp and fs) in Hz (or in normalized form in
radians)
4. Enter sampling frequency in samples/second
5. Check the entered values are correct
6. Normalize the frequencies and compute analog frequencies (Ωp and Ωs)
7. Find orders and cut-off frequencies of the analog filters using cheb1ord( ) and cheb2ord( )
function and display the values for verification
8. Compute the transfer functions in s-domain using cheby1( ) and cheby2( )
9. Transform the transfer functions to z-domain by impinvar( ) and bilinear( )
10. Compute the frequency responses of each type using freqz( ) function
11. Plot the each magnitude and phase responses
12. Stop

MATLAB
%Chebychev filter
clc;
clear all;
close all;
disp('IIR filter design using Chebyshev Approximation');
%Inputs
ftype=input('Enter filter type (LPF, HPF, BPF or BSF): ');
switch ftype
case 'LPF'
fp=input('Enter pass band frequency fp in Hz ');
fs=input('Enter stop band frequency fs in Hz ');
%Error message
if fp<=0
error('Pass band edge must be larger than 0');
end
if fs<=fp
error('Stop band edge must be larger than pass band edge');
_____________________________________________________________________________________________
Page 13 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________
end
case 'HPF'
fp=input('Enter pass band frequency fp in Hz ');
fs=input('Enter stop band frequency fs in Hz ');
%Error message
if fs<=0
error('Pass band edge must be larger than 0');
end
if fs>=fp
error('Stop band edge must be smaller than pass band edge');
end
case 'BPF'
fs=input('Enter stop band frequencies fs1 and fs2 (fs2 >fs1) in Hz ');
fp=input('Enter pass band frequencies fp1 and fs2 (fp1 >fs1 and fp2<fp2) in Hz ');
if (fp(1) || fp(2))<=0
error('Pass band edge must be larger than 0');
end
if fp(1)<=fs(1)
error('Pass band edge must be larger than stop band edge');
end
if fp(2)>=fs(2)
error('Pass band edge must be smaller than stop band edge');
end
case 'BSF'
fs=input('Enter stop band frequencies fs1 and fs2 (fs2 >fs1) in Hz ');
fp=input('Enter pass band frequencies fp1 and fs2 (fp1 < fs1 and fp2 > fs2) in Hz ');
if (fs(1) || fs(2))<=0
error('Stop band edge must be larger than 0');
end
if fs(1)<=fp(1)
error('Stop band edge must be larger than pass band edge');
end
if fs(2)>=fp(2)
error('Stop band edge must be smaller than pass band edge');
end
end
Fs=input('Enter sampling frequency Fs in samples/sec ');
a1=input('Enter pass band ripple in dB ');
a2=input('Enter stop band ripple in dB ');
%conversion and normalization of frequencies
%pi radians/second
wp=2*fp/Fs;
ws=2*fs/Fs;
%conversion of frequency for transformation
trans=input('Enter transformation type (IIT or BT): ');
switch trans
case 'IIT'
%Analog frequencies by IIT
Wp=wp*Fs*pi;
Ws=ws*Fs*pi;
case 'BT'
%Analog frequencies by BT
Wp=2*Fs*tan(wp*pi/2);
Ws=2*Fs*tan(ws*pi/2);

_____________________________________________________________________________________________
Page 14 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________
end
%Cheby1 or Cheby2
type=input('Enter Chebyshev filter type (type-1 or type-2): ');
switch type
case 'type-1'
%Order and cut-off frequencies of filter
[N,Wc]=cheb1ord(Wp,Ws,a1,a2,'s');
switch ftype
case 'LPF' %Analog Filter response
[b,a]=cheby1(N,a1,Wc,'s');
case 'HPF'
[b,a]=cheby1(N,a1,Wc,'high','s');
case 'BPF'
[b,a]=cheby1(N,a1,Wc,'bandpass','s');
case 'BSF'
[b,a]=cheby1(N,a1,Wc,'stop','s');
end
case 'type-2'
%Order and cut-off frequencies of filter
[N,Wc]=cheb2ord(Wp,Ws,a1,a2,'s');
switch ftype
case 'LPF'
%Analog Filter response
[b,a]=cheby2(N,a2,Wc,'s');
case 'HPF'
[b,a]=cheby2(N,a2,Wc,'high','s');
case 'BPF'
[b,a]=cheby2(N,a2,Wc,'bandpass','s');
case 'BSF'
[b,a]=cheby2(N,a2,Wc,'stop','s');
end
end
%Transformation, Digital filter response & Frequency response
switch trans
case 'IIT'
[bz,az]=impinvar(b,a,Fs);
[H,f]=freqz(bz,az,512,Fs);
case 'BT'
[bz,az]=bilinear(b,a,Fs);
[H,f]=freqz(bz,az,512,Fs);
end
%display N and H(z)
disp('Order of the filter is:');
disp(N);
disp('Filter coefficients are:');
disp('a');
disp(az);
disp('b');
disp(bz);
%Plotting responses
subplot(2,1,1);
plot(f,20*log10(abs(H))); % Gain in dB
xlabel('f in Hz');
ylabel('|H(w)|');

_____________________________________________________________________________________________
Page 15 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________
title(['Magnitude response of IIR ',ftype,' filter with Chebyshev ',type,' approximation using
',trans]);
grid on;
subplot(2,1,2);
plot(f,angle(H));
xlabel('f in Hz');
ylabel('Phase of H(w)');
title(['Phase response of IIR ',ftype,' filter with Chebyshev ',type,' approximation using',trans]);

3. Exercise
Task#1 IIR Lowpass Filter Design:
Consider the low-pass discrete-time filter specification,
0.99≤|H(ejw)| ≤1.01 , |w|≤0.4π,
|H(ejw)| ≤0.001 , 0.6π ≤|w|≤ π
Design using MATLAB this low pass filter by butterworth, Chebyshev( I and II), elliptic
approximation. Plot the gain response, detailted plot of magnitude in pass-band and pole-zero
plot for each approximation.

Task#2 IIR bandpass Filter Design:


Consider the band-pass discrete time filter specification,
0.99≤|H(ejw)| ≤1.01 , 0.45 π≤|w|≤0.6π,
jw
|H(e )| ≤0.001 , 0 ≤|w|≤0.3 π, 0.75π ≤|w|≤ π

Design using MATLAB this band-pass filter by butterworth, Chebyshev( I and II), elliptic
approximation. Plot the gain response, detailted plot of magnitude in pass-band and pole-zero
plot for each approximation

Student's feedback: Purpose of feedback is to know the strengths and weaknesses of the system
for future improvements. This feedback is for the 'current lab session'. Circle your choice:

_____________________________________________________________________________________________
Page 16 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________
[-3 = Extremely Poor, -2 = Very Poor, -1 = Poor, 0 = Average, 1 = Good, 2 = Very Good, 3 = Excellent]:
The following table should describe your experience with:
S# Field Rating Describe in words if required
1 Overall Session -
-2 -1 0 1 2 3
3
2 Lab Instructor -
-2 -1 0 1 2 3
3
3 Lab Staff -
-2 -1 0 1 2 3
3
4 Equipment -
-2 -1 0 1 2 3
3
5 Atmosphere -
-2 -1 0 1 2 3
3

Any other valuable feedback: ______________________________________________________


______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Student's Signature: _________________________________


AWARDED

Correctness

Conclusion
Originality
of results

Initiative
Neatness
MARKS

Attitude

TOTAL

TOTAL 10 10 10 20 20 30 100

EARNED

Lab Instructor's Comments:________________________________________________________


______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

_____________________________________________________________________________________________
Page 17 of 18
DSP - Lab National University Roll No: __________
12

Lab #
of Computer and Emerging Sciences
(EL3031) Islamabad Spring 2023
_____________________________________________________________________________________

Lab Instructor's Signature: _________________________________

Assessment Rubric
LLO Statement Assessment Exemplary Proficient Developing Beginning Worst
Method (20%) (20%) (20%) (20%) Performance
(20%)
2 Design of finite- Practical Skill Able to attempt Able to attempt Able to attempt Able to attempt Able to attempt
impulse response Observation complete lab with 80% of the lab 60% of the lab 40% of the lab 20% of the lab
(FIR) and during proper tasks tasks tasks tasks
infinite-impulse experimentati labeling/explanatio
response (IIR) on & Lab n of results and
digital filters in Reports proper commenting
MATLAB. of the code

_____________________________________________________________________________________________
Page 18 of 18

You might also like