Sei sulla pagina 1di 11

FAKULTI TEKNOLOGI KEJURUTERAAN

ELEKTRIK DAN ELEKTRONIK


UNIVERSITI TEKNIKAL MALAYSIA MELAKA

DIGITAL SIGNAL PROCESSING

BEET3373 SEMESTER 1 SESI 2019/2020

LAB 3: INFINITE IMPULSE RESPONSE (IIR) FILTER DESIGN

NO. STUDENTS' NAME MATRIC. NO.

1.

2.

3.

PROGRAMME 3 BEEC / 3 BEET


SECTION /
GROUP
DATE

1.
NAME OF
INSTRUCTOR(S)
2.

EXAMINER’S COMMENT(S) TOTAL MARKS


FTK/JTKEK/BETT3373

Rev. Date Author(s) Description


No.
1. Izadora Binti Mustaffa 1. Update to new UTeM logo
1.0 30 JAN
2019 2. Update faculty's name
3. Change "course" to
"programme"
4. Remove verification stamp

Page 2 of 11
FTK/JTKEK/BETT3373

LAB 4: INFINITE IMPULSE RESPONSE (IIR) FILTER DESIGN

1.0 OBJECTIVES

Student able:
1. To understand the basic concepts and working principles of the IIR filter
2. To understand the structure of the IIR filter
3. To understand the concepts of certain basic IIR filter design techniques
4. To acquire the capability of designing IIR filters to meet certain filtering requirements

2.0 EQUIPMENT
Hardware Type/Version
1. Workstation (Computer) Windows 7
2. MATLAB R2013

3.0 SYNOPSIS & THEORY

An IIR filter has a transfer function in the general form as follows:

p 0 + p1 z −1 + p1 z −1 +  + p M z − M
H (z )IIR = where N = filter order
d 0 + d1 z −1 + d 2 z − 2 +  + p N z − N

In IIR filter design, the following steps are commonly followed:

Step 1. Convert digital filter specifications into analog low pass prototype filter specifications.
Step 2. Determine the analog low pass filter transfer function that meets these specifications.
Step 3. Transform the identified analog low pass filter transfer function into the desired digital
filter transfer function.

Figure 1 – Design Flow of the IIR Filter

Page 3 of 11
FTK/JTKEK/BETT3373

4.0 PROCEDURE

We will design the following IIR filters (with all frequencies and magnitudes specified in normalized
forms).

Filter 1: Low pass filter with a 3-dB cut-off frequency of 0.2, bandstop edge at a frequency of
0.3, passband maximum magnitude deviation of 3 dB, stopband maximum magnitude of –15 dB.

Typical filter magnitude specifications are shown in Figure 1.

For Step 1 mentioned earlier, we normally apply the bilinear transformation method to convert the
frequency requirements from the z-domain (digital: ) to the s-domain (analog: ). See the
following equations. We can use T=2 in the transformation from the z-domain to the s-domain as
long as the reverse transformation for Step 3 uses the same value of T.

2  1 − z −1 
s=   (1)
T  1 + z −1 

2  
= tan  (2)
T 2

|H(ej)|
1

1/(1 + 2)0.5

Transition
band

1/A

p s 
0
Figure 2 – Filter Magnitude Specifications

Exercises

a. Transform the 3-dB cut-off frequency of 0.2 and bandstop frequency of 0.3 from the
z-domain to the s-domain using the bilinear transformation equations provided earlier.
(Hint: From equation (2), convert p, s → p, s)

Page 4 of 11
FTK/JTKEK/BETT3373

b. Determine  and A shown in Figure 2 for Filter 1.


3
(Note: 20 log 10 20 = 3dB )

c. Determine the transition ratio, k, and discrimination parameter, k1, of the filter given by the
following equations:

p
k= (3)
s

k1 = (4)
A2 − 1

d. Design a Butterworth filter that meets the filtering requirements set for Filter 1, as
described earlier, using the following equations.
The order of a Butterworth filter is approximated as follows:

log10 (1 / k1 )
N=
log 10 (1 / k )
(5)

The transfer function of a Butterworth filter of order N is as follows:


 Np
H a (s ) =
 lN=1 (s − pl ) (6)
where pl =  p e j  ( N +2l −1) 2 N , l = 1,2, N
(Hint: From equation (5) and (6), find estimation of N (round up), Estimation of the poles
of filter, p1 and Transfer function of the Butterworth filter, Ha(s).)

Verify your answer by executing the following MATLAB code.


(Hint: Compare your answer in Exercise (a), (b), (c) and (d) with value in MATLAB’s
Workspace)

