You are on page 1of 36

CPEN 304 Digital Signal Processing

Lecture 6
IIR Digital Filter Design II
October 21, 2021
Dr. Godfrey A. Mills
Email: gmills@ug.edu.gh
Phone: 020-549-6944

Course TA
1 CPEN 304 Lecture 5 Baron Afutu
OUTLINE OF DSP COURSE
— Course outline
— Digital signal processing
— Discrete systems
— Z-transforms
— Digital filters and properties
— IIR digital filter design I (specifications)
— IIR digital filter design II (design methods)
— FIR digital filter design I
— FIR digital filter design II
— IIR and FIR digital filter implementation
— Number representation
— Filter design application
2 CPEN 304 Lecture 4
OUTLINE #6
— IIR digital filter design methods
— Bilinear transformation
— Impulse invariance method
— Step invariance
— Bilinear transformation and application
— Impulse invariance and application
— Step invariance in application
— IIR digital filter design application 1
— IIR digital filter design application 2

3 CPEN 304 Lecture 6


IIR digital filter design methods
— The method to transform the analog filter H(s), to the digital
filter H(z), is what we call the IIR digital filter design method
— We have three popular design methods (conversion methods) :
— Bilinear transformation method
— >> create the digital filter by transforming the analog
transfer function from the “s-plane” to the digital “z-plane”
using one-to-one mapping
— Impulse response invariant method
— >> create the digital filter by performing sampling of the
inverse of analog impulse response and convert to “z-”
— Step response invariant method
— >> same as above except that we first find the system
response of the step before sampling the analog version
4 CPEN 304 Lecture 6
Bilinear transformation method
— Bilinear transformation is a method for converting the analog
transfer function to digital transfer function and it is the most
frequently used IIR design technique
— This method is based on creating a digital filter using one-to-
one direct transformation from the s-plane to the z-plane
— Bilinear transform is a mathematical transformation from the
s-domain to the z-domain and it is defined by:
— >> s = c[1-z-1]/[1+z-1] --------------------(6)
— >> z-1 = [1-s/c]/[1+s/c] or z = [1+s/c]/[1- s/c]
— The parameter c = (2/T) is a constant that is set to map
precisely one analog frequency to one digital frequency,
and T is the sampling period
5 CPEN 304 Lecture 6
IIR digital filter transfer function
— Following the determination of the analog transfer function of
the filter H(s), we then apply the bilinear transform method to
convert H(s) to the digital filter equivalent by replacing s in
H(s) using equation (6)
— Suppose we have the analog transfer function for the filter as
H(s) as defined below
— H(s) = (A1s + A2)/(B1s + B2) , where c = (2/T)
— Then the digital filter H(z) after the bilinear transform will be
— H(z) = (A1{c[1-z-1]/[1+z-1]} + A2)/
(B1{s = c[1-z-1]/[1+z-1] } + B2)
— Example below shows conversion of a analog H(s) to H(z) as:
(1 + z -1 ) 1 - a 1 + z -1 1 - wC
G( z) = º * a=
-1 -1
(1 -6 z ) + (1 + z )
CPEN 304 Lecture 2 1 - az -1 1 + wC
6
IIR digital filter design example 1
— Question 2:
— Design a digital lowpass IIR Butterworth filter with a 1 dB
cutoff frequency at 1kHz and minimum attenuation of 40 dB
at 5 kHz.
— Solution 2:
— We first convert the frequency to digital frequency and then
convert the digital frequency to the analog frequency
— We then use the analog frequency specification in Butterworth
to find the order N of the filter using the specifications :
— >> αp =-1dB = 20log10(1/√[1+ ε2]) >> ε2 = 0.1220185
— >> αs =-40dB = 20log10(1/A) >> A2 = 31.622777
— >> k = ωS / ωP = 1.1708496 /0.4142135 = 5
— >> k1 = ε/√(A2-1) >> N = log10(1/k1)/log10(1/k)
— >> N = log10(15.841979)/log10(2.8266814) = 3
7 CPEN 304 Lecture 6
IIR digital filter design example 1
— Cont’d….
— We next use the filter order to find the cut-off frequency ωc
using the Butterworth >> use any of the filter bands (either
the passband or the stopband) and values of ε2, ωp, and N as:
— |H(jωaP)|2 = 1/[1+(ωp/ωc)2N] = 1/(1+ε2) or (1- δP)2
— |H(jωaS|2 = 1/[1+(ωS/ωc)2N] = 1/(A2) or (δS)2
— ωc = 1.419915(ωp) = 1.119918*0.4142135 = 0.588148
— With the cut-off and order N, we proceed to find the filter
transfer function Ha(s) by finding the pole locations and zeros
using the filter parameters which gives :
— >> Ha(s) = 1/[(s+1)(s2+2s+1)]
— Since the transfer function Ha(s) is obtained at the 3-dB cut-off
frequency where ω = 1, we normalize H(s) with the cut-off
CPEN 304 Lecture 6
8
IIR digital filter design example 1
— Cont’d….
— Thus, we adjust the computed transfer function H(s) to bring
the filter frequency the cut-off frequency ωc = 0.588148 by
replacing s in the transfer function H(s) with (s/0.588148).
— Thus, adjusted analog transfer function H(s) becomes :
— Ha(s) = Han(s/0.588148) = 0.203451/ [(s+0.588148)*
(s2+0.588148s+0.345918)]
— We finally convert the analog filter transfer function Ha(s) to
the digital filter using the bilinear transformation method
to obtain the digital lowpass filter transfer function H(z)
— Thus, we replace “s” in the Ha(s) with the equation below:
— >> s = c(1-z-1)/(1+z-1) , where we assume c = 1
9 CPEN 304 Lecture 6
IIR digital filter design example 1
— Cont’d….
— Thus, the final designed lowpass digital filter (transfer
function) G(z) based on the defined specification reduces to :
0.0662(1 + z -1 ) 3
G( z) =
(1 - 0.2593 z -1 )(1 - 0.6762 z -1 0.3917 z - 2 )
— We can design the above lowpass digital filter G(z) using the
Butterworth method directly in z-domain using the Matlab
function for buttord and butter

10 CPEN 304 Lecture 6


Impulse Invariant design method
— Another design method for converting the analog filter
transfer function H(s) to the equivalent digital filter transfer
function H(z) is the Impulse invariant method
— The method is based on creating a digital filter using discrete
impulse response which is a sampled version of the continuous
time impulse response of analog filter >> procedure is:
— Start with the analog filter transfer function H(s)
— Perform inverse Laplace transform of H(s), to determine
the continuous time impulse response h(t) of the system
— Sample the impulse response h(t) to obtain the discrete
time equivalent of the impulse response of the system h(n)
— Perform z-transform on the sampled version of the impulse
response to obtain the transfer function H(z)
11 CPEN 304 Lecture 6
Impulse Invariant design example
— Question 1 :
— Suppose we want to convert the following continuous time
transfer function to discrete time transfer function using the
impulse invariant method.
— >> H(s) = 12/[(s+12)(s+5)]
— Solution 1 :
— We use the partial fraction method to decompose the transfer
function to form of suitable for inverse transformation
— >> H(s) = [4/(s+2)] – [4/(s+5)]
— We find the inverse Laplace transform of the above to give the
impulse response as:
— >> h(t) = (4e-2t – 4e-5t) u(t)
12 CPEN 304 Lecture 6
Impulse Invariant design example
— Cont’d…..
— We then proceed to sample the impulse response at intervals
of T, to obtain the discrete impulse response h(n) as :
— >> h(n) = (4e-2nT – 4e-5nT)u(nT)
— The next step is to use the z-transform to find the transfer
function of the discrete sequence above in the z-domain as:
— H(z) = 4/[1 – e-2Tz-1] – 4/[1 – e-5Tz-1]
— Finally, we combine terms together to obtain a simplified as:
— H(z) = 4 [e-2T – e-5T]z-1/ ([1 – e-2Tz-1]. [1 – e-5Tz-1])

13 CPEN 304 Lecture 6


Step Invariant design method
— Another design method to convert the analog filter transfer
function H(s) to digital transfer function H(z) is the Step
Impulse invariant method
— This design method is essentially the same as impulse invariant
method except that we must determine the step response of
the system of the analog transfer function (adjusted the H(s)
by unit step function) before it is discretized and z-transform
— Conversion process using the step invariant is as follows :
— Start with the analog filter transfer function H(s)
— Find the transform of unit step input response D(s) = 1/s
— Compute the analog system step response by simply
multiplying H(s) and D(s) >> G(s) = H(s).(1/s)
14 CPEN 304 Lecture 6
Step Invariant design method
— Cont’d……
— We proceed to find time domain response of G(s) to obtain
the step response in g(t) using the inverse Laplace transform
— We then proceed to find the discrete time step response by
sampling the continuous time version (replace t = nT) as
— >> g(n) = g(t) for t = nT
— We next determine the z-transform of the discrete time
system response g(n) to obtain G(z)
— >> G(z) = Z{g(n)} = H(z).[1/(1-z-1)]
— Note that G(z) is the product of the discrete time transfer
function H(z) and the z-transform of the step input
— To find H(z), we simply multiply G(z) by (1-z-1)
— >> H(z) = G(z).((1-z-1)
15 CPEN 304 Lecture 6
Step Invariant design example
— Question 2:
— Suppose we want to convert the following continuous time
transfer function to discrete time transfer function using the
step invariant method.
— >> H(s) = 12/[(s+12)(s+5)]
— Solution 2:
— We first need to determine the systems response to a step
input by multiplying H(s) by the Laplace transform of step
input function (1/s)
— >> G(s) = H(s)*(1/s) = 12/[(s+12)(s+5)] (1/s)
— Using the partial fraction method to decompose the transfer
function to form of suitable for inverse transformation
— >> G(s) = [1.2/s] - [2/(s+2)] + [0.8/(s+5)]
16 CPEN 304 Lecture 6
Step Invariant design example
— Cont’d…..
— We find the inverse Laplace transform of the above to give the
impulse response as:
— >> g(t) = (1.2 - 2e-2t – 0.8e-5t) u(t)
— We then proceed to sample the impulse response at intervals
of T, to obtain the discrete impulse response h(n) as :
— >> g(n) = (1.2 - 2e-2nT – 0.8e-5nT) u(nT)
— The next step is to use the z-transform to find the transfer
function of the discrete sequence above in the z-domain as:
— G(z) = 1.2/[1–z-1] – 2/[1 – e-2Tz-1] + 0.8/[1 – e-5Tz-1]
— Finally, we can combine terms together to obtain simplified
transfer function as:
17 CPEN 304 Lecture 6
IIR digital filtering example 1
— Suppose we have a signal x(t) that is described by the function
below and we want to design a digital filter to remove or
filter out one of the frequency components
— >> x(t) = 1 + cos(t) + cos(5t)
— Suppose we want to remove the “cos(5t) component using a
2-pole digital lowpass Butterworth filter
— What specifications do we need to design and implement the
filtering operation
— Specifications:
— Since the highest frequency component of x(t) is 5rad/sec, to
avoid the problem of aliasing, we have to select a sampling
frequency of at least 10 rad/sec >> thus, a sampling period T
of 0.2 is sufficiently small enough to avoid aliasing effect
18 CPEN 304 Lecture 5
IIR digital filtering example 1
— Cont’d….
— A filter cut-off frequency, wc of 2 rad/sec should result in
attenuation of the “cos(5t)” component with little attenuation
effect on the “1 + cos(t)” component
— Design of filter :
— [z,p,n] = buttap(2); % design method >> Butterworth
— [num,den] = zp2tf(z,p,n); % analog transfer function
— wc = 2; % need to transform the cut-off frequency
— [num,den] = lp2lp(num,den,wc);
— T = 2; % sampling period
— [numd,dend] = bilinear(num,den,1/T); % digital method
— Display the digital filter >> display(numd); display(dend);
19 CPEN 304 Lecture 5
IIR digital filtering example 1
— Cont’d….
— Filtering implementation :
— >> n = 0:80; T = 0.2;
— >> xt = 1 + cos(T*n) + cos(5*T*n); % t = nT
— >> y = filter(numd,dend,xt);
— Plot the analog and discrete signals and the filtered versions
— >> t = 0:0.06:15; xa = 1 + cos(t) + cos(5*t);
— >> subplot(211); plot(t,xa);
— >> subplot(212); plot(n*T,y);
— >> pause;
— >> subplot(211); stem(n*T,x);
20
— >> subplot(212); stem(n*T,y);
CPEN 304 Lecture 5
IIR digital filtering example 2
— Practical filter design problem :
— Design a 50Hz IIR notch (narrow bandwidth bandstop)
filter to be used in a digital control system at the TOR
plant for controlling the fuel processing.The interference
noise in the power line will be eliminated digitally rather
than analog by inserting the 50Hz digital filter system in
cascade with the digital controller >> output of the filter
will be used as input to the digital controller.
— We now proceed to define the specifications required to meet
this objective such that the interference electrical noise will be
eliminated without affecting the control operations
— We have to determine select the filter design to determine the
order for the filter, analog transfer function, and
21
transformation
CPEN 304 Lecture 6 method to obtain the IIR digital filter
IIR digital filtering example 2
— Cont’d…..

22 CPEN 304 Lecture 6


IIR digital filtering example 2
— Cont’d…..
— Design requirements:
— Bandwidth of the rejected frequencies must be kept within a
very narrow limit since the 50 Hz frequency is in the range
of the control frequencies required for the system
— Attenuation (passband peak ripple) at the 49 Hz and 51 Hz
must be kept at 3 dB or less
— 50Hz frequency rejection (stopband frequency) must be at
least 100 dB
— Attenuation below the 48 Hz and also above the 52 Hz must
be kept at less than 1.0 % >> since the two frequencies are
within the passband, the magnitude values at the frequencies
must be at most 1.0%
23 CPEN 304 Lecture 6
IIR digital filtering solution 2
— The task is to design a bandstop (or band reject) digital filter
— Design approach is to first design a lowpass Butterworth filter
and convert the lowpass filter to a bandstop filter with center
frequency of 50 Hz and bandwidth of 4 Hz
— We first select the filter design method for the analog filter
— We next determine the sampling frequency (its not given)
that will be adequate for the digital filter design
— We design the analog filter (find H(s) for the filter) using
the given specifications and finally convert the analog filter
H(s) to the digital filter H(z) >> this is the lowpass filter
— Finally, we convert the lowpass to any filter type such as
highpass, bandpass, and bandstop filter >> in this context,
we convert to the bandstop filter
24 CPEN 304 Lecture 6
IIR digital filtering solution 2
— Cont’d…..
— We now proceed with the filter design using the numerical
approach to determine the filter order, the cutoff frequency,
transfer function H(s) and H(z) as follows:
— Select Butterworth design method and start the a minimum
biquad design filter with order 2 for lowpass filter :
— >> [Z1, P1, K1] = buttap(2); >> this give order N = 4
— >> [Num1, Den1] = zp2tf(Z1,P1,K1);
— We next convert convert the lowpass filter to a bandstop
filter with center frequency of 50Hz and bandwidth of 2 Hz
— >> [Num2, Den2] =
lp2bs(Num1,Den1,2*pi*50,(2*pi)*2);
— Now we check the frequency response of the bandstop filter
25 CPEN 304 Lecture 6
IIR digital filtering solution 2
— Cont’d…..
— We next determine the frequency response of the bandstop
filter to check if it meets the given filter specifications >> we
can select a broad range of frequencies
— >> frequency range, F = [10 48 49 50 52 100];
— >> omega = 2*pi*F;
— >> F_response, H_F = freqs(Num2,Den2,omega);
— >> Mag = abs(H_F); grid on;
— >> loglog(F, Mag) ; % we can also use plot(F, Mag);
— Now, if we check the from the response to see if the
requirements for the 49 Hz and 51Hz are within the desired
value of 3dB and also the requirements for the below 48 Hz
and above 52 Hz are within the 1.0% >> student to plot this
in Matlab and verify the values
26 CPEN 304 Lecture 6
IIR digital filtering solution 2
— Cont’d…..
— Observation from the frequency response curve show that, we
have approximately 3 dB (0.707) at 49 Hz and 51 Hz but at
the 48 Hz and 52Hz, the attenuation is about 3% which is
more than the desired requirement of less than 1.0% .
— We conclude that the design is not suitable and change the
order of the filter to another level, say third order.
— Using the third order Butterworth design method, we repeat
the process again :
— >> [Z2, P2, K2] = buttap(3); >> this gives order N = 6
— >> [Num3, Den3] = zp2tf(Z2,P2,K2);
— We transform LPF to BSF with 50Hz center frequency as
— >> [Num4, Den4] =
lp2bs(Num3,Den3,2*pi*50,2*pi*2);
27 CPEN 304 Lecture 6
IIR digital filtering solution 2
— Cont’d…..
— We proceed again to find frequency response of the bandstop
filter to determine if it meets the specifications given :
— >> frequency range, F = [10 48 49 50 52 100];
— >> Omega2 = 2*pi*F;
— >> F_response, H_F2 = freqs(Num4,Den4,Omega2);
— >> Mag2 = abs(H_F2); grid on;
— >> loglog(F, Mag2) ; % we can also use plot(F, Mag);
— We then observe from the response and check whether the
design meets the desired 1% specification. If not, we move
again to another filter order and go through the steps again till
we are satisfied that the requirements are fully met
— Observation from the values show that the order of 3 satisfies
the requirements and thus, we settle on this order
28 CPEN 304 Lecture 6
IIR digital filtering solution 2
— Cont’d….
— Now that we have settled on the analog filter, we then move to
the next of converting the analog filter using bilinear method
to transform the H(s) to the H(z) with a matching frequency
of 50Hz to achieve the final digital filter design.
— >> select a sampling rate, Fs = 1000;
— >> frequency range, F = [10 48 49 50 52 100];
— >> Omega3 = 2*pi*F;
— >> [Num_Z, Den_Z] = bilinear(Num2,Den2,Fs);
— >> H_Z = freqz(Num_Z, Den_Z, Omega3/Fs);
— >> Mag_Z = abs(H_Z);
— >> loglog(F, Mag_Z);
— Now, we have our digital filter but if we observe the response,
we can observe that the notch in the filter has been shifted
29 CPEN 304 Lecture 6
IIR digital filtering solution 2
— Cont’d….
— The bilinear transformation resulted in the shift in the notch
filter, making the resulting filter not matching the given
designed specification
— To overcome this, we force the bilinear transform to match
the digital frequencies with the analog frequencies at one
specified frequency point
— If we choose the 50Hz as the matching frequency, we then add
this matching frequency to the bilinear argument function as:
— >> Fs = 1000;
— >> [Num_Z1, Den_Z1] = bilinear(Num2,Den2,Fs, 50);
— >> H_Z2 = freqz(Num_Z1, Den_Z1,Omega3/Fs);
— >> Mag_Z2 = abs(H_Z2);
— >> loglog(F, Mag_Z2);
30 CPEN 304 Lecture 6
IIR digital filtering solution 2
— Cont’d….
— Once we are satisfied with the response, we can now generate
or print out (show as display) the analog filter H(s) and the
digital filter transfer H(z) using the coefficients values of the
numerator and denominator for the two cases.
— >> H(s) = ??
— >> H(z) = ??

31 CPEN 304 Lecture 6


Noise estimation in filters
— Theoretically, we expect magnitude response of anti-aliasing
filter to attenuate to zero but due to the nonzero attenuation,
aliasing noise from adjacent replica still appear
— We can controlled the amount of aliasing noise by either using
higher filter order or increase the sampling rate
— Example, for a unity gain second order lowpass Butterworth
filter, the magnitude frequency response will be given as :
— >> |H(f)|2 = 1/[1+(f/fc)4]
— Suppose we assume a cut-off frequency of 3.4kHz, a plot of
the magnitude response shows that the absolute attenuation
begins at the level of 0.7 at 3.4kHz and reduces to 0.3 at 6kHz
— Ideally, we want the gain attenuation to be zero after 4kHz if
the sampling rate is 8kHz but aliasing will practically occur
32 CPEN 304 Lecture 4
Noise estimation in filters
— Cont’d……
— We derive the % aliasing level in the filtered signal using the
Butterworth magnitude function as:
— >> % aliasing level = |H(f)|f=fs-fa/|H(f)|f=fa
— Where fs is the sampling frequency and fa is the aliasing
frequency or frequency at which aliasing occurs
— Thus, we can express the expression above as:
— % aliasing level = [1+(fa/fc)2N]0.5/ [1+{fs-fa}/fc)2N]0.5
— From the above relation, we can estimate the aliasing noise
percentage or choose a higher order filter to satisfy the
requirement for the aliasing level percentage

33 CPEN 304 Lecture 4


Noise estimation in filters
— Cont’d……
— Question 1 :
— Suppose we have a DSP system where a sampling rate of 8kHz
is used and an a second order Butterworth anti-aliasing filter
with a cut-off frequency of 3.4kHz. Determine (a) the % level
of aliasing at the cut-off frequency (b) the % level at aliasing
frequency of 1kHz
— Solution 1:
— Using fs = 8kHz, fc = fa = 3.4kHz, and N=2
— % = [1+(3.4/3.4)4]0.5/ [1+{8-3.4}/3.4)2N]0.5 = 67.8%
— Using fs = 8kHz, fa = 1kHz, and N=2
— % = [1+(1/3.4)4]0.5/ [1+{8-1}/3.4)2N]0.5 = 23.05%

