Transcript Section 5

University of Manchester
School of Computer Science
Comp 30291 : Digital Media Processing
Section 5
z-transforms & IIR-type digital filters
10 Nov'08
Comp30291 DMP Section 5
1
Introduction
• General causal digital filter has difference equation:
y[n] 
N
 a x[n  i]
i 0
i

M
 b y[n  j]
j 1
j
• Order is maximum of N and M.
• Recursive if any b j is non-zero.
• A 2nd order recursive filter has the difference-equation:
y[n] = a 0 x[n] + a 1 x[n-1] + a 2 x[n-2] - b 1 y[n-1] - b 2 y[n-2]
10 Nov'08
Comp30291 DMP Section 5
2
Signal-flow-graph for 2nd order recursive diff equn
+
x[n]
y[n]
+
a0
z-1
z-1
a1
+
+
-b1
z-1
z-1
a2
-b2
y[n] = a 0 x[n] + a 1 x[n-1] + a 2 x[n-2] - b 1 y[n-1] - b 2 y[n-2]
10 Nov'08
Comp30291 DMP Section 5
3
Derivation of ‘z-transform’
If {x[n]} with x[n] = zn is applied to an LTI system with impulseresponse {h[n]}, output would be, by convolution :
y[n] 

nm
h
[
m
]
z

m  


n m
h
[
m
]
z
z

m  
 zn

m
h
[
m
]
z

m  
 z n H ( z)
where H ( z ) 

m
h
[
m
]
z


m  
10 Nov'08

n
h
[
n
]
z
(z - transform)

n  
Comp30291 DMP Section 5
4
‘z-transform’ of {h[n]}

n
h
[
n
]
z

H ( z) 
n  
• If input is {zn}, output is {H(z).zn}
• z may be any real or complex number for which series converges.
• For causal & stable IIR, the series converges when |z|  1.
• Replacing z by ej gives frequency-response:
j
H (e ) 

 jn
h
[
n
]
e

n  
10 Nov'08
Comp30291 DMP Section 5
5
Visualising H(z)
On Argand diagram (‘z-plane’), z = ej lies on unit circle.
Imaginary part of z
z = ej

1
10 Nov'08
Comp30291 DMP Section 5
Real part of z
6
Example 5.1
Find H(z) for the non-recursive difference equation:
y[n] = x[n] + x[n-1]
Solution:
{h[n]} = { ... , 0, 1, 1, 0, ... },
therefore
H(z) = 1 + z - 1
10 Nov'08
Comp30291 DMP Section 5
7
Example 5.2
• Find H(z) for the recursive difference equation:
y[n]
= a 0 x[n] + a 1 x[n-1] - b 1 y[n-1]
Solution: If x[n] = z n then y[n] = H(z) z n ,
y[n-1] = H(z) z n - 1
• Substitute to obtain:
H(z) z n
= a 0 z n + a 1 z n - 1 - b 1 H(z) z n - 1
H(z)
= a0 +
a 1 z - 1 - b 1 H(z) z - 1
(1 + b1z-1) H(z) = a 0 +
a1z-1
a0  a1 z 1
 H ( z) 
except when z  -b1
1
1  b1 z
• When z = -b1, H(z) = 
10 Nov'08
Comp30291 DMP Section 5
8
Find H(z) for the 2nd order difference-equation
y[n]
= a 0 x[n] + a1x[n-1] + a2x[n-2] - b1 y[n-1] - b2 y[n-2]
The same method gives:
H(z) z n = a0zn + a1zn - 1 +a2zn - 2 - b1H(z) zn - 1 - b2H(z)zn-2
a0 + a1 z-1 + a2 z-2
 H(z) = 
b0 + b1 z-1 + b2 z-2
10 Nov'08
Comp30291 DMP Section 5
with b0 = 1.
9
Consider difference-equation for general digital filter
y[n]
=
N
M
 a i x[n  i]   b j y[n  j]
