Infinite Implse Response Filters - IIR

DSP C5000
Chapter 15
Infinite Impulse Response (IIR)
Filter Implementation
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Filters

Rational Z transfer function
Q
H (z) 
N (z)
D(z)
 bi z

i
i 0
P
1

ak z
k
k 1

Linear difference equation
yn 
ESIEE, Slide 2
Q
P
i 0
k 1
 bi x n  i   a k y n  k
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Filters – Poles and Zeros

Roots of the numerator
Q
Q

bi z
i0
i

 b 0  1  ri z
1

i0
ri are the roots of the z polynomial with bi coefficients. H(z) is null when
z is equal to one of the values. They are called the zeroes of the filter
and often noted by zi .

Roots of the denominator
P
1

i 1
ai z
i
P

 1  r z 
1
i
i0
ri are the roots of the z polynomial with ai coefficients. H(z) tends to infinity
when z is close to one of these values. They are called the poles of the filters
and often noted by pi .
ESIEE, Slide 3
Copyright © 2003 Texas Instruments. All rights reserved.
Z Transfer Function

Define frequency behaviour of the filter
Consider a first order z rational filter:

H (z)
ze
j  Te

1  b1 z
1
1  a1 z
1

ze
j  Te
e
z  z1
z  p1

ze
j  Te
N   e
j N
D   e
j D

z1
D  
e
j  N   D

j n T e
magnitude
N ( )
N  
phase
D ( )
p1
H(z) can be evaluated for each
value n from 0 to 1 with 1 corres-
ponding to sampling frequency
ESIEE, Slide 4
Copyright © 2003 Texas Instruments. All rights reserved.
Z Transfer Function
ESIEE, Slide 5

We obtain the transfer function by evaluation
of the z transform on the unit circle

We can see that it is a minimum phase filter
(the phase comes back at 0 at Fe/2) because the
zero of the filter is inside the unit circle.
Copyright © 2003 Texas Instruments. All rights reserved.
Z Transfer Function
ESIEE, Slide 6

If we change the zero z1 to 1/ z1 we get the same
magnitude transfer function (up to a scale
factor) …

But a maximum phase filter (the phase goes to p at Fe/2) because now, the zero lies outside the
unit circle.
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Filter Synthesis

Starting from frequency specifications
(here low pass filter):




ESIEE, Slide 7
Fpass : passband end frequency,
Fstop : stopband start frequency,
Apass : maximum passband ripple,
Astop : minimum stopband attenuation.
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Filters Synthesis

Analog prototype with analog to digital
transformation (bilinear transform) :




Direct digital method : Yule Walker

ESIEE, Slide 8
Digital to analog frequency specification
transformation using prewarping
Analog filter prototype
Analog transfer function to digital transfer
function transformation using bilinear
transform.
Try to find the recursive filter of order N which
is as close as possible to the frequency specifications using the least square optimization
method.
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Filters Synthesis

Bilinear transform :


One to one map of analog frquencies to digital
frequencies.
Based on the approximation of the continuous
integral operator by the trapezoïdal method.
n
t
y(t ) 
Laplace
 x ( u ) du
yn 

Te
xk
2
k  

Z
transform
transform
Y (s) 
1
X (s)
Y (z) 
s
Equating integral operators,
we get the bilinear transform.
ESIEE, Slide 9
 x k 1 
s
2 1 z
1
Te 1  z
1
Te 1  z
1
2 1 z
1
X (z)
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Filters Synthesis

Bilinear transform

s
s  j

Maps the stability region of the Laplace plane inside
the unit circle of the complex plane
2 1 z
1
Te 1  z
1
j
ze
j  Te
e
j T e
  Te 
 
tan 

Te
 2 
2
ESIEE, Slide 10
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Filters Synthesis

Bilinear transform :
  Te 
 
tan 

Te
 2 
2

The one to one mapping
achieved by this transform
prevents aliasing.
j
e
j T e
 Te
ESIEE, Slide 11
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Filters Synthesis


Characteristics frequencies (Fp, Fa) of the
target specifications have to be warped.
This warped specifications is used to compute
an analog prototype using approximation
functions :





ESIEE, Slide 12
Butterworth
Chebyshev I
Chebyshev II
Elliptic
Then the analog prototype is tranformed into a
digital filter that matches target frequency
specification thanks to Bilinear Transform (BT)
(this cancels the warping introduce at the first
step).
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Characteristics