34 CPEN 304 Lecture 4


Noise estimation in filters
— Cont’d……
— Question 2 :
— Suppose we have a DSP system where a sampling rate of
16kHz is used and an a second order Butterworth anti-aliasing
filter with a cut-off frequency of 3.4kHz. Determine the %
level of aliasing at the cut-off frequency
— Solution 2:
— Using fs = 16kHz, fc = fa = 3.4kHz, and N=2
— % = [1+(3.4/3.4)4]0.5/ [1+{16-3.4}/3.4)2N]0.5 = 10.26%
— When we compare this results with the former results, we
observe that increasing the sampling rate can reduce the
aliasing noise level

35 CPEN 304 Lecture 4


Noise estimation in filters
— Cont’d……
— Question 3 :
— Suppose we have a DSP system where a sampling rate of 40Hz
is used and an Butterworth anti-aliasing filter with a cut-off
frequency of 8kHz and the percentage of aliasing level at the
cut-off frequency is required to be less than 1%. Determine
the order of the lowpass filter required to meet this target
— Solution 3:
— Using fs = 40kHz, fc = fa = 8kHz, and at different values of N
— At N = 1, % = 34.30
— At N = 2, % = 8.82%
— At N = 3, % = 2.21%
— At N = 4, % < 1%
— Thus, to satisfy the requirements, we choose filter order of 4
36 CPEN 304 Lecture 4

You might also like