Finite Impulse Response (FIR) Filters
Finite Impulse Response (FIR) Filters
Learning Objectives
Dr. Naim
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.
Dr. Naim
Filter coefficients:
N 1
y n bk x n k
k 0
x[n]
bk
y[n]
N
Dr. Naim
Filter coefficients:
N 1
y n bk x n k
k 0
x(n)
-1
-1
-1
b2
FIR equation
z
-1
N-1
y(n)
Filter structure
Chapter 14, Slide 5
Dr. Naim
Filter coefficients:
N 1
y n bk x n k
k 0
N 1
b n k
k
k 0
y 0 b0 0 b1 1 bk N
Dr. Naim
Filter coefficients:
N 1
y n bk x n k
k 0
N 1
b n k
k
k 0
y n b0 n b1 n 1 bk n N
Dr. Naim
Filter coefficients:
N 1
y n bk x n k
k 0
N 1
b n k
k
k 0
1 for n k
n k
0 for n k
Chapter 14, Slide 8
Dr. Naim
Filter coefficients:
N 1
y n bk x n k
k 0
Finally:
b0 h 0
b1 h1
bk h k
Dr. Naim
Filter coefficients:
N 1
y n bk x n k
k 0
With:
bk h k
Dr. Naim
H z h n z n
n 0
N 1
H z z e j H e j h n e jn
n 0
Dr. Naim
N 1
N 1
n 0
n 0
H z z e 2 h n e jn 2 h n e jn
Therefore:
H e j 2 k H e j
Dr. Naim
H e j 2 k H e j
FIR
y[n]
x[n]
y[n]
x[n]
Freq
Fs/2
Freq
Fs/2
Dr. Naim
x(t)
ADC
x[n]
FIR
y[n]
y[n]
x(t)
Analogue
Anti-Aliasing
Fs/2
Freq
Fs/2
Freq
Dr. Naim
h(n)
h(n)
N = 2n + 2
N = 2n + 1
n
0
n+1
2n
2n+1
Even symmetry
Chapter 14, Slide 15
n
0
n-1
n+1
2n-1
2n
Odd symmetry
Dr. Naim
A causal FIR filter whose impulse response is symmetrical (ie h[n] = h[N-1n] for n = 0, 1, , N-1) is guaranteed to have a linear phase response.
Condition
h n h N n 1
Positive Symmetry
Phase k
N 1
Phase Property
Filter Type
Odd Symmetry Type 1
Linear phase
Dr. Naim
Signal separation
Q
I A cos f t B sin r t
Q A sin f t B cos r t
90
IH
delay
delay
90o
QH
IH A cos f t B sin r t
2
2
A sin f t B cos r t
Reverse
Forward
IH Q 2 B cos r t
QH I 2 B sin f t
Dr. Naim
Design Procedure
Filter specification.
Coefficient calculation.
Structure selection.
Simulation (optional).
Implementation.
Dr. Naim
pass-band
stop-band
f c : cut-off frequency
f(norm)
f s /2
(a)
|H(f)|
(dB)
pass-band
transition band
|H(f)|
(linear)
stop-band
1 p
1
1 p
pass-band
ripple
-3
stop-band
ripple
s
f sb : stop-band frequency
f c : cut-off frequency
f pb : pass-band frequency
f s /2
f(norm)
(b)
Dr. Naim
There are several different methods available, the most popular are:
Window method.
Frequency sampling.
Parks-McClellan.
Dr. Naim
Window Method
First stage of this method is to calculate the coefficients of the ideal filter.
This is calculated as follows:
1
hd n
2
1
2
H e jn d
1 e jn d
2 f c sin n c
n c
2 fc
Chapter 14, Slide 21
for n 0
for n 0
Dr. Naim
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.
Normalised Transition
Width (f(Hz))
Passband Ripple(dB)
Stopband Attenuation
(dB)
Rectangular
0.9
N
0.7416
21
Hanning
3.1
N
0.0546
44
Hamming
3.3
N
0.0194
53
Blackman
5.5
N
0.0017
74
0.0274
50
0.000275
90
Window Type
Kaiser
2.93
4.54
N
5.71
8.96
N
3.3
3.3
8kHz 132
f 1.2 1.4 kHz
Dr. Naim
Window Method
h n hd n W n
Where:
for
N 1
N 1
n
for N odd
2
2
N
N
for N even
n
2
2
2n
N
2n
133
for
66 n 66
Dr. Naim
Window Method
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;
[g,f] = freqz(d,1,512,44100);
figure(1)
plot(f,20*log10(abs(g)));
axis([0 2*10^4 -70 10]);
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
Dr. Naim
Window Method
Truncated Impulse Response
0.4
0.3
h(n)
0.2
0.1
0
Magnitude (dB)
-0.1
20
0.6
0.8
1
1.2
Frequency (Hz)
100
120
140
-20
-40
-60
0.2
0.4
0
Phase (degrees)
60
80
Coefficient number, n
1.4
1.6
1.8
2
4
x 10
-2000
-4000
-6000
40
0.5
1
Frequency (Hz)
1.5
2
4
x 10
Dr. Naim
H z bk z k
k 0
y n b0 x n b1 x n 1 .... bN 1 x n N 1
Y z H z X z
x(n)
-1
-1
-1
N-1
y(n)
Dr. Naim
H z bk z k
k 0
N even:
N Odd:
N
1
2
H z bk z k z N k 1
k 0
N 1
2
H z bk z k z N k 1 b N 1 z
k 0
N 1
2
Dr. Naim
-1
-1
-1
-1
-1
b0
b1
b2
N/2-1
+
+
y(n)
(a)
x(n)
-1
-1
-1
-1
-1
-1
b0
b1
b2
+
+
b(N-1)/2
+
y(n)
(N-3)/2
+
(b)
Dr. Naim
H z bk z k
k 0
Cascade structures:
H z
N 1
k 0
bk z k b0 b1 z 1 b2 z 2 ... bN 1 z N 1
bN 1 N 1
b1 1 b2 2
b0 1 z z ...
z
b
b
b
0
0
0
b0
1 b
M
k 1
1
2
z
b
z
k ,1
k ,2
Dr. Naim
H z bk z k
k 0
Cascade structures:
x(n)
+
z -1
z -1
1,1
z -1
1,2
+
z -1
2,1
z -1
b
M,1
y(n)
z -1
b
2,2
M,2
Dr. Naim
Implementation - Step 5
Transform:
(\Links\FIRFixed.pdf
\Links\FIRFixed.pdf))
Configure timer 1 to generate an interrupt at 8000Hz (\Links\
TimerSetup.pdf).
).
(\Links\TimerSetup.pdf
Set the interrupt generator to generate an interrupt to invoke the Interrupt Service Routine (ISR) (\Links\
InterruptSetup.pdf).
).
(\Links\InterruptSetup.pdf
to C code.
N 1
y n bk x n k
k 0
Dr. Naim
Implementation - Step 5
See \Links\FIRFloat.pdf
\Links\FIRFloat.pdf
Dr. Naim
Implementation - Step 5
is written in assembly.
(\Links\FIRFixedAsm.pdf
\Links\FIRFixedAsm.pdf))
N 1
y n bk x n k
k 0
Dr. Naim
Implementation - Step 5
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:
Dr. Naim
Implementation - Step 5
b0
b1
b2
b3
y[n]
y0 = b0*x0
x0
x1
x2
x3
time
Dr. Naim
Implementation - Step 5
b0
b1
b2
b3
y0 = b0*x0
y[n]
y1 = b0*x4
x4
x1
x2
x3
time
Dr. Naim
Implementation - Step 5
b0
b1
b2
b3
y0 = b0*x0
y[n]
y1 = b0*x4
y2 = b0*x4
x4
x5
x2
x3
time
Dr. Naim
FIR Code
Code location:
Projects:
Fixed Point in C:
Floating Point in C:
Fixed Point in Assembly:
Dr. Naim
Chapter 14
Finite Impulse Response (FIR) Filters
- End -