Finite Impulse Response (FIR) Filters
Finite Impulse Response (FIR) Filters
-1 -1 -1 -1
x (n ) z z z z
b 0
b 1
b2 b N -1
x x x x
+ + + y (n )
Filter structure
Properties of an FIR Filter
Filter coefficients:
N −1
y[ n] = ∑ bk ⋅ x[ n − k ]
k =0
y[ 0] = b0δ [ 0] + b1δ [ − 1] + + bk δ [ − N ]
Properties of an FIR Filter
Filter coefficients:
N −1
y[ n] = ∑ bk ⋅ x[ n − k ]
k =0
y[ n] = b0δ [ n] + b1δ [ n − 1] + + bk δ [ n − N ]
Properties of an FIR Filter
Filter coefficients:
N −1
y[ n] = ∑ bk ⋅ x[ n − k ]
k =0
1 for n = k
δ [n − k ] =
0 for n ≠ k
Properties of an FIR Filter
Filter coefficients:
N −1
y[ n] = ∑ bk ⋅ x[ n − k ]
k =0
Finally:
b0 = h[ 0]
b1 = h[1]
bk = h[ k ]
Properties of an FIR Filter
Filter coefficients:
N −1
y[ n] = ∑ bk ⋅ x[ n − k ]
k =0
bk = h[ k ]
With:
( )
N −1
H ( z ) z =e jω = H e jω = ∑ h[ n] e − jnω
n =0
Frequency Response of an FIR
Filter
Since e-j2π k = 1 then:
N −1 N −1
H ( z ) z =eω +2π = ∑ h[ n] e − jn ( ω + 2π ) =∑ h[ n] e − jnω
n =0 n =0
Therefore:
H ( e jω+2 kπ ) = H ( e jω )
y[n]
Freq
Freq
Fs/2 Fs/2
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
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 2 n -1 2n
N−
Phase
1
Condition k=
− Phase Property Filter Type
2
h[n ]=
h[N −
n−1] Odd Symmetry – Type 1
kω Linear phase
Positive Symmetry Even Symmetry – Type 2
Phase Linearity of an FIR
Filter
Application of 90° linear phase shift:
IH
o
I 90 +
Reverse
delay +
Signal
separation delay
-
Forward
Q 90o +
QH
f c : c u t- o ff f r e q u e n c y f s /2 f( n o r m )
(a )
s to p - b a n d
∆
s
rip p le
δ s
f s /2 f( n o r m )
f s b : s to p -b a n d fr e q u e n c y
f c : c u t- o ff fr e q u e n c y
f p b : p a s s -b a n d fr e q u e n c y
(b )
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.
Window Method
First stage of this method is to calculate the
coefficients of the ideal filter.
This is calculated as follows:
π
1
hd ( n ) = ∫ H ( ω )e jωn dω
2π −π
ωc
1
=
2π ∫ 1 ⋅ e jωn dω
−ω c
2 f c sin ( nω c )
for n ≠ 0
= nω c
2 fc for n = 0
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 Stopband Attenuation
Window Type Passband Ripple(dB)
Width ( ∆f(Hz)) (dB)
0.9
Rectangular 0.7416 21
N
3.1
Hanning 0.0546 44
N
3.3
Hamming 0.0194 53
N
5.5
Blackman 0.0017 74
N
2.93
→β = 4.54
N 0.0274 50
Kaiser 5.71
→β = 8.96
N 0.000275 90
Using the N=
3.3
=
3.3
⋅ 8kHz = 132
∆f (1.2 − 1.4 ) kHz
Hamming Window:
Window Method
The third stage is to calculate the set of truncated
or windowed impulse response coefficients, h[n]:
N −1 N −1
− ≤n≤ for N = odd
h( n ) = hd ( n ) ⋅ W ( n ) for 2 2
N N for N = even
− ≤n≤
2 2
2πn
Where: W ( n ) = 0.54 + 0.46 cos
N
for −66 ≤ n ≤ 66
2πn
= 0.54 + 0.46 cos
133
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]);
Window Method
Truncated Impulse Response
0.4
0.3
0.2
0.1
h(n)
0
-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
Realization Structure Selection
- Step 3
Direct form structure for an FIR
filter: H ( z) = ∑b z
N −1
k
−k
k =0
Y ( z) = H ( z) ⋅ X ( z) y ( n ) = b0 x( n ) + b1 x( n − 1) + .... + bN −1 x( n − N + 1)
-1 -1 -1
x (n ) z z z
b b b b
0 1 2 N -1
+ + + y (n )
Realization Structure Selection
- Step 3
Direct form structure for an FIR
filter: H ( z ) = N −1 b z −k
∑k =0
k
∑ ( )
2
N even:
H ( z) =
bk z − k + z N − k −1
k =0
N Odd: N −1
N −1
∑b (z )
2 −
H ( z) = k
−k
+ z N − k −1 + b N −1 z 2
k =0 2
Realization Structure Selection -
Step 3
(a) N even.
-1 -1 -1 -1 -1
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 )
- Step 3
Direct form structure for an FIR
filter: H ( z) = ∑b z
N −1
k
−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
b1 −1 b2 − 2 bN −1 − ( N −1)
= b0 1 + z + z + ... + z
b0 b0 b0
∏ (1 + b )
M
−1 −2
= b0 k ,1 z + bk ,2 z
k =1
Realisation Structure Selection
- Step 3
Direct form structure for an FIR
filter: H ( z) = ∑b z
N −1
k
−k
k =0
Cascade structures:
x (n ) b 0 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
Implementation - Step 5
Implementation procedure in ‘C’ with fixed-
point:
Set up the codec (\Links\CodecSetup.pdf).
N −1
y[ n] = ∑ bk ⋅ x[ n − k ]
k =0
Transform: to ‘C’ code.
(\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).
Implementation - Step 5
N −1
y[ n] = ∑ bk ⋅ x[ n − k ] is written in assembly.
k =0
(\Links\FIRFixedAsm.pdf)
b0 x0
b1 x1
b2 x2
b3 x3
y0 = + b1*x1+ b2*x2
+ b3*x3
b0*x0
y[n]
time
0 1 2
Circular addressing link slide.
Implementation - Step 5
b0 x4
b1 x1
b2 x2
b3 x3
y0 = + b1*x1+ b2*x2
+ b3*x3
b0*x0
y1 = + b1*x1+ b2*x2
+ b3*x3
b0*x4
y[n]
time
0 1 2
Circular addressing link slide.
Implementation - Step 5
b0 x4
b1 x5
b2 x2
b3 x3
y0 = + b1*x1+ b2*x2
+ b3*x3
b0*x0
y1 = + b1*x1+ b2*x2
+ b3*x3
b0*x4
y2 = + b1*x5+ b2*x2
+ b3*x3
b0*x4
y[n]
time
0 1 2
Circular addressing link slide.
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
Finite Impulse Response (FIR) Filters
- End -