i=0
j=1
• The same method gives:
1
2
N
a0  a1 z  a2 z  ...  aN z
H ( z) 
b0  b1 z 1  b2 z 2  ...  bM z M
with b0  1
• This is the ‘system function’ of the digital filter.
• Also referred to as ‘transfer function’
10 Nov'08
Comp30291 DMP Section 5
10
System function
• Ratio of 2 polynomials in z-1
• Equal to z-transform of impulse-response when this converges.
• Easily derived from difference-equation & signal-flow graph.
• Replacing z by ej gives frequency-response
10 Nov'08
Comp30291 DMP Section 5
11
Example 5.3
Give a signal-flow graph for the system function:
a0  a1 z 1  a2 z 2
H ( z) 
1  b1 z 1  b2 z 2
Solution: The difference-equation is:
y[n] = a0 x[n] + a1 x[n-1] + a2 x[n-2] - b1 y[n-1] - b2 y[n-2]
Represented by the signal-flow graph below:
+
x[n]
y[n]
+
a0
z-1
z-1
a1
+
+
-b1
z-1
z-1
a2
10 Nov'08
2nd order or
‘bi-quadratic’
IIR section
in ‘direct form 1’.
-b2
Comp30291 DMP Section 5
12
To implement ‘direct form 1’ biquad as a program
Label ‘z-1’ box inputs & outputs as shown:
+
X
Y
+
a0
z-1
X1
z-1
a1
+
+
-b1
z-1
z-1
X2
10 Nov'08
Y1
a2
-b2
Comp30291 DMP Section 5
Y2
13
In MATLAB using floating point arithmetic
X1=0; X2=0; Y1=0; Y2=0;
while 1
X = input(‘X=’);
Y = a0*X + a1*X1 + a2*X2 - b1*Y1 - b2*Y2;
disp(sprintf(‘Y = %f’ , Y) ) ;
% output Y
X2 = X1; X1 = X ;
Y2 = Y1; Y1 = Y ;
end;
10 Nov'08
Comp30291 DMP Section 5
14
In MATLAB using Signal Processing toolbox:
y = filter([a0 a1 a2], [b0 b1 b2], x );
10 Nov'08
Comp30291 DMP Section 5
15
In MATLAB using fixed point arith & shifting
K=1024;
A0=round(a0*K); A1=round(a1*K); A2=round(a2*K);
B1=round(b1*K); B2=round(b2*K);
X1=0; X2=0; Y1=0; Y2=0;
while 1
X = input(‘X=’) ;
Y = A0*X + A1*X1 + A2*X2 - A1*Y1 - A2*Y2 ;
Y = round(Y/K);
% Divide by arith right shift
disp(sprint(‘Y=%f’,Y));
% Output Y
X2 = X1; X1 = X ;
% Prepare for next time
Y2 = Y1; Y1 = Y ;
end;
10 Nov'08
Comp30291 DMP Section 5
16
Look again at ‘Direct Form 1’ signal-flow-graph
+
x[n]
y[n]
+
a0
z-1
z-1
a1
+
+
-b1
z-1
z-1
a2
-b2
• It may be thought of as two signal-flow-graphs:
x[n]
10 Nov'08
Non-recursive
part
Recursive
part
Comp30291 DMP Section 5
y[n]
17
Re-ordering LTI systems
• It may be shown than if we have two LTI systems as shown:
x[n]
L1
L2
y[n]
then re-ordering L1 & L2 does not change the behaviour of
the overall system.
x[n]
L2
L1
y[n]
• Only guaranteed to work for LTI systems
10 Nov'08
Comp30291 DMP Section 5
18
Alternative signal-flow-graph
Look again at ‘Direct Form 1’:
+
x[n]
y[n]
+
a0
z-1
z-1
a1
+
+
-b1
z-1
z-1
a2
-b2
Re-order the two ‘halves’ & then simplify to ‘direct form 2’:
x[n]
+
a0
z-1
+
+
y[n]
x[n]
10 Nov'08
+
y[n]
z-1
a1
-b1
-b2
a0
z-1
+
z-1
+
+
+
-b1
z-1
a1
z-1
a2
-b2
Comp30291 DMP Section 5
a2
19
‘Direct Form II’ signal-flow-graph
x[n]
W
+
a0
+ y[n]
z-1
+
W1
-b1
+
a1
z-1
-b2
W2
• Direct form II
economises on
‘delay boxes’.
• Notice labels:
W,W1 & W2
a2
It is a 2nd order (bi-quad) section whose system function is:
a0  a1 z 1  a2 z 2
H ( z) 
1  b1 z 1  b2 z 2
Its difference equation is:
y[n] = a 0 x[n] + a 1 x[n-1] + a 2 x[n-2] - b 1 y[n-1] - b 2 y[n-2]
i.e. exactly the same as Direct Form 1
10 Nov'08
Comp30291 DMP Section 5
20
Program to implement Direct Form II using normal arithmetic
W1 = 0; W2 = 0;
%For delay boxes
while 1
X = input(‘X=’) ;
% Input to X
W =X - b1*W1 - b2*W2;
% Recursive part
Y = W*a0 + W1*a1 + W2*a2; % Non-rec. part
W2 = W1;
W1 = W;
% For next time
disp(sprintf(‘Y=%f’,Y)); % Output Y using disp
end;
% Back for next sample
10 Nov'08
Comp30291 DMP Section 5
21
Direct Form II in fixed point arithmetic with shifting
K=1024;
A0=round(a0*K); A1=round(a1*K); A2=round(a2*K);
B1=round(b1*K); B2=round(b2*K);
W1 = 0; W2 = 0;
%For delay boxes
while 1
X = input(‘X=’) ;
% Assign X to input
W =K*X - B1*W1 - B2*W2;
% Recursive part
W =round( W / K);
% By arith right-shift
Y = W*A0+W1*A1+W2*A2; % Non-rec. part
W2 = W1;
W1 = W;
%For next time
Y = round(Y/K);
%By arith right-shift
disp(sprintf( ‘Y=%f’, Y)); %Output Y using disp
end;
% Back for next sample
10 Nov'08
Comp30291 DMP Section 5
22
Poles & zeros of H(z)
• For a discrete time filter:
a0  a1 z 1  a2 z 2  ...  aN z  N
H ( z) 
b0  b1 z 1  b2 z 2  ...  bM z M
with b0  1
• Re-express as:
H ( z)  z
M N
a0 z N  a1 z N 1  a2 z N 2  ...  aN
z M  b1 z M 1  b2 z M 2  ...  bM
• Now factorise numerator & denominator:
H ( z )  a0 z
10 Nov'08
M N
( z  z1 )(z  z2 )...(z  z N )
( z  p1 )(z  p2 )...(z  pM )
Comp30291 DMP Section 5
23
Poles & zeros of H(z) continued
• z 1 , z 2 ,..., z N , are ‘zeros’.
p 1 ,p 2 ,..., p N , are ‘poles’.
• H(z) generally infinite with z equal to a pole.
• H(z) generally zero with z equal to a zero.
• For a causal stable system all poles must satisfy  p i  < 1.
i.e. on Argand diagram: poles must lie inside unit circle.
• No restriction on the positions of zeros.
10 Nov'08
Comp30291 DMP Section 5
24
Design of IIR ‘notch’ filter
• Design a 4th order 'notch' filter to eliminate an unwanted
sinusoid at 800 Hz without severely affecting rest of signal. The
sampling rate is FS = 10 kHz.
• One way is to use the MATLAB function ‘butter’ as follows:
FL = 800 – 25 ; FU = 800+25;
[a b] = butter(2, [FL FU]/(FS/2),’stop’);
a = [0.98 -3.43 4.96 -3.43 0.98]
b= [ 1 -3.47 4.96 -3.39 0.96]
freqz(a, b);
freqz(a, b, 512, FS);
% Better graph
axis([0 FS/2 -50 5]); % Scales axes
MATLAB
response
• Notch has -3 dB frequency band: 25 + 25 = 50 Hz.
10 Nov'08
Comp30291 DMP Section 5
25
Gain/phase response of notch filter
Magnitude (dB)
0
-20
-40
0
500
1000
1500
2000 2500 3000
Frequency (Hz)
3500
4000
4500
5000
0
500
1000
1500
2000 2500 3000
Frequency (Hz)
3500
4000
4500
5000
Phase (degrees)
0
-100
-200
-300
-400
10 Nov'08
Comp30291 DMP Section 5
26
Magnitude (dB)
Gain/phase responses of notch filter
0
-20
-40
Phase (degrees)
0
500
1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency (Hz)
500
1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency (Hz)
0
-100
-200
-300
-400
0
10 Nov'08
Comp30291 DMP Section 5
27
Details
• How sharp is the notch?
• Can answer this question by specifying notch’s -3 dB bandwidth.
• Have just designed what Barry calls a 4th order band-stop filter.
• MATLAB calls it a 2nd order band-stop filter.
• For a sharper notch, decrease -3 dB bandwidth
• But this will decrease its ‘depth’,
i.e. the attenuation at the ‘notch’ frequency.
• If necessary, increase the order to 6 (3) or 8 (4).
10 Nov'08
Comp30291 DMP Section 5
28
Sketch the same gain-response
• The -3dB frequencies are at ( 800 +  ) and ( 800 -  ) Hz.
• Given  (= 25 Hz say) can sketch gain-response:
Gain
1
0 dB
0.5
-3 dB
F
0
FS/2
800 - 
10 Nov'08
800
800 + 
Comp30291 DMP Section 5
29
Implement the 4th order ‘notch’ filter
MATLAB function gave us:
a = [0.98 -3.43 4.96 -3.43 0.98]
b= [ 1 -3.47 4.96 -3.39 0.96]
Transfer (System) Function is:
 0.98  3.43z 1  4.96z 2  3.43z 3  0.98z 4
