Chapter14
-
Upload
shshokri1355 -
Category
Technology
-
view
200 -
download
3
Transcript of Chapter14
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 2
Learning ObjectivesLearning Objectives
Introduction to the theory behind FIR Introduction to the theory behind FIR filters:filters: Properties (including aliasing).Properties (including aliasing). Coefficient calculation.Coefficient calculation. Structure selection.Structure selection.
Implementation in Matlab, C, assembly Implementation in Matlab, C, assembly and linear assembly.and linear assembly.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 3
IntroductionIntroduction
Amongst all the obvious advantages that digital filters offer, the FIR filter can Amongst all the obvious advantages that digital filters offer, the FIR filter can guarantee linear phase characteristics.guarantee linear phase characteristics.
Neither analogue or IIR filters can achieve this.Neither analogue or IIR filters can achieve this. There are many commercially available software packages for filter design. However, There are many commercially available software packages for filter design. However,
without basic theoretical knowledge of the FIR filter, it will be difficult to use them.without basic theoretical knowledge of the FIR filter, it will be difficult to use them.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 4
Properties of an FIR FilterProperties of an FIR Filter
Filter coefficients:Filter coefficients:
1
0
N
kk knxbny
x[n] x[n] represents the filter input,represents the filter input,bbk k represents the filter coefficients,represents the filter coefficients,
y[n] y[n] represents the filter output,represents the filter output,NN is the number of filter coefficients is the number of filter coefficients
(order of the filter).(order of the filter).
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 5
Properties of an FIR FilterProperties of an FIR Filter
Filter coefficients:Filter coefficients:
1
0
N
kk knxbny
z-1
+
z-1 z-1
+ +
z-1
y(n)
x(n)
x xxxb0 b1 b2 bN-1
FIR equationFIR equation
Filter structureFilter structure
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 6
Properties of an FIR FilterProperties of an FIR Filter
Filter coefficients:Filter coefficients:
1
0
N
kk knxbny
If the signal x[n] is replaced by an impulse If the signal x[n] is replaced by an impulse [n] then: [n] then:
1
0
N
kk knbny
Nbbby k 100 10
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 7
Properties of an FIR FilterProperties of an FIR Filter
Filter coefficients:Filter coefficients:
1
0
N
kk knxbny
If the signal x[n] is replaced by an impulse If the signal x[n] is replaced by an impulse [n] then: [n] then:
1
0
N
kk knbny
Nnbnbnbny k 110
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 8
Properties of an FIR FilterProperties of an FIR Filter
Filter coefficients:Filter coefficients:
1
0
N
kk knxbny
If the signal x[n] is replaced by an impulse If the signal x[n] is replaced by an impulse [n] then: [n] then:
1
0
N
kk knbny
kn for 0
knfor 1kn
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 9
Properties of an FIR FilterProperties of an FIR Filter
Filter coefficients:Filter coefficients:
1
0
N
kk knxbny
Finally: Finally:
khb
hb
hb
k
1
0
1
0
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 10
Properties of an FIR FilterProperties of an FIR Filter
Filter coefficients:Filter coefficients:
1
0
N
kk knxbny
With: With: khbk
The coefficients of a filter are the same as The coefficients of a filter are the same as the impulse response samples of the filter.the impulse response samples of the filter.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 11
Frequency Response of an FIR FilterFrequency Response of an FIR Filter
By taking the z-transform of h[n], H(z):By taking the z-transform of h[n], H(z):
Replacing z by eReplacing z by ejj in order to find the in order to find the frequency response leads to:frequency response leads to:
1
0
N
n
nznhzH
1
0
N
n
jnj
ezenheHzH j
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 12
Frequency Response of an FIR FilterFrequency Response of an FIR Filter
Since eSince e-j2-j2kk = 1 then: = 1 then:
Therefore:Therefore:
1
0
1
0
22
N
n
jnN
n
jn
ezenhenhzH
jkj eHeH 2
FIR filters have a periodic frequency FIR filters have a periodic frequency response and the period is 2response and the period is 2..
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 13
Frequency Response of an FIR FilterFrequency Response of an FIR Filter
Frequency Frequency response:response:
FIRFIR y[n]y[n]x[n]x[n]
FFss/2/2FFss/2/2
FreqFreq
FreqFreq
x[n
]x[
n]
y[n
]y[
n]
jkj eHeH 2
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 14
Frequency Response of an FIR FilterFrequency Response of an FIR Filter
Solution: Use an anti-aliasing filter.Solution: Use an anti-aliasing filter.
FIRFIR y[n]y[n]x[n]x[n]ADCADC
Analogue Analogue Anti-AliasingAnti-Aliasing
x(t)x(t)
FFss/2/2FFss/2/2FreqFreqFreqFreq
x(t)
x(t)
y[n
]y[
n]
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 15
Phase Linearity of an FIR FilterPhase Linearity of an FIR Filter
A causal FIR filter whose impulse response is symmetrical is A causal FIR filter whose impulse response is symmetrical is guaranteed to have a linear phase response.guaranteed to have a linear phase response.
0n
h(n)
1 n n+1 2n+12n
N = 2n + 2
0n
h(n)
1 n n+1 2n2n-1n-1
N = 2n + 1
Even symmetryEven symmetry Odd symmetryOdd symmetry
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 16
Phase Linearity of an FIR FilterPhase Linearity of an FIR Filter
A causal FIR filter whose impulse response is symmetrical (ie h[n] = h[N-A causal FIR filter whose impulse response is symmetrical (ie h[n] = h[N-1-n] for n = 0, 1, …, N-1) is guaranteed to have a linear phase response.1-n] for n = 0, 1, …, N-1) is guaranteed to have a linear phase response.
Condition Phase
2
1Nk Phase Property Filter Type
1 nNhnh
Positive Symmetryk Linear phase
Odd Symmetry – Type 1
Even Symmetry – Type 2
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 17
Phase Linearity of an FIR FilterPhase Linearity of an FIR Filter
Application of 90° linear phase shift:Application of 90° linear phase shift:
Signal separationSignal separation
9090oo
delaydelay
9090oo
delaydelay
++
++
++
--
II
ReverseReverse
ForwardForward
IHIH
QHQH
tBtAI rf sincos
tBtAQ rf cossin tBtA
tBtAIH
rf
rf
cossin
2sin
2cos
tBQIH rcos2
tBIQH fsin2
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 18
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.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 19
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)|
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 20
Coefficient Calculation - Step 2Coefficient Calculation - Step 2 There are several different methods available, the most popular are:There are several different methods available, the most popular are:
Window method.Window method. Frequency sampling.Frequency sampling. Parks-McClellan.Parks-McClellan.
We will just consider the window method.We will just consider the window method.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 21
Window MethodWindow Method
First stage of this method is to calculate the coefficients of the First stage of this method is to calculate the coefficients of the ideal filterideal filter.. This is calculated as follows:This is calculated as follows:
0nfor
0nfor
2
sin2
12
1
2
1
c
c
cc
nj
njd
fn
nf
de
deHnh
c
c
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 22
Window MethodWindow Method Second stage of this method is to select a window function based on the passband or Second stage of this method is to select a window function based on the passband or
attenuation specifications, then determine the filter length based on the required width of the attenuation specifications, then determine the filter length based on the required width of the transition band.transition band.
W i n d o w T y p e N o r m a l i s e d T r a n s i t i o nW i d t h ( f ( H z ) )
P a s s b a n d R i p p l e ( d B ) S t o p b a n d A t t e n u a t i o n( d B )
R e c t a n g u l a rN
9.00 . 7 4 1 6 2 1
H a n n i n gN
1.30 . 0 5 4 6 4 4
H a m m i n gN
3.30 . 0 1 9 4 5 3
B l a c k m a nN
5.50 . 0 0 1 7 7 4
K a i s e r
54.493.2
N
96.871.5
N
0 . 0 2 7 4
0 . 0 0 0 2 7 5
5 0
9 0
13284.12.1
3.33.3
kHz
kHzfNUsing the Hamming Using the Hamming
Window:Window:
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 23
Window MethodWindow Method
The third stage is to calculate the set of truncated or windowed The third stage is to calculate the set of truncated or windowed impulse response coefficients, h[n]:impulse response coefficients, h[n]:
nWnhnh d even Nfor
odd Nfor
22
2
1
2
1
Nn
N
Nn
N
133
2cos46.054.0
2
cos46.054.0
n
N
nnW
forfor
Where:Where:6666 nforfor
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 24
Window MethodWindow Method
Matlab code for calculating coefficients:Matlab code for calculating coefficients:close all;clear all;
fc = 8000/44100; % cut-off frequencyN = 133; % number of tapsn = -((N-1)/2):((N-1)/2);n = n+(n==0)*eps; % avoiding division by zero
[h] = sin(n*2*pi*fc)./(n*pi); % generate sequence of ideal coefficients[w] = 0.54 + 0.46*cos(2*pi*n/N); % generate window functiond = h.*w; % window the ideal coefficients
[g,f] = freqz(d,1,512,44100); % transform into frequency domain for plotting
figure(1)plot(f,20*log10(abs(g))); % plot transfer functionaxis([0 2*10^4 -70 10]);
figure(2);stem(d); % plot coefficient valuesxlabel('Coefficient number');ylabel ('Value');title('Truncated Impulse Response');
figure(3)freqz(d,1,512,44100); % use freqz to plot magnitude and phase responseaxis([0 2*10^4 -70 10]);
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 25
Window MethodWindow Method
0 0.5 1 1.5 2
x 104
-6000
-4000
-2000
0
Frequency (Hz)
Pha
se (
degr
ees)
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
-60
-40
-20
0
Frequency (Hz)
Mag
nitu
de (
dB)
0 20 40 60 80 100 120 140-0.1
0
0.1
0.2
0.3
0.4
Coefficient number, n
h(n
)
Truncated Impulse Response
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 26
Realisation Structure Selection - Step 3Realisation Structure Selection - Step 3
1
0
N
k
kk zbzH
zXzHzY 1....1 110 Nnxbnxbnxbny N
z-1
z-1
z-1
+ + +
b0
b2
bN-1
y(n)
x(n)
b1
Direct form structure for an FIR filter:Direct form structure for an FIR filter:
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 27
Realisation Structure Selection - Step 3Realisation Structure Selection - Step 3
1
0
N
k
kk zbzH
Linear phase structures:Linear phase structures:
N even:N even:
N Odd:N Odd:
1
2
0
1
N
k
kNkk zzbzH
2
1
0
2
1
2
11
N
k
N
NkNk
k zbzzbzH
Direct form structure for an FIR filter:Direct form structure for an FIR filter:
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 28
Realisation Structure Selection - Step 3Realisation Structure Selection - Step 3
(a) N even.(a) N even.
(b) N odd.(b) N odd.+
b0
+
+
+
+b
1
+b
2
+b
N/2-1
y(n)
(a)
z-1
z-1
z-1
z-1
z-1
+
b0
+
+
+
+b
1
+b
2
+b (N-3)/2
y(n)
x(n)
b(N-1)/2
+
(b)
z-1
z-1
z-1
z-1
z-1
z-1
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 29
Realisation Structure Selection - Step 3Realisation Structure Selection - Step 3
1
0
N
k
kk zbzH
Cascade structures:Cascade structures:
M
kkk
NN
NN
N
k
kk
zbzbb
zb
bz
b
bz
b
bb
zbzbzbbzbzH
1
22,
11,0
1
0
12
0
21
0
10
11
22
110
1
0
1
...1
...
Direct form structure for an FIR filter:Direct form structure for an FIR filter:
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 30
Realisation Structure Selection - Step 3Realisation Structure Selection - Step 3
1
0
N
k
kk zbzH
Cascade structures:Cascade structures:
z -1
+b
1,1
x(n)
z -1
+
b1,2
z -1
+b
2,1
z -1
+
b2,2
z -1
+b
M,1
z -1
+
bM,2
y(n)b0
Direct form structure for an FIR filter:Direct form structure for an FIR filter:
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 31
Implementation - Step 5Implementation - Step 5 Implementation procedure in ‘C’ with fixed-point:Implementation procedure in ‘C’ with fixed-point:
Set up the codec (Set up the codec (\Links\\Links\CodecSetup.pdfCodecSetup.pdf).).
Transform: to ‘C’ code. Transform: to ‘C’ code.
((\Links\\Links\FIRFixed.pdfFIRFixed.pdf)) Configure timer 1 to generate an interrupt at 8000Hz (Configure timer 1 to generate an interrupt at 8000Hz (\Links\\Links\TimerSetup.pdfTimerSetup.pdf).). Set the interrupt generator to generate an interrupt to invoke the Interrupt Service Routine (ISR) (Set the interrupt generator to generate an interrupt to invoke the Interrupt Service Routine (ISR) (\Links\\Links\InterruptSetup.pdfInterruptSetup.pdf).).
1
0
N
kk knxbny
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 32
Implementation - Step 5Implementation - Step 5 Implementation procedure in ‘C’ with floating-point:Implementation procedure in ‘C’ with floating-point:
Same set up as fixed-point plus:Same set up as fixed-point plus: Convert the input signal to floating-point format.Convert the input signal to floating-point format. Convert the coefficients to floating-point format.Convert the coefficients to floating-point format. With floating-point multiplications there is no need for the shift required when using Q15 format.With floating-point multiplications there is no need for the shift required when using Q15 format.
See See \Links\\Links\FIRFloat.pdfFIRFloat.pdf
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 33
Implementation - Step 5Implementation - Step 5 Implementation procedure in assembly:Implementation procedure in assembly:
Same set up as fixed-point, however:Same set up as fixed-point, however: is written in assembly.is written in assembly.
((\Links\\Links\FIRFixedAsm.pdfFIRFixedAsm.pdf))
The ISR is now declared as external.The ISR is now declared as external.
1
0
N
kk knxbny
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 34
Implementation - Step 5Implementation - Step 5 Implementation procedure in assembly:Implementation procedure in assembly:
The filter implementation in assembly is now using The filter implementation in assembly is now using circular addressingcircular addressing and therefore: and therefore: The circular pointers and block size register are selected and initialised by setting the appropriate values of the AMR bit fields.The circular pointers and block size register are selected and initialised by setting the appropriate values of the AMR bit fields. The data is now aligned using:The data is now aligned using:
Set the initial value of the circular pointers, see Set the initial value of the circular pointers, see \Links\\Links\FIRFixedAsm.pdfFIRFixedAsm.pdf..
#pragma DATA_ALIGN (symbol, constant (bytes))#pragma DATA_ALIGN (symbol, constant (bytes))
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 35
Implementation - Step 5Implementation - Step 5
y0 = b0*x0y0 = b0*x0 + b1*x1+ b1*x1 + b2*x2+ b2*x2 + b3*x3+ b3*x3
Circular addressing link slide.Circular addressing link slide.
timetime
y[n
]y[
n]
00 11 22
bb00
bb11
bb22
bb33
xx00
xx11
xx22
xx33
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 36
xx44
xx11
xx22
xx33
Implementation - Step 5Implementation - Step 5
y0 = b0*x0y0 = b0*x0 + b1*x1+ b1*x1 + b2*x2+ b2*x2 + b3*x3+ b3*x3
y1 = b0*x4y1 = b0*x4 + b1*x1+ b1*x1 + b3*x3+ b3*x3+ b2*x2+ b2*x2
Circular addressing link slide.Circular addressing link slide.
timetime
y[n
]y[
n]
00 11 22
bb00
bb11
bb22
bb33
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 37
xx44
xx55
xx22
xx33
Implementation - Step 5Implementation - Step 5
y0 = b0*x0y0 = b0*x0 + b1*x1+ b1*x1 + b2*x2+ b2*x2 + b3*x3+ b3*x3
y1 = b0*x4y1 = b0*x4 + b1*x1+ b1*x1 + b3*x3+ b3*x3+ b2*x2+ b2*x2
y2 = b0*x4y2 = b0*x4 + b1*x5+ b1*x5 + b3*x3+ b3*x3+ b2*x2+ b2*x2
Circular addressing link slide.Circular addressing link slide.
timetime
y[n
]y[
n]
00 11 22
bb00
bb11
bb22
bb33
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14, Slide 38
FIR CodeFIR Code
Code location:Code location: Code\Chapter 14 - Finite Impulse Response FiltersCode\Chapter 14 - Finite Impulse Response Filters
Projects:Projects: Fixed Point in C:Fixed Point in C: \FIR_C_Fixed\\FIR_C_Fixed\ Floating Point in C:Floating Point in C: \FIR_C_Float\\FIR_C_Float\ Fixed Point in Assembly:Fixed Point in Assembly: \FIR_Asm_Fixed\\FIR_Asm_Fixed\ Floating Point in Assembly:Floating Point in Assembly: \FIR_Asm_Float\\FIR_Asm_Float\