H(f)
2

1
 f 

1
 f 
 p
2N
Butterworth filters :
• Defined by its order N and its cut-off frequency fp.
• Monotonic magnitude transfer function.
Matlab commands:
• buttord : estimate the needed order
• butter : compute the digital filter from
analog prototype using warping and BT,
given the order and cut-off frequency.
Sample Matlab code
ESIEE, Slide 13
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Characteristics

H(f)
2
• Defined by its order N, its passband corner
1

1   TN
2
Chebyshev I filters :
2
 f 


 f 
 p
frequency fp and its passband ripple .
• Ripple in passband and monotonic in stopband.
Matlab commands:
• cheb1ord : estimate the needed order
• cheby1 : compute the digital filter from
analog prototype using warping and BT,
Given the order and passband ripple and
Corner frequency.
Sample Matlab code
TN( ) is a Chebyshev polynomial of order N
ESIEE, Slide 14
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Characteristics

H(f)
2
 1
Chebyshev II filters :
1
2 f 
2
1   T N  s 
 f 
• Defined by its order N, its stopband edge
frequency fs and its stopband attenuation .
• Monotonic in passband and ripple in stopband.
Matlab commands:
• cheb2ord : estimate the needed order
• cheby2 : compute the digital filter from
analog prototype using warping and BT,
Given the order and stopband attenuation
and edge frequency.
Sample Matlab code
TN( ) is a Chebyshev polynomial of order N
ESIEE, Slide 15
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Characteristics

H(f)
2
• Defined by its order N, its passband and stopband
1

1   RN
2
2




Elliptic filters :


f p fs 

f
edge frequencies, fp and fs, its passband ripple and
its stopband attenuation .
• Ripple in passband and in stopband.
Matlab commands:
• ellipord : estimate the needed order
• ellip : compute the digital filter from
analog prototype using warping and BT,
given the order, passband ripple, stopband
attenuation and center frequency.
Sample Matlab code
RN( ) is a Chebyshev rationnal polynomial of order N
ESIEE, Slide 16
Copyright © 2003 Texas Instruments. All rights reserved.
IIR Characteristics
    
ESIEE, Slide 17
   


Group delay

Characterize the phase distorsion (waveform
distorsion) introduced by the filter.
Copyright © 2003 Texas Instruments. All rights reserved.
IIR structure

Derived from difference equation
Q
Direct form I
yn 
 bi x n  i
i 0
b0
xn
z-1
z-1
z-1
z-1
ESIEE, Slide 18
-a1
b2
-a2
bQ-1

 ak ynk
k 1
yn
b1
b3
P
-a3
-aQ-1
z-1
H (z)  B(z)
1
A( z )
z-1
• non canonical form
z-1
z-1
Copyright © 2003 Texas Instruments. All rights reserved.
IIR structure
Direct form II
b0
xn
-a1
-a2
-a3
-aQ-1
ESIEE, Slide 19
z-1
z-1
z-1
z-1
b1
b2
yn
H (z) 
1
B(z)
A( z )
• Canonical form
b3
bQ-1
Copyright © 2003 Texas Instruments. All rights reserved.
IIR structure
Transposed direct form II
xn
b2
b1
b2
b3
bQ-1
ESIEE, Slide 20
yn
z-1
z-1
z-1
z-1
H (z) 
-a1
1
B(z)
A( z )
• Canonical form
-a2
-a3
-aQ-1
Copyright © 2003 Texas Instruments. All rights reserved.
IIR – Coefficients quantization

Finite precision of DSP involves coefficients
quantization:
Let consider the denominator of the transfer function with a k  a k  D a k , the kth
quantized coefficients and Dak the quantification error. Quantized
denominator is then:
A z   1 
Q 1
Q 1
a
k 1
k
z
k

 1 
pl z
1

