Chapter 14 Finite Impulse Response (FIR) Filters Learning Objectives Introduction to the theory behind FIR filters: Chapter 14, Slide 2 Properties (including aliasing). Coefficient calculation. Structure selection. Implementation.
Download ReportTranscript Chapter 14 Finite Impulse Response (FIR) Filters Learning Objectives Introduction to the theory behind FIR filters: Chapter 14, Slide 2 Properties (including aliasing). Coefficient calculation. Structure selection. Implementation.
Slide 1
Chapter 14
Finite Impulse Response (FIR) Filters
Slide 2
Learning Objectives
Introduction to the theory behind FIR
filters:
Chapter 14, Slide 2
Properties (including aliasing).
Coefficient calculation.
Structure selection.
Implementation in Matlab, C, assembly
and linear assembly.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 3
Introduction
Chapter 14, Slide 3
Amongst all the obvious advantages that
digital filters offer, the FIR filter can
guarantee linear phase characteristics.
Neither analogue or IIR filters can achieve
this.
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.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 4
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
x[n]
bk
y[n]
N
Chapter 14, Slide 4
represents the filter input,
represents the filter coefficients,
represents the filter output,
is the number of filter coefficients
(order of the filter).
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 5
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
-1
z
x (n)
x
b0
-1
z
x
+
b1
-1
z
x
b2
+
FIR equation
-1
z
x
+
b N -1
y (n)
Filter structure
Chapter 14, Slide 5
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 6
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
If the signal x[n] is replaced by an impulse
[n] then:
y n
N 1
b n k
k
k 0
y 0 b 0 0 b1 1 b k N
Chapter 14, Slide 6
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 7
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
If the signal x[n] is replaced by an impulse
[n] then:
y n
N 1
b n k
k
k 0
y n b 0 n b1 n 1 b k n N
Chapter 14, Slide 7
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 8
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
If the signal x[n] is replaced by an impulse
[n] then:
y n
N 1
b n k
k
k 0
1 for n k
n k
0 for n k
Chapter 14, Slide 8
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 9
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
Finally:
b 0 h 0
b1 h 1
b k h k
Chapter 14, Slide 9
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 10
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
With:
b k h k
The coefficients of a filter are the same as
the impulse response samples of the filter.
Chapter 14, Slide 10
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 11
Frequency Response of an FIR Filter
By taking the z-transform of h[n], H(z):
H z
N 1
h n z
n
n0
Replacing z by ej in order to find the
frequency response leads to:
N 1
h n e
H z z e j H e
Chapter 14, Slide 11
j
jn
n0
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 12
Frequency Response of an FIR Filter
Since e-j2k = 1 then:
H z z e 2
h n e
jn 2
n0
N 1
h n e
jn
n0
Therefore:
H e
N 1
j 2 k
H e
j
FIR filters have a periodic frequency
response and the period is 2.
Chapter 14, Slide 12
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 13
Frequency Response of an FIR Filter
Frequency
response:
H e
H e
j
y[n]
y[n]
FIR
x[n]
x[n]
j 2 k
Freq
Fs/2
Chapter 14, Slide 13
Freq
Fs/2
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 14
Frequency Response of an FIR Filter
Solution: Use an anti-aliasing filter.
x(t)
ADC
x[n]
FIR
y[n]
x(t)
y[n]
Analogue
Anti-Aliasing
Fs/2
Chapter 14, Slide 14
Freq
Fs/2
Freq
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 15
Phase Linearity of an FIR Filter
A causal FIR filter whose impulse
response is symmetrical is guaranteed to
have a linear phase response.
h (n )
h (n )
N = 2n + 2
N = 2n + 1
n
0
1
n
n+ 1
2n 2n+ 1
Even symmetry
Chapter 14, Slide 15
n
0
1
n -1
n
n+ 1
2 n -1 2 n
Odd symmetry
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 16
Phase Linearity of an FIR Filter
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.
C on d ition
P h ase k
N 1
2
P h ase P rop erty
h n h N n 1
O dd S ym m etry – T ype 1
k
P ositive S ym m etry
Chapter 14, Slide 16
F ilter T yp e
L inear phase
E ven S ym m etry – T ype 2
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 17
Phase Linearity of an FIR Filter
Application of 90° linear phase shift:
I
90
o
IH
+
Reverse
Signal
separation
Q
I A cos f t B sin r t
Q A sin f t B cos r t
Chapter 14, Slide 17
delay
+
delay
-
90o
Forward
QH
+
IH A cos f t B sin r t
2
2
A sin f t B cos r t
IH Q 2 B cos r t
QH I 2 B sin f t
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 18
Design Procedure
To fully design and implement a filter five
steps are required:
(1)
(2)
(3)
(4)
(5)
Chapter 14, Slide 18
Filter specification.
Coefficient calculation.
Structure selection.
Simulation (optional).
Implementation.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 19
Filter Specification - Step 1
|H (f)|
pas s -band
s top-band
1
f c : c ut-off frequenc y
f(norm )
f s /2
(a)
|H (f)|
(dB )
pas s -band
trans ition band
|H (f)|
(linear)
s top-band
1
p
1
p
pas s -band
ripple
-3
p
1
0
s top-band
ripple
s
f s /2
s
f(norm )
f s b : s top-band frequenc y
f c : c ut-off frequenc y
f pb : pas s -band frequenc y
(b)
Chapter 14, Slide 19
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 20
Coefficient Calculation - Step 2
There are several different methods
available, the most popular are:
Window method.
Frequency sampling.
Parks-McClellan.
We will just consider the window method.
Chapter 14, Slide 20
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 21
Window Method
First stage of this method is to calculate
the coefficients of the ideal filter.
This is calculated as follows:
h d n
1
2
1
2
H e
j n
c
1e
j n
d
c
2 f c sin n c
n c
2 fc
Chapter 14, Slide 21
d
for n 0
for n 0
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 22
Window Method
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 transition band.
W in d o w T y p e
N o r m a lis e d T r a n s itio n
W id th ( f (H z))
P a s s b a n d R ip p le (d B )
S to p b a n d A tte n u a tio n
(d B )
0 .7 4 1 6
21
0 .0 5 4 6
44
0 .0 1 9 4
53
0 .0 0 1 7
74
0 .0 2 7 4
50
0 .0 0 0 2 7 5
90
0 .9
R e c ta n g u la r
N
3 .1
H a n n in g
N
3 .3
H a m m in g
N
5 .5
B la c k m a n
N
2 . 93
K a is e r
N
5 . 71
4 . 54
8 . 96
N
Using the Hamming
Window:
Chapter 14, Slide 22
N
3 .3
f
3 .3
1 .2 1 . 4 kHz
8 kHz 132
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 23
Window Method
The third stage is to calculate the set of
truncated or windowed impulse response
coefficients, h[n]:
h n h d n W n
for
N 1
n
2
2
N
n
2
Where:
2 n
W n 0 . 54 0 . 46 cos
N
2 n
0 . 54 0 . 46 cos
133
Chapter 14, Slide 23
N 1
N
for N odd
for N even
2
for
66 n 66
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 24
Window Method
Matlab code for calculating coefficients:
close all;
clear all;
fc = 8000/44100;
N = 133;
n = -((N-1)/2):((N-1)/2);
n = n+(n==0)*eps;
% cut-off frequency
% number of taps
[h] = sin(n*2*pi*fc)./(n*pi);
[w] = 0.54 + 0.46*cos(2*pi*n/N);
d = h.*w;
% generate sequence of ideal coefficients
% generate window function
% 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)));
axis([0 2*10^4 -70 10]);
% plot transfer function
figure(2);
stem(d);
xlabel('Coefficient number');
ylabel ('Value');
title('Truncated Impulse Response');
figure(3)
freqz(d,1,512,44100);
axis([0 2*10^4 -70 10]);
Chapter 14, Slide 24
% avoiding division by zero
% plot coefficient values
% use freqz to plot magnitude and phase response
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 25
Window Method
Truncated Impulse Response
0.4
0.3
h(n)
0.2
0.1
0
Magnitude (dB)
-0.1
0
20
40
60
80
Coefficient number, n
0.6
0.8
1
1.2
Frequency (Hz)
100
120
140
0
-20
-40
-60
0
0.2
0.4
1.4
1.6
1.8
x 10
Phase (degrees)
0
-2000
-4000
-6000
Chapter 14, Slide 25
2
4
0
0.5
1
Frequency (Hz)
1.5
2
4
x 10
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 26
Realisation Structure Selection - Step 3
Direct form structure for an FIR filter:
H z
N 1
bk z
k
k 0
y n b 0 x n b1 x n 1 .... b N 1 x n N 1
Y z H z X z
x (n )
z
-1
z
b
z
b
0
-1
b
1
+
Chapter 14, Slide 26
-1
b
2
+
+
N -1
y (n )
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 27
Realisation Structure Selection - Step 3
Direct form structure for an FIR filter:
H z
N 1
bk z
k
k 0
Linear phase structures:
N
N even:
H z
1
2
bk z
k
z
N k 1
N k 1
b
k 0
N 1
N Odd:
H z
b z
2
k
k 0
Chapter 14, Slide 27
k
z
N 1
z
N 1
2
2
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 28
Realisation Structure Selection - Step 3
(a) N even.
(b) N odd.
z
-1
z
-1
z
-1
z
-1
z
-1
b
0
+
b
1
+
+
b
2
+
b
+
N / 2-1
+
+
y (n )
(a )
x (n )
z
-1
z
-1
z
-1
z
-1
z
-1
z
-1
b
+
0
b
+
1
+
b
+
2
+
b
(N -1)/ 2
b (N -3)/ 2
+
y (n )
+
+
(b )
Chapter 14, Slide 28
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 29
Realisation Structure Selection - Step 3
Direct form structure for an FIR filter:
H z
N 1
bk z
k
k 0
Cascade structures:
H z
N 1
bk z
k
b 0 b1 z
1
b2 z
2
... b N 1 z
N 1
k 0
b
b 1 b
2
N 1
b 0 1 1 z 2 z ... N 1 z
b
b
b
0
0
0
M
b0
1 b
k ,1 z
1
bk ,2 z
2
k 1
Chapter 14, Slide 29
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 30
Realisation Structure Selection - Step 3
Direct form structure for an FIR filter:
H z
N 1
bk z
k
k 0
Cascade structures:
x (n )
b
y (n )
0
+
z -1
+
z -1
b
z -1
b
1, 1
Chapter 14, Slide 30
1, 2
M ,1
+
z -1
b
b
2, 1
+
z -1
+
+
z -1
b
2, 2
b
M ,2
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 31
Implementation - Step 5
Implementation procedure in ‘C’ with
fixed-point:
Set up the codec (\Links\CodecSetup.pdf).
Transform:
y n
N 1
b
k
x n k
to ‘C’ code.
k 0
Chapter 14, Slide 31
(\Links\FIRFixed.pdf)
Configure timer 1 to generate an interrupt at
8000Hz (\Links\TimerSetup.pdf).
Set the interrupt generator to generate an
interrupt to invoke the Interrupt Service
Routine (ISR) (\Links\InterruptSetup.pdf).
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 32
Implementation - Step 5
Implementation procedure in ‘C’ with
floating-point:
Same set up as fixed-point plus:
Convert the input signal 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.
See \Links\FIRFloat.pdf
Chapter 14, Slide 32
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 33
Implementation - Step 5
Implementation procedure in assembly:
Same set up as fixed-point, however:
y n
N 1
b k x n k
is written in assembly.
k 0
(\Links\FIRFixedAsm.pdf)
Chapter 14, Slide 33
The ISR is now declared as external.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 34
Implementation - Step 5
Implementation procedure in assembly:
The filter implementation in assembly is
now using circular addressing and
therefore:
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:
#pragma DATA_ALIGN (symbol, constant (bytes))
Chapter 14, Slide 34
Set the initial value of the circular pointers,
see \Links\FIRFixedAsm.pdf.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 35
Implementation - Step 5
b0
b1
b2
b3
+ b1*x1 + b2*x2 + b3*x3
y[n]
y0 = b0*x0
x0
x1
x2
x3
0
1
2
time
Circular addressing link slide.
Chapter 14, Slide 35
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 36
Implementation - Step 5
b0
b1
b2
b3
y0 = b0*x0
+ b1*x1 + b2*x2 + b3*x3
+ b1*x1 + b2*x2 + b3*x3
y[n]
y1 = b0*x4
x4
x1
x2
x3
0
1
2
time
Circular addressing link slide.
Chapter 14, Slide 36
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 37
Implementation - Step 5
b0
b1
b2
b3
y0 = b0*x0
+ b1*x1 + b2*x2 + b3*x3
+ b1*x1 + b2*x2 + b3*x3
+ b1*x5 + b2*x2 + b3*x3
y[n]
y1 = b0*x4
y2 = b0*x4
x4
x5
x2
x3
0
1
2
time
Circular addressing link slide.
Chapter 14, Slide 37
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 38
FIR Code
Code location:
Code\Chapter 14 - Finite Impulse Response Filters
Projects:
Fixed Point in C:
Floating Point in C:
Fixed Point in Assembly:
Floating Point in Assembly: \FIR_Asm_Float\
Chapter 14, Slide 38
\FIR_C_Fixed\
\FIR_C_Float\
\FIR_Asm_Fixed\
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 39
Chapter 14
Finite Impulse Response (FIR) Filters
- End -
Chapter 14
Finite Impulse Response (FIR) Filters
Slide 2
Learning Objectives
Introduction to the theory behind FIR
filters:
Chapter 14, Slide 2
Properties (including aliasing).
Coefficient calculation.
Structure selection.
Implementation in Matlab, C, assembly
and linear assembly.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 3
Introduction
Chapter 14, Slide 3
Amongst all the obvious advantages that
digital filters offer, the FIR filter can
guarantee linear phase characteristics.
Neither analogue or IIR filters can achieve
this.
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.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 4
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
x[n]
bk
y[n]
N
Chapter 14, Slide 4
represents the filter input,
represents the filter coefficients,
represents the filter output,
is the number of filter coefficients
(order of the filter).
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 5
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
-1
z
x (n)
x
b0
-1
z
x
+
b1
-1
z
x
b2
+
FIR equation
-1
z
x
+
b N -1
y (n)
Filter structure
Chapter 14, Slide 5
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 6
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
If the signal x[n] is replaced by an impulse
[n] then:
y n
N 1
b n k
k
k 0
y 0 b 0 0 b1 1 b k N
Chapter 14, Slide 6
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 7
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
If the signal x[n] is replaced by an impulse
[n] then:
y n
N 1
b n k
k
k 0
y n b 0 n b1 n 1 b k n N
Chapter 14, Slide 7
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 8
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
If the signal x[n] is replaced by an impulse
[n] then:
y n
N 1
b n k
k
k 0
1 for n k
n k
0 for n k
Chapter 14, Slide 8
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 9
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
Finally:
b 0 h 0
b1 h 1
b k h k
Chapter 14, Slide 9
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 10
Properties of an FIR Filter
Filter coefficients:
y n
N 1
b
k
x n k
k 0
With:
b k h k
The coefficients of a filter are the same as
the impulse response samples of the filter.
Chapter 14, Slide 10
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 11
Frequency Response of an FIR Filter
By taking the z-transform of h[n], H(z):
H z
N 1
h n z
n
n0
Replacing z by ej in order to find the
frequency response leads to:
N 1
h n e
H z z e j H e
Chapter 14, Slide 11
j
jn
n0
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 12
Frequency Response of an FIR Filter
Since e-j2k = 1 then:
H z z e 2
h n e
jn 2
n0
N 1
h n e
jn
n0
Therefore:
H e
N 1
j 2 k
H e
j
FIR filters have a periodic frequency
response and the period is 2.
Chapter 14, Slide 12
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 13
Frequency Response of an FIR Filter
Frequency
response:
H e
H e
j
y[n]
y[n]
FIR
x[n]
x[n]
j 2 k
Freq
Fs/2
Chapter 14, Slide 13
Freq
Fs/2
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 14
Frequency Response of an FIR Filter
Solution: Use an anti-aliasing filter.
x(t)
ADC
x[n]
FIR
y[n]
x(t)
y[n]
Analogue
Anti-Aliasing
Fs/2
Chapter 14, Slide 14
Freq
Fs/2
Freq
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 15
Phase Linearity of an FIR Filter
A causal FIR filter whose impulse
response is symmetrical is guaranteed to
have a linear phase response.
h (n )
h (n )
N = 2n + 2
N = 2n + 1
n
0
1
n
n+ 1
2n 2n+ 1
Even symmetry
Chapter 14, Slide 15
n
0
1
n -1
n
n+ 1
2 n -1 2 n
Odd symmetry
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 16
Phase Linearity of an FIR Filter
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.
C on d ition
P h ase k
N 1
2
P h ase P rop erty
h n h N n 1
O dd S ym m etry – T ype 1
k
P ositive S ym m etry
Chapter 14, Slide 16
F ilter T yp e
L inear phase
E ven S ym m etry – T ype 2
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 17
Phase Linearity of an FIR Filter
Application of 90° linear phase shift:
I
90
o
IH
+
Reverse
Signal
separation
Q
I A cos f t B sin r t
Q A sin f t B cos r t
Chapter 14, Slide 17
delay
+
delay
-
90o
Forward
QH
+
IH A cos f t B sin r t
2
2
A sin f t B cos r t
IH Q 2 B cos r t
QH I 2 B sin f t
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 18
Design Procedure
To fully design and implement a filter five
steps are required:
(1)
(2)
(3)
(4)
(5)
Chapter 14, Slide 18
Filter specification.
Coefficient calculation.
Structure selection.
Simulation (optional).
Implementation.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 19
Filter Specification - Step 1
|H (f)|
pas s -band
s top-band
1
f c : c ut-off frequenc y
f(norm )
f s /2
(a)
|H (f)|
(dB )
pas s -band
trans ition band
|H (f)|
(linear)
s top-band
1
p
1
p
pas s -band
ripple
-3
p
1
0
s top-band
ripple
s
f s /2
s
f(norm )
f s b : s top-band frequenc y
f c : c ut-off frequenc y
f pb : pas s -band frequenc y
(b)
Chapter 14, Slide 19
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 20
Coefficient Calculation - Step 2
There are several different methods
available, the most popular are:
Window method.
Frequency sampling.
Parks-McClellan.
We will just consider the window method.
Chapter 14, Slide 20
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 21
Window Method
First stage of this method is to calculate
the coefficients of the ideal filter.
This is calculated as follows:
h d n
1
2
1
2
H e
j n
c
1e
j n
d
c
2 f c sin n c
n c
2 fc
Chapter 14, Slide 21
d
for n 0
for n 0
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 22
Window Method
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 transition band.
W in d o w T y p e
N o r m a lis e d T r a n s itio n
W id th ( f (H z))
P a s s b a n d R ip p le (d B )
S to p b a n d A tte n u a tio n
(d B )
0 .7 4 1 6
21
0 .0 5 4 6
44
0 .0 1 9 4
53
0 .0 0 1 7
74
0 .0 2 7 4
50
0 .0 0 0 2 7 5
90
0 .9
R e c ta n g u la r
N
3 .1
H a n n in g
N
3 .3
H a m m in g
N
5 .5
B la c k m a n
N
2 . 93
K a is e r
N
5 . 71
4 . 54
8 . 96
N
Using the Hamming
Window:
Chapter 14, Slide 22
N
3 .3
f
3 .3
1 .2 1 . 4 kHz
8 kHz 132
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 23
Window Method
The third stage is to calculate the set of
truncated or windowed impulse response
coefficients, h[n]:
h n h d n W n
for
N 1
n
2
2
N
n
2
Where:
2 n
W n 0 . 54 0 . 46 cos
N
2 n
0 . 54 0 . 46 cos
133
Chapter 14, Slide 23
N 1
N
for N odd
for N even
2
for
66 n 66
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 24
Window Method
Matlab code for calculating coefficients:
close all;
clear all;
fc = 8000/44100;
N = 133;
n = -((N-1)/2):((N-1)/2);
n = n+(n==0)*eps;
% cut-off frequency
% number of taps
[h] = sin(n*2*pi*fc)./(n*pi);
[w] = 0.54 + 0.46*cos(2*pi*n/N);
d = h.*w;
% generate sequence of ideal coefficients
% generate window function
% 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)));
axis([0 2*10^4 -70 10]);
% plot transfer function
figure(2);
stem(d);
xlabel('Coefficient number');
ylabel ('Value');
title('Truncated Impulse Response');
figure(3)
freqz(d,1,512,44100);
axis([0 2*10^4 -70 10]);
Chapter 14, Slide 24
% avoiding division by zero
% plot coefficient values
% use freqz to plot magnitude and phase response
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 25
Window Method
Truncated Impulse Response
0.4
0.3
h(n)
0.2
0.1
0
Magnitude (dB)
-0.1
0
20
40
60
80
Coefficient number, n
0.6
0.8
1
1.2
Frequency (Hz)
100
120
140
0
-20
-40
-60
0
0.2
0.4
1.4
1.6
1.8
x 10
Phase (degrees)
0
-2000
-4000
-6000
Chapter 14, Slide 25
2
4
0
0.5
1
Frequency (Hz)
1.5
2
4
x 10
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 26
Realisation Structure Selection - Step 3
Direct form structure for an FIR filter:
H z
N 1
bk z
k
k 0
y n b 0 x n b1 x n 1 .... b N 1 x n N 1
Y z H z X z
x (n )
z
-1
z
b
z
b
0
-1
b
1
+
Chapter 14, Slide 26
-1
b
2
+
+
N -1
y (n )
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 27
Realisation Structure Selection - Step 3
Direct form structure for an FIR filter:
H z
N 1
bk z
k
k 0
Linear phase structures:
N
N even:
H z
1
2
bk z
k
z
N k 1
N k 1
b
k 0
N 1
N Odd:
H z
b z
2
k
k 0
Chapter 14, Slide 27
k
z
N 1
z
N 1
2
2
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 28
Realisation Structure Selection - Step 3
(a) N even.
(b) N odd.
z
-1
z
-1
z
-1
z
-1
z
-1
b
0
+
b
1
+
+
b
2
+
b
+
N / 2-1
+
+
y (n )
(a )
x (n )
z
-1
z
-1
z
-1
z
-1
z
-1
z
-1
b
+
0
b
+
1
+
b
+
2
+
b
(N -1)/ 2
b (N -3)/ 2
+
y (n )
+
+
(b )
Chapter 14, Slide 28
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 29
Realisation Structure Selection - Step 3
Direct form structure for an FIR filter:
H z
N 1
bk z
k
k 0
Cascade structures:
H z
N 1
bk z
k
b 0 b1 z
1
b2 z
2
... b N 1 z
N 1
k 0
b
b 1 b
2
N 1
b 0 1 1 z 2 z ... N 1 z
b
b
b
0
0
0
M
b0
1 b
k ,1 z
1
bk ,2 z
2
k 1
Chapter 14, Slide 29
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 30
Realisation Structure Selection - Step 3
Direct form structure for an FIR filter:
H z
N 1
bk z
k
k 0
Cascade structures:
x (n )
b
y (n )
0
+
z -1
+
z -1
b
z -1
b
1, 1
Chapter 14, Slide 30
1, 2
M ,1
+
z -1
b
b
2, 1
+
z -1
+
+
z -1
b
2, 2
b
M ,2
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 31
Implementation - Step 5
Implementation procedure in ‘C’ with
fixed-point:
Set up the codec (\Links\CodecSetup.pdf).
Transform:
y n
N 1
b
k
x n k
to ‘C’ code.
k 0
Chapter 14, Slide 31
(\Links\FIRFixed.pdf)
Configure timer 1 to generate an interrupt at
8000Hz (\Links\TimerSetup.pdf).
Set the interrupt generator to generate an
interrupt to invoke the Interrupt Service
Routine (ISR) (\Links\InterruptSetup.pdf).
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 32
Implementation - Step 5
Implementation procedure in ‘C’ with
floating-point:
Same set up as fixed-point plus:
Convert the input signal 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.
See \Links\FIRFloat.pdf
Chapter 14, Slide 32
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 33
Implementation - Step 5
Implementation procedure in assembly:
Same set up as fixed-point, however:
y n
N 1
b k x n k
is written in assembly.
k 0
(\Links\FIRFixedAsm.pdf)
Chapter 14, Slide 33
The ISR is now declared as external.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 34
Implementation - Step 5
Implementation procedure in assembly:
The filter implementation in assembly is
now using circular addressing and
therefore:
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:
#pragma DATA_ALIGN (symbol, constant (bytes))
Chapter 14, Slide 34
Set the initial value of the circular pointers,
see \Links\FIRFixedAsm.pdf.
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 35
Implementation - Step 5
b0
b1
b2
b3
+ b1*x1 + b2*x2 + b3*x3
y[n]
y0 = b0*x0
x0
x1
x2
x3
0
1
2
time
Circular addressing link slide.
Chapter 14, Slide 35
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 36
Implementation - Step 5
b0
b1
b2
b3
y0 = b0*x0
+ b1*x1 + b2*x2 + b3*x3
+ b1*x1 + b2*x2 + b3*x3
y[n]
y1 = b0*x4
x4
x1
x2
x3
0
1
2
time
Circular addressing link slide.
Chapter 14, Slide 36
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 37
Implementation - Step 5
b0
b1
b2
b3
y0 = b0*x0
+ b1*x1 + b2*x2 + b3*x3
+ b1*x1 + b2*x2 + b3*x3
+ b1*x5 + b2*x2 + b3*x3
y[n]
y1 = b0*x4
y2 = b0*x4
x4
x5
x2
x3
0
1
2
time
Circular addressing link slide.
Chapter 14, Slide 37
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 38
FIR Code
Code location:
Code\Chapter 14 - Finite Impulse Response Filters
Projects:
Fixed Point in C:
Floating Point in C:
Fixed Point in Assembly:
Floating Point in Assembly: \FIR_Asm_Float\
Chapter 14, Slide 38
\FIR_C_Fixed\
\FIR_C_Float\
\FIR_Asm_Fixed\
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Slide 39
Chapter 14
Finite Impulse Response (FIR) Filters
- End -