Professional Documents
Culture Documents
WINSEM2019-20 EEE2005 ETH VL2019205003575 Reference Material I 05-Feb-2020 Design of FIR Filters
WINSEM2019-20 EEE2005 ETH VL2019205003575 Reference Material I 05-Feb-2020 Design of FIR Filters
Chapter 14, Slide 2 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Introduction
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.
Chapter 14, Slide 3 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Properties of an FIR Filter
Filter coefficients:
N 1
yn bk xn k
k 0
Chapter 14, Slide 4 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Properties of an FIR Filter
Filter coefficients:
N 1
yn bk xn k FIR equation
k 0
-1 -1 -1 -1
x(n) z z z z
b0 b1 b2 bN-1
x x x x
+ + + y(n)
Filter structure
Chapter 14, Slide 5 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Properties of an FIR Filter
Filter coefficients:
N 1
yn bk xn k
k 0
Chapter 14, Slide 6 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Properties of an FIR Filter
Filter coefficients:
N 1
yn bk xn k
k 0
Chapter 14, Slide 7 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Properties of an FIR Filter
Filter coefficients:
N 1
yn bk xn 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
Properties of an FIR Filter
Filter coefficients:
N 1
yn bk xn k
k 0
Finally:
b0 h0
b1 h1
bk hk
Chapter 14, Slide 9 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Properties of an FIR Filter
Filter coefficients:
N 1
yn bk xn k
k 0
With: bk hk
Chapter 14, Slide 10 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Frequency Response of an FIR Filter
By taking the z-transform of h[n], H(z):
N 1
H z hnz n
n 0
N 1
H z z e j H e j hne jn
n 0
Chapter 14, Slide 11 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Frequency Response of an FIR Filter
Since e-j2k = 1 then:
N 1 N 1
H z z e 2 hne jn 2 hne jn
n 0 n 0
Therefore:
H e j 2 k H e j
Chapter 14, Slide 12 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Frequency Response of an FIR Filter
Frequency
response:
H e j 2k H e j
y[n]
Freq
Freq
Fs/2 Fs/2
Chapter 14, Slide 13 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Frequency Response of an FIR Filter
Solution: Use an anti-aliasing filter.
x[n]
x(t) ADC FIR y[n]
Analogue
Anti-Aliasing
y[n]
x(t)
Freq Freq
Fs/2 Fs/2
Chapter 14, Slide 14 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
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 n
0 1 n n+1 2n 2n+1 0 1 n-1 n n+1 2n-1 2n
Chapter 14, Slide 15 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
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.
N 1
Condition Phase k Phase Property Filter Type
2
Chapter 14, Slide 16 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Phase Linearity of an FIR Filter
Application of 90° linear phase shift:
o IH
I 90 +
Reverse
delay +
Signal
separation delay -
Forward
Q 90o +
QH
Chapter 14, Slide 17 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Design Procedure
To fully design and implement a filter five
steps are required:
(1) Filter specification.
(2) Coefficient calculation.
(3) Structure selection.
(4) Simulation (optional).
(5) Implementation.
Chapter 14, Slide 18 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Filter Specification - Step 1
|H(f)| pass-band stop-band
0 1
1 p
pass-band
-3
ripple
stop-band
ripple
s s
fs/2 f(norm)
fsb : stop-band frequency
fc : cut-off frequency
fpb : pass-band frequency
(b)
Chapter 14, Slide 19 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
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
Window Method
First stage of this method is to calculate
the coefficients of the ideal filter.
This is calculated as follows:
hd n H e jn d
1
2
c
1
2 1 e jn d
c
2 f c sin n c
for n 0
n c
2 fc for n 0
Chapter 14, Slide 21 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
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.
0.9
Rectangular 0.7416 21
N
3.1
Hanning N
0.0546 44
3.3
Hamming N 0.0194 53
5.5
Blackman N 0.0017 74
2.93
4.54
N 0.0274 50
Kaiser 5.71
8.96
N 0.000275 90
2n
Where: W n 0.54 0.46 cos
N
for 66 n 66
2n
0.54 0.46 cos
133
Chapter 14, Slide 23 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Window Method
Matlab code for calculating coefficients:
close all;
clear all;
figure(1)
plot(f,20*log10(abs(g))); % plot transfer function
axis([0 2*10^4 -70 10]);
figure(2);
stem(d); % plot coefficient values
xlabel('Coefficient number');
ylabel ('Value');
title('Truncated Impulse Response');
figure(3)
freqz(d,1,512,44100); % use freqz to plot magnitude and phase response
axis([0 2*10^4 -70 10]);
Chapter 14, Slide 24 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Window Method
Truncated Impulse Response
0.4
0.3
0.2
h(n)
0.1
-0.1
0 20 40 60 80 100 120 140
Coefficient number, n
0
Magnitude (dB)
-20
-40
-60
-2000
-4000
-6000
0 0.5 1 1.5 2
Frequency (Hz) 4
x 10
Chapter 14, Slide 25 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Realisation Structure Selection - Step 3
Direct form structure for an FIR filter:
N 1
H z bk z k
k 0
-1 -1 -1
x(n) z z z
b b b b
0 1 2 N-1
+ + + y(n)
Chapter 14, Slide 26 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Realisation Structure Selection - Step 3
Direct form structure for an FIR filter:
N 1
H z bk z k
k 0
2
N even: H z bk z k z N k 1
k 0
N 1
N 1
2
N Odd: H z bk z k z N k 1 b N 1 z 2
k 0 2
Chapter 14, Slide 27 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Realisation Structure Selection - Step 3
-1 -1 -1 -1 -1
(a) N even. z z z z z
+
b0
b1
(b) N odd. +
+
b2
+
b N/2-1
+ +
y(n)
(a)
x(n) -1 -1 -1 -1 -1 -1
z z z z z z
b0
+
b1
+ +
b2
+ +
b(N-1)/2
b(N-3)/2
+ +
y(n) +
(b)
Chapter 14, Slide 28 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Realisation Structure Selection - Step 3
Direct form structure for an FIR filter:
N 1
H z bk z k
k 0
Cascade structures:
N 1
H z bk z k b0 b1 z 1 b2 z 2 ... bN 1 z N 1
k 0
b b b
b0 1 1 z 1 2 z 2 ... N 1 z N 1
b0 b0 b0
M
b0 1 bk ,1 z 1 bk , 2 z 2
k 1
Chapter 14, Slide 29 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Realisation Structure Selection - Step 3
Direct form structure for an FIR filter:
N 1
H z bk z k
k 0
Cascade structures:
x(n) b0 y(n)
+ + +
z -1 z -1 z -1
b 1,1 b 2,1 b M,1
+ + +
z -1 z -1 z -1
b 1,2 b 2,2 b M,2
Chapter 14, Slide 30 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Implementation - Step 5
Implementation procedure in ‘C’ with
fixed-point:
Set up the codec (\Links\CodecSetup.pdf).
Transform: N 1
yn bk xn k to ‘C’ code.
k 0
(\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).
Chapter 14, Slide 31 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
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
Implementation - Step 5
Implementation procedure in assembly:
Same set up as fixed-point, however:
N 1
yn bk xn k
is written in assembly.
k 0
(\Links\FIRFixedAsm.pdf)
Chapter 14, Slide 33 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
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 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Implementation - Step 5
b0 x0
b1 x1
b2 x2
b3 x3
time
0 1 2
Circular addressing link slide.
Chapter 14, Slide 35 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Implementation - Step 5
b0 x4
b1 x1
b2 x2
b3 x3
time
0 1 2
Circular addressing link slide.
Chapter 14, Slide 36 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Implementation - Step 5
b0 x4
b1 x5
b2 x2
b3 x3
time
0 1 2
Circular addressing link slide.
Chapter 14, Slide 37 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
FIR Code
Code location:
Code\Chapter 14 - Finite Impulse Response Filters
Projects:
Fixed Point in C: \FIR_C_Fixed\
Floating Point in C: \FIR_C_Float\
Fixed Point in Assembly: \FIR_Asm_Fixed\
Floating Point in Assembly: \FIR_Asm_Float\
Chapter 14, Slide 38 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004
Chapter 14
Finite Impulse Response (FIR) Filters
- End -