H z   
1
2
3
4
1

3
.
47
z

4
.
96
z

3
.
39
z

0
.
96
z

10 Nov'08
Comp30291 DMP Section 5
30



A direct Form 2 implementation of the 4th order IIR notch filter
x[n]
+
+
z-1
3.47
+
0.98
-3.43
-4.96
y[n]
+
z-1
+
+
4.96
z-1
+
3.39
-0.96
z-1
-3.43
+
0.0.98
10 Nov'08
Comp30291 DMP Section 5
31
Problems with ‘direct form’ IIR implementations
•Implementation on previous slide works fine in MATLAB.
•But ‘direct form’ IIR implementations of order >2 are rarely used.
•Sensitivity to round-off error in coeff values will be high.
•Also range of ‘intermediate’ signals in z-1 boxes is high.
•High wordlength floating point arithmetic hides this problem
•But in fixed point arithmetic, great difficulty occurs.
•Instead we use ‘cascaded biquad sections’
10 Nov'08
Comp30291 DMP Section 5
32
Using biquad (2nd order) IIR sections
Given 4th order H(z), instead of:
x[n]
y[n]
H(z)
we prefer to arrange two biquad sectns as follows:
G
x[n]
10 Nov'08
H1(z)
H2(z)
Comp30291 DMP Section 5
y[n]
33
Converting to the new implementation
• Get a & b for 4th order H(z) as before:
[a b] = butter(2, [FL FU]/(FS/2),’stop’);
• Then execute:
Transfer function
[SOS G] = tf2sos(a,b)
to 2nd order sectns
• MATLAB responds with:
First sectn
SOS = 1 -1.753 1 1 -1.722 0.9776
nd sectn
2
1 -1.753 1 1 -1.744 0.9785
G = 0.978
10 Nov'08
Comp30291 DMP Section 5
34
H(z) may now be realised as:
x[n]
y[n]
0.978
1.722
-1.753
-0.978
1.744
-1.753
-0.979
Fourth order IIR notch filter realised as two biquad (SOS) sections
10 Nov'08
Comp30291 DMP Section 5
35
Example
A digital filter with a sampling rate of 200 Hz is required to
eliminate an unwanted 50 Hz sinusoidal component of an input
signal without affecting the magnitudes of other components
too severely. Design a 4th order "notch" filter for this purpose
whose 3dB bandwidth is not greater than 3.2 Hz.
Solution method:
FS=200; FL=50-1.6; FU=50+1.6;
[a b]=butter(2,[FL,FU]/(FS/2), ‘stop’);
[SOS G] = tf2sos(a,b)
10 Nov'08
Comp30291 DMP Section 5
36
IIR digital filter design by bilinear transformation
• Many design techniques for IIR digital filters have
adopted ideas of analogue filters.
• Can transform analogue ‘prototype’ transfer function Ha(s) into
H(z) for an IIR digital filter.
• Analogue filters have infinite impulse-responses.
• Many gain-response approximations exist which are realisable
by analogue filters
• e.g. Butterworth low-pass approximation which can be
transformed to high-pass, band-pass & band-stop.
10 Nov'08
Comp30291 DMP Section 5
37
Butterworth low-pass gain approximation of order n
Ga ( ) 
1
1  ( / C ) 2n
Butterworth LP gain responses (Cut-off = 1)
1
n=2
n=4
n=7
0.9
0.8
Gain(absolute)
0.7
At C , Gain  0.71
i.e -3 dB
0.6
0.5
0.4
0.3
0.2
0.1
0
10 Nov'08
0
0.5
1
1.5
3
2.5
2
Freq (radians/s)
3.5
Comp30291 DMP Section 5
4
4.5
5
38
Transformations from Ha(s) to H(z) for IIR digital filter
• Can transform Ha(s), with gain-response Ga(), to H(z)
for an IIR digital filter with similar gain-response G().
• Many ways exist.
• Most famous is ‘bilinear transformation’.
• Replaces s by 2(z-1)/(z+1) to transform Ha(s) to H(z).
• Fortunately MATLAB does all this for us.
10 Nov'08
Comp30291 DMP Section 5
39
Properties of bilinear transformation
(i) Order of H(z) = order of Ha(s)
(ii) If Ha(s) is causal & stable, so is H(z).
(iii) G() = Ga() where  = 2 tan(/2)
So gain of analog filter at  radians/second becomes gain of digital
filter at  radians/sample where  = 2tan( /2).
10 Nov'08
Comp30291 DMP Section 5
40
Frequency warping
By (iii),  from - to  mapped to  in range - to .
Radians/sample
3.14
2.355

