Upload
todd-hicks
View
253
Download
6
Tags:
Embed Size (px)
Citation preview
Lecture 10aLecture 10a
Infinite Impulse Response (IIR) FiltersInfinite Impulse Response (IIR) Filters
2
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.
Implementation in Matlab, C.Implementation in Matlab, C. ChaissiangChaissiang
R - DSP Applications Using C and the R - DSP Applications Using C and the TMS320C6x DSK, Chapter 5TMS320C6x DSK, Chapter 5
3
IntroductionIntroduction
Infinite Impulse Response (IIR) filters are the first choice when:Infinite Impulse Response (IIR) filters are the first choice when: Speed is paramount.Speed is paramount. Phase non-linearity is acceptable.Phase non-linearity is acceptable.
IIR filters are computationally more efficient than FIR filters as they require fewer coefficients due to the IIR filters are computationally more efficient than FIR filters as they require fewer coefficients due to the fact that they use feedback or poles.fact that they use feedback or poles.
However feedback can result in the filter becoming unstable if the coefficients deviate from their true However feedback can result in the filter becoming unstable if the coefficients deviate from their true values.values.
4
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:
M
k
kk
N
k
kk
MM
NN
za
zb
zaza
zbzbbzH
1
0
11
110
1
1
aakk and b and bkk are the filter coefficients. are the filter coefficients.
5
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:
zXzY
pzpzpz
zzzzzzkzH
N
N
21
21
Where:Where: zz11, z, z22, …, z, …, zNN are the zeros, are the zeros,
pp11, p, p22, …, p, …, pNN are the poles. are the poles.
6
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:
zXzY
pzpzpz
zzzzzzkzH
N
N
21
21
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
7
Properties of an IIR FilterProperties of an IIR Filter
M
k
N
k
knykaknxkbny10
x(n)+b0
+b1
+b2
+
+
+
a1
a2
z -1
y(n)
z -1
z -1
z -1
IIR EquationIIR Equation
IIR structure for N = M = 2IIR structure for N = M = 2
8
Design ProcedureDesign Procedure To fully design and implement a filter five steps are required:To fully design and implement a filter five steps are required:
(1)(1) Filter specification.Filter specification.
(2)(2) Coefficient calculation.Coefficient calculation.
(3)(3) Structure selection.Structure selection.
(4)(4) Simulation (optional).Simulation (optional).
(5)(5) Implementation.Implementation.
9
Filter Specification - Step 1Filter Specification - Step 1
(a)
1
f(norm)fc : cut-off frequency
pass-band stop-band
pass-band stop-bandtransition band
1
s
pass-bandripple
stop-bandripple
fpb : pass-band frequency
fsb : stop-band frequency
f(norm)
(b)
p1
s
p0
-3
p1
fs/2
fc : cut-off frequency
fs/2
|H(f)|(dB)
|H(f)|(linear)
|H(f)|
10
Coefficient Calculation - Step 2Coefficient Calculation - Step 2
There are two different methods available for calculating the coefficients:There are two different methods available 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.
11
Placement MethodPlacement Method
All that is required for this method is the knowledge that:All that is required for this method is the knowledge that: Placing a zero near or on the unit circle in the z-plane will minimise the transfer function at this point.Placing a zero near or on the unit circle in the z-plane will minimise the transfer function at this point. Placing a pole near or on the unit circle in the z-plane will maximise the transfer function at this point.Placing a pole near or on the unit circle in the z-plane will maximise the transfer function at this point. To obtain real coefficients the poles and zeros must either be real or occur in complex conjugate pairs.To obtain real coefficients the poles and zeros must either be real or occur in complex conjugate pairs.
12
Placement MethodPlacement Method
Example - Placement method:Example - Placement method:
Link: Link: zeropole.exezeropole.exe
13
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 well-established analysis analogue filters with well-established analysis methods.methods.
The method involves designing an analogue The method involves designing an analogue filter and then transforming it to a digital filter and then transforming it to a digital filter.filter.
The two principle methods are:The two principle methods are: Bilinear transform method (Bilinear transform method (Bilinear Bilinear Theory.pdfTheory.pdf).). Impulse invariant method.Impulse invariant method.
14
Bilinear Transform MethodBilinear Transform Method Practical example of the bilinear transform method:Practical example of the bilinear transform method:
The design of a digital filter to approximate a second order low-pass analogue filter is required.The design of a digital filter to approximate a second order low-pass analogue filter is required. The transfer function that describes the analogue filter is:The transfer function that describes the analogue filter is:
The digital filter is required to have:The digital filter is required to have: Cut-off frequency of 6kHz.Cut-off frequency of 6kHz. Sampling frequency of 20kHz.Sampling frequency of 20kHz.
12
12
ss
sH
15
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];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);
16
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, --1.3007e-016, 0.1716]aa = [1, --1.3007e-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]
a = (bb * 2a = (bb * 21515))HEXHEX = [0x7FFF, 0x0, 0x15F6] = [0x7FFF, 0x0, 0x15F6]
Note that 1 ~ (0x7FFF)Note that 1 ~ (0x7FFF)DECDEC
Use: Use: q152dec.mq152dec.m or or dec2q15.mdec2q15.m functions functions
17
Realisation Structures - Step 1Realisation Structures - Step 1
Direct Form I:Direct Form I:
M
M
NN
M
k
kk
N
k
kk
zaza
zbzbb
za
zb
zX
zYzH
11
110
1
0
11
Difference equation:Difference equation:
M
kk
N
kk knyaknxbny
10
This leads to the following structure…This leads to the following structure…
18
Realisation Structures - Step 2Realisation Structures - Step 2
Direct Form I:Direct Form I:x(n)
+b0
+b1
+b2
+bN-1
+bN
+
+
+
+
+
a1
a2
aM-1
aM
z -1
y(n)
z -1
z -1z -1
z -1
z -1
19
Realisation Structures - Step 3Realisation Structures - Step 3 Direct Form II canonic realisation:Direct Form II canonic realisation:
zPzY
zX
zP
zb
za
zHzHzHN
k
kkM
k
kk
MNfor ;
1
1
0
1
21
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 z-transform of P(z) and Y(z) leads to:Taking the inverse of the z-transform of P(z) and Y(z) leads to:
20
Realisation Structures - Step 4Realisation Structures - Step 4
Direct Form II canonic realisation:Direct Form II canonic realisation:
+b 0
+b 1
z -1
+b 2
+b N
-a 1
-a 2
-a N
+
+
+
+
y(n)x(n) P (n)
z -1
z -1
P (n-1)
P (n-2)
P (n-N)
21
Implementation - Step 5Implementation - Step 5
void 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;
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;}
‘‘C’ codeC’ code
22
IIR CodeIIR Code
Code location:Code location: Lecture 10 - Infinite Impulse Response FiltersLecture 10 - Infinite Impulse Response Filters
Projects:Projects: Fixed Point in C:Fixed Point in C: \\IIR_C_FixedIIR_C_Fixed\\
Lecture 10aLecture 10a
Infinite Impulse Response (IIR) FiltersInfinite Impulse Response (IIR) Filters
- End -- End -