%% myLab4_1.m
clear all; close all;
%Passband
ps_nor = 0.2;
ps_ang = pi*ps_nor;
ps_max_dev_dB = -3;
ps_max_dev = 10^(ps_max_dev_dB/20);
%Stopband
sp_nor = 0.3;
sp_ang = pi*sp_nor;
sp_max_mag_dB = -15;
sp_max_mag = 10^(sp_max_mag_dB/20);

%% IIR low-pass filter based on Butterworth design step-by-step bilinear


transformation
% Filter parameters
e = sqrt((1/ps_max_dev)^2 - 1);
A = 1/sp_max_mag;
k1 = e / sqrt(A^2 - 1);
% Mapping of angular frequencies from z-domain to s-domain with T = 2
ps_alpha_ang = tan(ps_ang/2);
sp_alpha_ang = tan(sp_ang/2);
%Transition ratio
k = ps_alpha_ang / sp_alpha_ang;
% Butterworth filter order determination

Page 5 of 11
FTK/JTKEK/BETT3373

N_ord = ceil(log10(1/k1) / log10(1/k));

e. Convert the transfer function derived in Exercise (d) into the z-domain using bilinear
transformation. You may need to refer to Equation (1) for the conversion.
(Hint: Ha(s) → Ha(z) )
f. Implement the above Butterworth IIR filter in MATLAB (myLab4_2.m). You may want to
use the built-in buttap function in MATLAB to determine the reference transfer function
for a low pass Butterworth filter with a cut-off angular frequency of 1 rad/s. The adjustment
of s → s / cutoff must be made to the reference transfer function to obtain the filter transfer
function of the desired cut-off frequency. Use the bilinear function in MATLAB for
bilinear transformation.
(Hint: Adjustment of s → s / cutoff )

The nth of Denominator


The nth of Denominator =
Butterworth filter 3dB cut − off frequency( m+1)−n

where m is the highest power of the filter transfer function polynomials.

%% myLab4_2.m % Lowpass IIR filter design


clear all; close all;
%Passband
ps_nor = 0.2;
ps_ang = pi*ps_nor;
ps_max_dev_dB = -3;
ps_max_dev = 10^(ps_max_dev_dB/20);
%Stopband
sp_nor = 0.3;
sp_ang = pi*sp_nor;
sp_max_mag_dB = -15;
sp_max_mag = 10^(sp_max_mag_dB/20);

%% IIR low-pass filter based on Butterworth design step-by-step bilinear


transformation
% Filter parameters
e = sqrt((1/ps_max_dev)^2 - 1);
A = 1/sp_max_mag;
k1 = e / sqrt(A^2 - 1);
% Mapping of angular frequencies from z-domain to s-domain with T = 2
ps_alpha_ang = tan(ps_ang/2);
sp_alpha_ang = tan(sp_ang/2);
%Transition ratio
k = ps_alpha_ang / sp_alpha_ang;
% Butterworth filter order determination
N_ord = ceil(log10(1/k1) / log10(1/k));
% Butterworth filter 3dB cut-off angular frequency
cut_alpha_ang = ps_alpha_ang / e^(1/N_ord);
% Butterworth filter (analog) with 3dB cut-off angular frequency at 1 rad/s
[Z, P, K] = buttap(N_ord);
% Filter transfer function polynomials
D_poly = poly(P);
N_poly = K*poly(Z);
% Adjust the denominator polynomial the required low-pass cut-off angle
% s -> s / cut_alpha_ang
for i = [1:length(D_poly)]
D_poly(i) = D_poly(i)*(1/cut_alpha_ang)^(length(D_poly)-i);
end
% Bilinear transformation with T = 2 to generate IIR transfer function
[numd, dend] = bilinear(N_poly, D_poly, 0.5);
% Magnitude response
N = 1024;
[H1_a, W1_a] = freqz(numd, dend, N);
H1_a = H1_a / max(abs(H1_a));

%% Plot of magnitude response of IIR low-pass filter based on step-by-step