1.57
0.785
Radians/second
0
-12
-10
-8
-6
-4
-2
0
-0.785
2
-1.57
4
6
8
10
12

-2.355
-3.14
10 Nov'08
Comp30291 DMP Section 5
41
Frequency warping (cont)
• Shape of G() will change under the transformation.
• If Ga() is Butterworth, G() will not have exactly the same
shape, but we still call it Butterworth.
• Mapping approx linear for  in the range -2 to 2.
• As  increases above 2 , a given increase in  produces
smaller and smaller increases in .
10 Nov'08
Comp30291 DMP Section 5
42
Comparing Ga() with G()
• G() becomes more and more compressed as   .
• Illustrate for an analog gain-response with ripples:
G()
Ga()


(a): Analogue gain response
10 Nov'08

/2

(b): Effect of bilinear transformation
Comp30291 DMP Section 5
43
‘Prototype’ analogue transfer function
• Although the shape changes, we would like G() at its cut
off C to the same as Ga() at its cut-off frequency.
• If Ga() is Butterworth, it is -3dB at its cut-off freq
• So we would like G() to be -3 dB at its cut-off C.
• Achieved if analogue prototype is designed to have its cutoff frequency at C = 2 tan(C/2).
• C is the ‘pre-warped’ cut-off frequency.
• Designing analog prototype with cut-off freq 2 tan(C/2)
guarantees that the digital filter will have its cut-off at C.
10 Nov'08
Comp30291 DMP Section 5
44
Design 2nd order IIR lowpass digital filter by bilinear transfm
• Let required cut-off frequency C = /4 radians/sample.
• Need prototype transfer fn Ha(s) for 2nd order Butt low-pass filter
with 3 dB cut-off at 2tan(C/2) = 2 tan(/8) radians/second.
• C = 2 tan(/8) = 0.828
• I happen to remember that the transfer fn for a 2nd order Butt lowpass filter with cut-off C is:
1
H a ( s) 
1  2 ( s / C )  ( s / C ) 2
• If you don’t believe me, check that replacing s by j and taking
the modulus gives G() = 1/[1+(/C)2n] with n=2.
• Set C = 0.828 in this formula, then replace s by 2(z-1)/(z+1).
• Gives us H(z) for an IIR digital filter. That’s it!
10 Nov'08
Comp30291 DMP Section 5
45
Resulting IIR digital filter


