Chapter 15Chapter 15Infinite Impulse Response (IIR) FiltersInfinite Impulse Response (IIR) Filters
Learning ObjectivesLearning Objectives
�� Introduction to the theory behind IIR Introduction to the theory behind IIR filters:filters:�� Properties.Properties.�� Coefficient calculation.Coefficient calculation.�� Structure selection.Structure selection.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 2
�� Implementation in Matlab, C and linear Implementation in Matlab, C and linear assembly.assembly.
IntroductionIntroduction
�� Infinite Impulse Response (IIR) filters are Infinite Impulse Response (IIR) filters are the first choice when:the first choice when:�� Speed is paramount.Speed is paramount.�� Phase nonPhase non--linearity is acceptable.linearity is acceptable.
�� IIR filters are computationally more IIR filters are computationally more
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 3
�� IIR filters are computationally more IIR filters are computationally more efficient than FIR filters as they require efficient than FIR filters as they require fewer coefficients due to the fact that they fewer coefficients due to the fact that they use feedback or poles.use feedback or poles.
�� However feedback can result in the filter However feedback can result in the filter becoming unstable if the coefficients becoming unstable if the coefficients deviate from their true values.deviate from their true values.
Properties of an IIR FilterProperties of an IIR Filter
�� The general equation of an IIR filter can The general equation of an IIR filter can be expressed as follows:be expressed as follows:
( )
∑−
−−
−−
++++++
=
Nk
k
MM
NN
zb
zaza
zbzbbzH
11
110
1 K
K
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 4
∑
∑
=
−
=
+=
M
k
kk
kk
za
zb
1
0
1
�� aakk and band bkk are the filter coefficients.are the filter coefficients.
Properties of an IIR FilterProperties of an IIR Filter
�� The transfer function can be factorised to The transfer function can be factorised to give:give:
( ) ( )( ) ( )( )( ) ( )
( )( )zX
zY
pzpzpz
zzzzzzkzH
N
N =−−−−−−
=L
L
21
21
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 5
�� Where:Where: zz11, z, z22, …, z, …, zNN are the zeros,are the zeros,pp11, p, p22, …, p, …, pNN are the poles.are the poles.
Properties of an IIR FilterProperties of an IIR Filter
�� The transfer function can be factorised to The transfer function can be factorised to give:give:
( ) ( )( ) ( )( )( ) ( )
( )( )zX
zY
pzpzpz
zzzzzzkzH
N
N =−−−−−−
=L
L
21
21
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 6
�� For the implementation of the above For the implementation of the above equation we need the difference equation:equation we need the difference equation:
[ ] [ ] [ ]
[ ] [ ]∑∑
∑
==
∞
=
−−−=
−=
M
kk
N
kk
k
knyaknxb
knxkhny
10
0
Properties of an IIR FilterProperties of an IIR Filter
[ ] [ ] [ ] [ ] [ ]∑∑==
−+−=M
k
N
k
knykaknxkbny10
x(n)+b0 +
y(n)
z-1z-1
IIR EquationIIR Equation
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 7
+b1
+b2
+
+
a1
a2
z-1
z-1
z-1
z-1
IIR structure for N = M = 2IIR structure for N = M = 2
Design ProcedureDesign Procedure
�� To fully design and implement a filter five To fully design and implement a filter five steps are required:steps are required:(1)(1) Filter specification.Filter specification.(2)(2) Coefficient calculation.Coefficient calculation.(3)(3) Structure selection.Structure selection.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 8
(4)(4) Simulation (optional).Simulation (optional).(5)(5) Implementation.Implementation.
Filter Specification Filter Specification -- Step 1Step 1
(a)
1
f(norm)fc : cut-off frequency
pass-band stop-band
fs/2
|H(f)|
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 9
pass-band stop-bandtransition band
1
sδ
pass-bandripple
stop-bandripple
fpb : pass-band frequency
fsb : stop-band frequencyf(norm)
(b)
p1 δ+
s∆
p∆0
-3
p1 δ−
fs/2
fc : cut-off frequency
|H(f)|(dB)
|H(f)|(linear)
Coefficient Calculation Coefficient Calculation -- Step 2Step 2
�� There are two different methods available There are two different methods available for calculating the coefficients:for calculating the coefficients:�� Direct placement of poles and zeros.Direct placement of poles and zeros.�� Using analogue filter design.Using analogue filter design.
�� Both of these methods are described.Both of these methods are described.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 10
�� Both of these methods are described.Both of these methods are described.
Placement MethodPlacement Method
�� All that is required for this method is the All that is required for this method is the knowledge that:knowledge that:�� Placing a zero near or on the unit circle in Placing a zero near or on the unit circle in
the zthe z--plane will minimise the transfer plane will minimise the transfer function at this point.function at this point.
�� Placing a pole near or on the unit circle in Placing a pole near or on the unit circle in
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 11
�� Placing a pole near or on the unit circle in Placing a pole near or on the unit circle in the zthe z--plane will maximise the transfer plane will maximise the transfer function at this point.function at this point.
�� To obtain real coefficients the poles and To obtain real coefficients the poles and zeros must either be real or occur in zeros must either be real or occur in complex conjugate pairs.complex conjugate pairs.
Placement MethodPlacement Method
�� Example Example -- Placement method:Placement method:
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 12
�� Link: Link: \\LinksLinks\\zeropole.exezeropole.exe
Analogue to Digital Filter ConversionAnalogue to Digital Filter Conversion
�� This is one of the simplest method.This is one of the simplest method.�� There is a rich collection of prototype There is a rich collection of prototype
analogue filters with wellanalogue filters with well--established established analysis methods.analysis methods.
�� The method involves designing an The method involves designing an analogue filter and then transforming it to analogue filter and then transforming it to
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 13
The method involves designing an The method involves designing an analogue filter and then transforming it to analogue filter and then transforming it to a digital filter.a digital filter.
�� The two principle methods are:The two principle methods are:�� Bilinear transform method Bilinear transform method
((\\LinksLinks\\Bilinear Theory.pdfBilinear Theory.pdf ).).�� Impulse invariant method.Impulse invariant method.
Bilinear Transform MethodBilinear Transform Method
�� Practical example of the bilinear Practical example of the bilinear transform method:transform method:�� The design of a digital filter to approximate a The design of a digital filter to approximate a
second order lowsecond order low--pass analogue filter is pass analogue filter is required.required.
�� The transfer function that describes the The transfer function that describes the
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 14
�� The transfer function that describes the The transfer function that describes the analogue filter is:analogue filter is:
�� The digital filter is required to have:The digital filter is required to have:�� CutCut--off frequency of 6kHz.off frequency of 6kHz.�� Sampling frequency of 20kHz.Sampling frequency of 20kHz.
( )12
12 ++
=ss
sH
Bilinear Transform MethodBilinear Transform Method
�� Matlab code for calculating coefficients:Matlab code for calculating coefficients:a = tan(pi*2/8) % cut-off 2kHz, fsample 8 kHz, input < 580 mVppb = (1 + 2^0.5 + (a*a))b00 = (a*a)/bb01 = 2*b00b02 = b00a01 = 2*(a^2 -1)/ba02 = (1 + a^2 - (2^0.5)*a)/b
bb = [b00 b01 b02];
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 15
bb = [b00 b01 b02];aa = [1 a01 a02];
figure(1)freqz(bb,aa,512,8000)
fid = fopen('IIR_coef_float.txt', 'w');fprintf(fid,'%0.4f,%0.4f,%0.4f\n',bb);fprintf(fid,'%0.4f,%0.4f\n',aa);
fclose(fid);
Bilinear Transform MethodBilinear Transform Method
�� Output from Matlab code:Output from Matlab code:�� bb = [0.2929, 0.5858, 0.2929]bb = [0.2929, 0.5858, 0.2929]�� aa = [1, aa = [1, ----1.3007e1.3007e--016, 0.1716]016, 0.1716]
�� Converting these to Q15 format we get:Converting these to Q15 format we get:�� b = (bb * 2b = (bb * 21515))HEXHEX = [0x257D, 0x4AFB, 0x257D]= [0x257D, 0x4AFB, 0x257D]
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 16
�� b = (bb * 2b = (bb * 21515))HEXHEX = [0x257D, 0x4AFB, 0x257D]= [0x257D, 0x4AFB, 0x257D]
�� a = (bb * 2a = (bb * 21515))HEXHEX = [0x7FFF, 0x0, 0x15F6]= [0x7FFF, 0x0, 0x15F6]
�� Note that 1 ~ (0x7FFF)Note that 1 ~ (0x7FFF)DECDEC
Realisation Structures Realisation Structures -- Step 3Step 3
�� Direct Form I:Direct Form I:
( ) ( )( ) M
M
NN
M
k
kk
N
k
kk
zaza
zbzbb
za
zb
zX
zYzH −−
−−
=
−
=
−
++++++
=+
==
∑
∑
K
K
11
110
1
0
11
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 17
�� Difference equation:Difference equation:
[ ] [ ] [ ]∑∑==
−−−=M
kk
N
kk knyaknxbny
10
�� This leads to the following structure…This leads to the following structure…
Realisation Structures Realisation Structures -- Step 3Step 3
�� Direct Form I:Direct Form I:x(n)
+b0
+b1
+
+ a1
-1
y(n)
z-1z-1
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 18
+b2
+bN-1
+bN
+
+
+
a2
aM-1
aM
z-1
z-1z-1
z-1
Realisation Structures Realisation Structures -- Step 3Step 3�� Direct Form II canonic realisation:Direct Form II canonic realisation:
( ) ( ) ( )
( )( )
( )( )zP
zY
zX
zP
zb
za
zHzHzHN
k
kkM
k
kk
⋅=
=+
== ∑∑
=
−
=
−MNfor ;
1
1
0
1
21
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 19
�� Where:Where:( )( )
( )( ) ∑
∑=
−
=
−=
+=
N
k
kkM
k
kk
zbzP
zY
zazX
zP
0
1
and
1
1
( ) ( )∑=
−=N
kk knpbny
0
( ) ( ) ( )∑=
−−=N
kk knpanxnp
1
�� Taking the inverse of the zTaking the inverse of the z--transform of transform of P(z) and Y(z) leads to:P(z) and Y(z) leads to:
Realisation Structures Realisation Structures -- Step 3Step 3
�� Direct Form II canonic realisation:Direct Form II canonic realisation:
+b0
+b1
z-1
-a1
+
+
y(n)x(n) P(n)
P(n-1)
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 20
+b2
+bN
-a2
-aN
+
+
z-1
z-1
P(n-2)
P(n-N)
Implementation Implementation -- Step 5Step 5void IIR_Isr (void){
short a1 = 0x0; short a2 = 0x15f6; short b0 = 0x257d;short b1 = 0x4afd;short b2 = 0x257d;static short d01=0, d02=0, d00;short xn, y0;int prod1, prod2, prod3, prod4, prod5, input, output;
input = mcbsp0_read(); // Read the input sample from the serial porty0 = 0;input &= 0xffff;
‘C’ code‘C’ code
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 21
input &= 0xffff;
xn = (short) (input & 0x000ffff);prod1 = _mpy(d02,a2)>>15;prod2 = _mpy(d01,a1)>>15;d00 = xn + (short)(prod1 + prod2);prod3 = _mpy(d01,b1);prod4 = _mpy(d02,b2);prod5 = _mpy(d00,b0);y0 = (short)((prod3+prod4+prod5)>>15);d02 = d01;d01 = d00;output = y0;
mcbsp0_write(output& 0xfffffffe); // Write the signal to the serial port return;
}
Implementation Implementation -- Step 5Step 5.def _iir_sa.sect "mycode"
_iir_sa .cproc an1, an2, bn0, bn1, bn2, delays, x_ptr, y_ptr,mask, mask2
.reg p0, p1, p2
.reg prod1, prod2, prod3, prod4, prod5
.reg sum1, sum2, sum3
.reg x, ref, y0,y1
LDW *x_ptr, xAND x,mask,xLDH *+delays[0], p1LDH *+delays[1], p2MPY an1, p1, prod1MPY an2, p2, prod2ADD prod1, prod2, sum1
Linear assembly Linear assembly codecode
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 22
ADD prod1, prod2, sum1SHR sum1, 15, sum1ADD x, sum1, p0MPY bn0, p0, prod3MPY bn1, p1, prod4MPY bn2, p2, prod5ADD prod4, prod5, sum2ADD prod3, sum2, sum3SHRU sum3, 15, y0
STH p1, *+delays[1]STH p0, *+delays[0]
AND y0, mask2, y0 STW y0, *y_ptr
.return y0
.endproc
IIR CodeIIR Code
�� Code location:Code location:�� CodeCode\\Chapter 15 Chapter 15 -- Infinite Impulse Response FiltersInfinite Impulse Response Filters
�� Projects:Projects:�� Fixed Point in C:Fixed Point in C: \\IIR_C_FixedIIR_C_Fixed\\�� Fixed Point in Linear Asm:Fixed Point in Linear Asm: \\IIR_Sa_FixedIIR_Sa_Fixed\\
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 15, Slide 23
Chapter 15Chapter 15Infinite Impulse Response (IIR) FiltersInfinite Impulse Response (IIR) Filters
-- End End --