% bilinear transformation
plot(W1_a/pi, 20*log10(abs(H1_a)));
title('Magnitude response, |H1| (Butterworth - Manual Bilinear)'); xlabel('Normalized
frequency'); ylabel('|H1|');

Page 6 of 11
FTK/JTKEK/BETT3373

grid on; axis([0 1 -20 0]);

g. Build another Butterworth IIR filter with the same order and filtering specifications in the z-
domain using both the butter and buttord functions directly. Understand the coding
and compare the magnitude responses of the two IIR filters. You may refer to Appendix
for more information about the MATLAB functions.

%% myLab4_3.m % Lowpass IIR filter design


clear all; close all;
%Passband
ps_nor = 0.2;
ps_ang = pi*ps_nor;
ps_max_dev_dB = -3;
ps_max_dev = 10^(ps_max_dev_dB/20);
%Stopband
sp_nor = 0.3;
sp_ang = pi*sp_nor;
sp_max_mag_dB = -15;
sp_max_mag = 10^(sp_max_mag_dB/20);

%% IIR low-pass filter based on Butterworth design using Matlab function directly
[N_ord1, Wn1] = buttord(ps_nor, sp_nor, -ps_max_dev_dB, -sp_max_mag_dB);
[b, a] = butter(N_ord1, Wn1);
% Magnitude response
N = 1024;
[H1_b, W1_b] = freqz(b, a, N);
H1_b = H1_b / max(abs(H1_b));

%% Plot of magnitude response of IIR low-pass filter based on direct use of


% Matlab function
plot(W1_b/pi, 20*log10(abs(H1_b)));
title('Magnitude response, |H2| (Butterworth - Matlab Direct)'); xlabel('Normalized
frequency'); ylabel('|H2|');
grid on; axis([0 1 -20 0]);

h. Based on previous example, implement the following filters using both the butter and
buttord functions directly. Refer to Appendix for more information about these functions.
|HBP(ej)|
|HHP(ej)| 0 dB
0 dB
-3dB
-3dB

Transition
band

-15 dB -15 dB

0.7 0.8  0.2 0.3 0.7 0.8 


0 0

(a) (b)

Page 7 of 11
FTK/JTKEK/BETT3373

|HBS(ej)|
0 dB

-3dB

-15 dB

0.2 0.3 0.7 0.8 


0

(c)

Figure 3 – Specifications for High Pass, Bandpass, and Bandstop Filters

5.0 EXPERIMENT DATA


(Please attached all the codings obtained from the Procedure)

6.0 EXPERIMENT RESULT


(Please attached all the graphs obtained from the Procedure)

7.0 QUESTION & DISCUSSION


Answer all Questions in Procedure (Exercise) and show the calculation.
Discuss based on Experiment Data and Experiment Result regarding on MATLAB
functions in the given codings.

8.0 CONCLUSION

Page 8 of 11
FTK/JTKEK/BETT3373

Appendix

Butterworth Analog Low Pass Filter Prototype (buttap)

Butterworth filters are characterized by a magnitude response that is maximally flat in the passband
and monotonic overall. In the low pass case, the first 2n–1 derivatives of the squared magnitude
response are zero at ω = 0. The squared magnitude response function is

1
| H ( ) | 2 =
 2n
1+ ( )
0

which corresponds to a transfer function with poles equally spaced around a circle in the left half-
plane. The magnitude response at the cut-off angular frequency ω0 is 1 / 2 , regardless of the filter
order. buttap sets ω0 to 1 for a normalized result.

The syntax for the Butterworth analog low pass filter prototype in MATLAB is as follows:

[z,p,k] = buttap(n)

[z,p,k] = buttap(n) returns the poles and gain of an order n Butterworth analog low pass
filter prototype. The function returns the poles in the length n, column vector p, and gain in scalar
k. z is an empty matrix because there are no zeros. The transfer function is computed as follows:

z ( s) k
H (s) = =
p( s) ( s − p(1))(s − p(2)) ( s − p(n))

Bilinear Transformation (bilinear)

Bilinear transformation is a method for analog-to-digital filter conversion. The syntax of bilinear
transformation in MATLAB is as follows:

[numd,dend] = bilinear(num,den,fs)

This syntax will convert an s-domain transfer function given by num and den to a discrete
equivalent. Row vectors num and den specify the coefficients of the numerator and denominator,
respectively, in descending powers of s.

num(s) num(1)s n +  + num(n)s + num(n + 1)


=
den(s) den(1)s m +  + den(m)s + den(m + 1)

fs is the sampling frequency in hertz. bilinear returns the discrete equivalent in row vectors
numd and dend in descending powers of z (ascending powers of z–1).

Page 9 of 11
FTK/JTKEK/BETT3373

Butterworth Analog and Digital Filter Design (butter)

The butter function in MATLAB designs low pass, bandpass, high pass, and bandstop digital
and analog Butterworth filters. Butterworth filters are characterized by a magnitude response that
is maximally flat in the passband and monotonic overall. There is a built-in function in MATLAB
which can be used to build the Butterworth IIR filter directly. The syntax of this function is as
follows:

[b,a] = butter(n,Wn)

[b,a] = butter(n,Wn,'s') designs an order n low pass analog Butterworth filter with
angular cut-off frequency Wn rad/s. It returns the filter coefficients in the length n+1, row vectors b
and a, in descending powers of s, derived from the transfer function as follows:

B(s) b(1)s n + b(2)s n−1 +  + b(n + 1)


H ( s) = = n
A(s) s + a(2)s n−1 +  + a(n + 1)

For digital filter design, butter uses bilinear to convert the analog filter into a digital filter
through a bilinear transformation with frequency prewarping. Careful frequency adjustment
guarantees that the analog filters and the digital filters will have the same frequency response
magnitude at Wn, or w1 and w2.

Butterworth Filter Order and Cut-Off Frequency (buttord)

The MATLAB function of buttord calculates the minimum order of a digital or analog
Butterworth filter required to meet a set of filter design specifications. The syntax of this function
in MATLAB is as follows:

[n,Wn] = buttord(Wp,Ws,Rp,Rs,'s')

[n,Wn] = buttord(Wp,Ws,Rp,Rs) returns the lowest order, n, of the digital Butterworth filter
that loses no more than Rp dB in the passband and has at least Rs dB of attenuation in the
stopband. The scalar (or vector) of corresponding cut-off frequencies, Wn, is also returned. Use
the output arguments n and Wn in butter. Wp and Ws are the normalized passband and
stopband frequencies respectively.

Transform Low Pass Analog Filters to High Pass (lp2hp)

One of the frequency transformation functions in MATLAB is lp2hp. It transforms analog low
pass filter prototypes with a cut-off angular frequency of 1 rad/s into high pass filters with the
desired cut-off angular frequency. The transformation can be done in the following syntax in
MATLAB:

[bt,at] = lp2hp(b,a,Wo)

[bt,at] = lp2hp(b,a,Wo) transforms an analog low pass filter prototype given by


polynomial coefficients into a high pass filter with cut-off angular frequency Wo. Row vectors b
and a specify the coefficients of the numerator and denominator of the prototype in descending
powers of s.

b( s) b(1) s n +  + b(n)s + b(n + 1)


=
a(s) a(1)s m +  + a(m) s + a(m + 1)

Scalar Wo specifies the cut-off angular frequency in unit of radians/second. The frequency
transformed filter is returned in row vectors bt and at.

Page 10 of 11
FTK/JTKEK/BETT3373

Transform Low Pass Analog Filters to Bandpass (lp2bp)

lp2bp transforms analog low pass filter prototypes with a cut-off angular frequency of 1 rad/s into
bandpass filters with the desired bandwidth and center frequency. It is one of the frequency
transformation functions where its syntax in MATLAB is as follows:

[bt,at] = lp2bp(b,a,Wo,Bw)

This function transforms an analog low pass filter prototype given by polynomial coefficients into a
bandpass filter with center frequency Wo and bandwidth Bw. Row vectors b and a specify the
coefficients of the numerator and denominator of the prototype in descending powers of s.

b( s) b(1) s n +  + b(n)s + b(n + 1)


=
a(s) a(1)s m +  + a(m) s + a(m + 1)

Scalars Wo and Bw specify the center frequency and bandwidth in unit of rad/s. For a filter with
lower band edge w1 and upper band edge w2, use Wo = sqrt(w1*w2) and Bw = w2-w1.
lp2bp returns the frequency transformed filter in row vectors bt and at.

Transform Low Pass Analog Filters to Bandstop (lp2bs)

Another frequency transformation functions in MATLAB is lp2bs. This function transforms


analog low pass filter prototypes with a cut-off angular frequency of 1 rad/s into bandstop filters
with the desired bandwidth and center frequency. The syntax of this function in MATLAB is as
follows:

[bt,at] = lp2bs(b,a,Wo,Bw)

[bt,at] = lp2bs(b,a,Wo,Bw) transforms an analog low pass filter prototype given by


polynomial coefficients into a bandstop filter with center frequency Wo and bandwidth Bw. Row
vectors b and a specify the coefficients of the numerator and denominator of the prototype in
descending powers of s.

b( s) b(1) s n +  + b(n)s + b(n + 1)


=
a(s) a(1)s m +  + a(m) s + a(m + 1)

Scalars Wo and Bw specify the center frequency and bandwidth in unit of radians/second. For a
filter with lower band edge w1 and upper band edge w2, use Wo = sqrt(w1*w2) and
Bw = w2–w1. lp2bs returns the frequency transformed filter in row vectors bt and at.

Page 11 of 11

Potrebbero piacerti anche