z 2  2z 1
1  2 z 1  z 2

H ( z) 
 0.098
2
1
2 
10.2 z  9.6 z  3.4
 1  0.94z  0.33z 
x[n]
y[n]
0.098
0.94
2
-0.33
-
10 Nov'08
Comp30291 DMP Section 5
46
Design of 2nd order IIR low-pass digital filter by bilinear
transform using MATLAB
• If required cut-off freq is /4 radians/sample, type:
[a b] = butter(2, 0.25)
• MATLAB gives us:
a = [0.098 0.196 0.098]
b = [1 -0.94 0.33]
The required expression for H(z) is therefore:
0.098 0.196z 1  0.098z 2
H ( z) 
1  0.94z 1  0.33z 2
To save multipliers it is a good idea to re-express this as:
1  2 z 1  z 2
H ( z )  0.098
1  0.94z 1  0.33z 2
10 Nov'08
Comp30291 DMP Section 5
47
Realise by ‘direct form 2’ signal-flow graph
H z 
x[n]


1  2 z 1  z 2

 0.098
1
2 
 1  0.94z  0.33z 
y[n]
0.098
0.94
2
-0.33
10 Nov'08
Comp30291 DMP Section 5
48
Higher order IIR digital filters
Example: Design 4th order Butterwth-type IIR low-pass digital filter
with 3 dB c/o at fS / 16. .
Solution: Relative cut-off frequency is /8. Typing:
[a b] = butter(4, 0.125)
gives the response:
a = 0.0009 0.0037 0.0056 0.0037 0.0009