l 1
The resulting quantified poles will disrupt the transfer function.
The higher order the polynomial is, the greater will be pertubation on its roots due
to quantization.
Following slides illustrate this fact:
• Next slide shows the transfer function of a 6th order direct form filter for
different quantification.
• Following one shows the transfer function obtained for the same filter and
same quantificaiton, but with a cascade structure of second order section, this
last structure is much less sensitive to quantization than the previous one.
ESIEE, Slide 21
Copyright © 2003 Texas Instruments. All rights reserved.
Direct structure
ESIEE, Slide 22
Copyright © 2003 Texas Instruments. All rights reserved.
Cascade structure of second order section
ESIEE, Slide 23
Copyright © 2003 Texas Instruments. All rights reserved.
IIR structure
This sensitivity to coefficients quantization
leads to second order cascade or parallel form.
Second order section is chosen to get the least
order together with complex conjugated roots.


4th order example:
Parallel form
Cascade form
c0
b 0  b1 z
1  a1 z
xn
1
 a2z
b 0  b1 z
1  a1 z
1
1
xn
2
B(z)
A( z )
ESIEE, Slide 24
 c0 
 a2z
i0
i1
1
 b2 z
 a2z
2
2
b 0  b1 z
1  a1 z
1
1
 b2 z
 a2z
2
2
yn
Spectral factorisation
2
bi 0  bi 1 z
 1 a
1  a1 z
1
yn
1
Partial fraction expansion
N 1
b 0  b1 z
z
1
A( z )
1
 ai2z
B(z)
N 1
 b0 
i0
1  bi 1 z
1
 bi 2 z
2
1  a i1 z
1
 ai2z
2
2
Copyright © 2003 Texas Instruments. All rights reserved.
IIR – Cascade structure

Cascade structure involves addressing two
problems :


ESIEE, Slide 25
Pairing: which zeros with which poles to form a
second order rational transfer function.
The goal will be minimize the overshoot caused
by the poles.
Ordering: which second order section will be
ahead and which one will be the last.
To answer to this question we will have consider
quantification noise and the way to minimize it.
Copyright © 2003 Texas Instruments. All rights reserved.
IIR – case study 1

Consider the following specification:

Using inverse Chebyshev approximation,
we get a 6th order filter (matlab commands)
[N,Wn]=CHEB2ORD(1800/8000,4000/8000,0.01,50);
[B,A]=CHEBY2(N,50,Wn)
ESIEE, Slide 26
Copyright © 2003 Texas Instruments. All rights reserved.
IIR – case study 2
Actual transfer function is obtained
with: freqz(B,A)
Plot of poles and zeros with:
zplane(A,B)
3 2 1
Pairing: complex conjugate poles closest to the unit circle (responsible for the greatest
overshoot) are paired with complex conjugate zeros closest in frequency (angle on unit
circle). Then the process iterate with the next complex conjugate closest to the unit circle.
This done with the following routine
ESIEE, Slide 27
Copyright © 2003 Texas Instruments. All rights reserved.
IIR – data quantization
For DSP, quantification noise appear when we truncate the accumulator to store its
high part. (en equivalent noise source)
Direct form II
one noise source
en
Transposed direct form II
two noise sources
b0
xn
z-1
-a1
z-1
-a2
yn
en
b2
xn
b1
yn
z-1
b1
b2
z-1
b2
Output noise power is reduced by the
ENB of the complete filter

2
e _ out

1
2
e
Fe
ESIEE, Slide 28
Fe / 2

 Fe / 2
B( f )
A( f )
df
-a1
-a2
Output noise power is only reduced by
the ENB of the denominator

2
e _ out

1
2
e
Fe
Fe / 2

 Fe / 2
1
df
A( f )
Copyright © 2003 Texas Instruments. All rights reserved.
IIR – scaling factor

wn
xn
-a1
-a2
a
z-1
z-1
wn
xn
-a1
-a2
z-1
z-1
Direct form II
b0
yn
This scale factor, a, is commonly
computed depending on the nature of
signal that will be process:
b1
b2
b0 /a
b1 /a
To prevent overflow when storing at the
node wn, we need a scale factor to have a
0 dB gain from input to this node.
Narrow band signal, in this case we use
L norm and we get:
a1 
1/a
yn
1 / A( f )

Wide band signal, we use L2 norm and we
get:
a2 
b2 /a
1
1
1 / A( f )
2
Futhermore we have: a 2
ESIEE, Slide 29
 a1
Copyright © 2003 Texas Instruments. All rights reserved.
IIR – ordering

Depend on:



Criteria for scale factor computation, L or L2
norm.
Which norm of the quantization noise we want
to minimize L max value) or L2 norm
(power).
Following rules could apply:
• L for scale factor and L2 for noise
ascending order of overshoot.
• L2 for scale factor and L for noise
descending order of overshoot.
If the same norm is used
ESIEE, Slide 30
no prefered order.
Copyright © 2003 Texas Instruments. All rights reserved.
Scale factor & ordering

6th filter example (look at this routine)
: quantization noise source
a0 
1
1 / A0  f
a1 
ESIEE, Slide 31
a3 

1
a 0 B 0  f  /  A 0  f  A1  f
 
a2 
b0
a 0a 1a 2
1
a 0a 1 B 0  f  B 1  f  /  A 0  f  A1  f  A 2  f
 
Copyright © 2003 Texas Instruments. All rights reserved.
IIR – coefficients coding

We have to choose the right Qn coding for the
coefficients.

For second order section, A(z) or B(z) can be written, if
we let their roots to be r e  j 
1  2 r cos   z



r z
2
2
Denominator: for stability we need |r|<1, so coefficients
belong to [-2,2].
Numerator, by using analog approximation function as
prototype we get zeros on the unit circle so |r|=1 and
coefficients also belong to [-2,2].
The right coding is then Q14 for 16 bits word.

ESIEE, Slide 32
1
Look at this routine which does the work fir the 6th order
filter.
Copyright © 2003 Texas Instruments. All rights reserved.
IIR – noise power
The noise power at the output of that 6th
order filter:

1
o e
2
2
Fe
e
2
e
2
1
Fe
1
Fe

Fe
0

Fe

Fe
0
0
2
2
2
a 1 a 2 a 3 H 0 ( f ) H 1 ( f ) H 2 ( f ) df
2
2
2
2
2
a 2 a 3 H 1 ( f ) H 2 ( f ) df
2
2
Second stage noise power
2
a 3 H 2 ( f ) df
2
First stage noise power
Third stage noise power
Input scale factor attenuates only the input signal not the quantization noise:
• the lower the scale factor is the worst the signal to noise ratio will be.
ESIEE, Slide 33
Copyright © 2003 Texas Instruments. All rights reserved.
IIR - computation

Evaluation of an order 2 direct form II is as follows:
ACC=x(n)  a0
Q29=Q15  Q14
ACC=ACC - a1  w(n-1)
Q29=Q29 - (Q15  Q14)
ACC=ACC - a2  w(n-2)
Q29=Q29 - (Q15  Q14)
ACC<<2
Q31=Q29  22
w(n)=ACCH
Q15
ACC=w(n)  b0
Q29=Q15  Q14
ACC=ACC + b2  w(n-2)
Q29=Q29 + (Q15  Q14)
ACC=ACC + b1  w(n-1)
Q29=Q29 + (Q15  Q14)
ACC<<2
Q31=Q29  22
y(n)=ACCH
Q15
w(n-2)=w(n-1)
w(n-1)=w(n)
ESIEE, Slide 34
Copyright © 2003 Texas Instruments. All rights reserved.
IIR – program on C54

Following program works on a sample by
sample basis and is C callable.
Memory managment
sect1
a
*AR2 memfilt
w1(n-1)
a11
w1(n-2)
a12
w2(n-1)
b12
w2(n-2)
*AR3
b11
b10
a21
a22
b22
b21
b20
ESIEE, Slide 35
Copyright © 2003 Texas Instruments. All rights reserved.
Follow on Activities for thr C5416 DSK

Laboratory 6 for the C5416 DSK


Laboratory 7 for the C5416 DSK


Implemements band stop and notch filters
using poles / zeroes and Bilinear Transform
(BLT).
Laboratory 8 for the C5416 DSK

ESIEE, Slide 36
Implemements high pass and low pass
Butterworth filters from 1st order to 6th order.
Looks at sharpness of cut off and stability of
IIR filters designed by placing poles and zeroes
and Bilinear Transform (BLT).
Copyright © 2003 Texas Instruments. All rights reserved.
Follow on Activities for thr C5510 DSK

Application 3 for the C5510 DSK

Uses IIR filter for reverberation


ESIEE, Slide 37
Simulates single and multiple reflections from
the walls of a room. Introduces the
configuration used for an Infinite Impulse
Response (IIR) filter.
The majority of the code is written in C, except
where the C code would be too slow and
assembly code is required
Copyright © 2003 Texas Instruments. All rights reserved.