b = 1 -2.9768 3.4223 -1.7861
0.3556
 0.00093 0.0037z 1  .0056z 2  .0037z 3  0.00093z 4
H z   
1
2
3
4
1

2
.
977
z

3
.
422
z

1
.
786
z

0
.
3556
z


1  4 z 1  6 z 2  4 z 3  z 4
 0.00093
1
2
3
4
1

2
.
977
z

3
.
422
z

1
.
786
z

0
.
3556
z

10 Nov'08
Comp30291 DMP Section 5
49






A direct Form 2 implementation of 4th order IIR filter
x[n]
+
+
2.977
z-1
+
0.00093
0.0037
-3.422
y[n]
+
z-1
+
+
0.0056
z-1
+
1.79
-0.356
z-1
0.0037
+
0.00093
10 Nov'08
Comp30291 DMP Section 5
50
Better ‘direct Form 2’ implementation of 4th order IIR filter
x[n]
+
+
0.00093
z-1
y[n]
2.977
+
4
+
z-1
-3.422
+
+
6
z-1
+
1.79
-0.356
10 Nov'08
z-1
Comp30291 DMP Section 5
4
+
51
Cascaded bi-quad sections
• Higher order IIR digital filters not normally implemented in Direct
Form 1 or 2.
• Instead, implement as cascaded biquad (sos) sections by typing:
[a b] = butter(4, 0.125);
[sos G] = tf2sos(a,b)
• MATLAB responds with:

‘transfer function’ to
sos = 1 2 1 1 -1.365 0.478
‘second order sections’
1 2 1 1 -1.612 0.745
G = 0.00093
 z 2  2z 1  

z 2  2z 1
. 2

H z   0.00093 2
 z  1.6 z  0.74   z  1.365z  0.48 
10 Nov'08
Comp30291 DMP Section 5
52
H(z) may be realised as:
x[n]
y[n]
0.00093
1.6
2
1.36
2
-0.74
-0.48
Fourth order IIR Butterworth filter with cut -off fs/16
10 Nov'08
Comp30291 DMP Section 5
53
Better realisation of H(z)
•At =0, gain of 1st section is (1+2+1)/(1-1.612+0.0745) =30.12
•At =0, gain of 2nd section is (1+2+1)/(1-1.365+0.488) = 35.56
•Make gain of each section one at =0 by scaling as follows:
x[n]
y[n]
0.028
0.033
1.6
2
1.36
2
-0.74
1/30.12
1/35.56
-0.48
Fourth order IIR Butterworth filter with cut-off Fs/16
10 Nov'08
Comp30291 DMP Section 5
54
Gain-responses for 4th order analog & IIR digital filter
1.1
0.9
0.7
Analogue gain resp.
Gain
0.5
0.3
Radians/second
0.1
-0.1 0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
1.1
0.9
0.7
Gain
0.5
Gain response of 4th order IIR filter
0.3
Radians/sample
0.1
-0.1 0
10 Nov'08
0.785
1.57
Comp30291 DMP Section 5
2.355
3.14
55
Compare gain-response of 4th order Butt low-pass transfer
function used as a prototype, with that of derived digital filter.
• Both are 1 (0 dB) at zero frequency.
• Both are 0.707 (-3 dB) at the cut-off frequency.
• Analogue gain approaches 0 as    whereas digital filter
gain becomes exactly zero at  = .
• Shape of Butt gain response is "warped" by bilinear transfn.
• For digital filter, cut-off rate becomes sharper as   
because of the compression as   .
10 Nov'08
Comp30291 DMP Section 5
56
High-pass band-pass and band-stop IIR filters
Example: 2nd (4th)order bandpass filter with  L = /4 ,  u = /2.
Solution:
[a b] = butter(2,[0.25 0.5])
a = 0.098
0 -0.195
0 0.098
b = 1 -1.219 1.333 -0.667 0.33
freqz(a,b);
[sos G] = tf2sos(a,b)
sos = 1 2 1 1 -0.1665 0.5348
1 -2 1 1 -1.0524 0.6232
G = 0.098
Many people call this 4th order - MATLAB calls it 2nd order.
10 Nov'08
Comp30291 DMP Section 5
57
Magnitude (dB)
2nd (4th) order IIR bandpass
-10
-20
-30
-40
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)
0.9
Phase (degrees)
200
100
0
-100
-200
10 Nov'08
0
Comp30291 DMP Section 5
1
58
Arranged as 2 biquad sections

 1  2 z 1  z 2

1  2 z 1  z 2


H ( z )  0.1
1
1 
1
2 
 1  0.17z  0.54z  1  1.05z  0.62z 
x[n]
y[n]
1
0.1
.17
-2
1.05
2
-0.54
-0.62
10 Nov'08
Comp30291 DMP Section 5
59
Higher order band-stop IIR filter
Example: 4th (8th)order bandpass filter with  L = /4 ,  u = /2.
Solution:
[a b] = butter(4,[0.25 0.5],’stop’)
a = 0.35 -1.15 2.815 -4.24 5.1 -4.24 2.815 -1.15 0.35
b = 1 -2.472 4.309 -4.886 4.477 -2.914 1.519 -0.5 0.12
freqz(a,b);
[sos G] = tf2sos(a,b)
sos =1 -.828 1 1 -0.351 0.428
1 -.828 1 1 -0.832 0.49
1 -.828 1 1 -0.046 0.724
1 -0.828 1 1 -1.244 0.793
G = 0.347
10 Nov'08
Comp30291 DMP Section 5
60
Gain & phase resp of IIR band-stop filter
Magnitude (dB)
0
-10
-20
-30
-40
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)
0.9
1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)
0.9
1
Phase (degrees)
0
-200
-400
-600
-800
10 Nov'08
Comp30291 DMP Section 5
61
Band-pass as arrangement of 4 ‘sos’ biquads
H1(z)
H2(z)
H3(z)
H4(z)
• Careful with scaling for band-pass & high-pass sections
• Can make gain =1 in pass-band for each section.
• Not at =0 this time !!!
10 Nov'08
Comp30291 DMP Section 5
62
Transfer-function to second order sections: ‘tf2sos’
•. Must use
[sos G] = tf2sos ([a4 a3 a2 a1 a0], [b4 … b0 ])
• ‘help tf2sos’ to find out abt this function
10 Nov'08
Comp30291 DMP Section 5
63
Wide-band band-pass & band-stop filters
•Option of cascading high pass & low-pass digital filters to
give band-pass or band-stop filters must be used with care.
•It is much simpler & avoids the factorisation problem.
•Then make sure that analogue prototype is wide-band
• High-pass IIR filters are designed by:
[a b] = butter(4,0.125,’high’);
10 Nov'08
Comp30291 DMP Section 5
64
Comparison of IIR and FIR digital filters
Advantage of IIR type digital filters:
Economical in use of delays, multipliers and adders.
Disadvantages:
(1) Sensitive to coefficient round-off inaccuracies
& effects of overflow in fixed point arith.
These effects can lead to instability or serious distortion.
(2) An IIR filter cannot be exactly linear phase.
10 Nov'08
Comp30291 DMP Section 5
65
Advantages of FIR filters:
(1) may be realised by non-recursive structures which are simpler
and more convenient for programming especially on devices
specifically designed for DSP.
(2) FIR structures are always stable.
(3) Because there is no recursion, round-off and overflow errors
are easily controlled.
(4) An FIR filter can be exactly linear phase.
Disadvantage of FIR filters:
Large orders can be required to perform fairly simple filtering
tasks.
10 Nov'08
Comp30291 DMP Section 5
66
Problems
1 Find H(z) for the following difference equations
(a) y[n] = 2x[n] - 3x[n-1] + 6x[n-4]
(b) y[n] = x[n-1] - y[n-1] - 0.5y[n-2]
2 Show that passing {x[n]} thro’ H(z) = z - 1 produces {x[n-1]}.
3. Give difference equation & give a signal-flow graph for:
1 + 3 z - 1 + 2z - 2
H(z) =

1 + 0.9z - 1
Plot poles & zeros & roughly sketch its gain response.
4 Calculate the impulse response of the digital filter with
1
H(z) = 
1 - 2 z -1
Draw its signal flow graph, plot its poles and zeros and comment on them.
5. Plot poles & zeros for the following difference equation:
y[n] = x[n] - 0.9x[n-1] + 0.81x[n-2] + 0.95y[n-1] - 0.9025y[n-2]
on z-plane and estimate gain and phase responses
10 Nov'08
Comp30291 DMP Section 5
67
6 Write high level language program, or give flow diagram to
implement difference equation given in Prob. 2.6.
7. Modify your program for prob 7 so that it uses only integers.
8. If LTI systems L1 & L2, with imp-responses {h1[n]} & {h2[n]}
are arranged as below, calculate overall impulse- response.
Show that this is affected by interchanging L1 & L2 .
y[n]
x[n]
L1
{ h 1 [n] }
L2
{ h 2 [n] }
9. A 3rd order low-pass IIR filter is required with 3 dB cut-off at f S /4. Apply
bilinear transfn to design it & give its signal flow graph as 2nd & 1st order
sections in cascade.
10. Give program to implement 3rd order IIR filter above in floating
point arithmetic. Then do it in fixed point arithmetic.
11. Low-pass IIR digital filter required with cut-off at f s/4 & stop-band
attenuation at least 20 dB for all frequencies above 3f s /8 & below f s /2.
Design by bilinear transfn using MATLAB.
10 Nov'08
Comp30291 DMP Section 5
68
12. Design a 4th order band-pass IIR digital filter with lower & upper cut-off
frequencies at 300 Hz & 3400 Hz when fS = 8 kHz.
13. Design a 4th order band-pass IIR digital filter with lower & upper cut-off
frequencies at 2000 Hz & 3000 Hz when fS = 8 kHz.
14. What limits how good a notch filter we can implement on a fixed point DSP
processor? In theory we can make notch sharper & sharper by moving
poles closer & closer to zeros. What limits us in practice. I wonder how
sharp a notch we could get in 16-bit fixed pt arithmetic?
15. What order of FIR filter would be required to implement a /4 notch
approximately as good as a 2nd order IIR /4 notch with 3 dB bandwidth
0.2 radians/sample?
16. What order of FIR low-pass filter would be required to be approx as good
as the 2nd order IIR low-pass filter (/4 cut-off) designed in these notes?
10 Nov'08
Comp30291 DMP Section 5
69