0% found this document useful (0 votes)
137 views39 pages

Finite Impulse Response (FIR) Filters

This document discusses finite impulse response (FIR) filters. It covers the basic properties of FIR filters, including that they have a linear phase response. It discusses calculating filter coefficients and selecting a filter structure. The frequency response of FIR filters is periodic with a period of 2π. For a filter to have a linear phase response, its impulse response must be symmetrical. The document outlines a five step design procedure for FIR filters: 1) specification, 2) coefficient calculation, 3) structure selection, 4) simulation, and 5) implementation.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views39 pages

Finite Impulse Response (FIR) Filters

This document discusses finite impulse response (FIR) filters. It covers the basic properties of FIR filters, including that they have a linear phase response. It discusses calculating filter coefficients and selecting a filter structure. The frequency response of FIR filters is periodic with a period of 2π. For a filter to have a linear phase response, its impulse response must be symmetrical. The document outlines a five step design procedure for FIR filters: 1) specification, 2) coefficient calculation, 3) structure selection, 4) simulation, and 5) implementation.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 39

Chapter 14

Finite Impulse Response (FIR) Filters


Learning Objectives
Introduction to the theory behind FIR filters:
Properties (including aliasing).
Coefficient calculation.
Structure selection.
Implementation in Matlab, C, assembly and
linear assembly.
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.
Properties of an FIR Filter N −1
Filter coefficients: y[ n] = ∑ bk ⋅ x[ n − k ]
k =0

x[n] represents the filter input,


bk represents the filter coefficients,
y[n] represents the filter output,
N is the number of filter
coefficients (order of the
filter).
Properties of an FIR Filter
Filter coefficients: N −1
y[ n] = ∑ bk ⋅ x[ n − k ]
k =0
FIR equation

-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

 If the signal x[n] is replaced by an


impulse δ [n] then:
N −1
y[ n ] = ∑b δ [n − k ]
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

 If the signal x[n] is replaced by an


impulse δ [n] then:
N −1
y[ n ] = ∑b δ [n − k ]
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

 If the signal x[n] is replaced by an


impulse δ [n] then:
N −1
y[ n ] = ∑b δ [n − k ]
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:

 The coefficients of a filter are the


same as the impulse response
samples of the filter.
Frequency Response of an FIR
Filter
By taking the z-transform of h[n], H(z):
N −1
H ( z ) = ∑ h[ n] z − n
n =0

 Replacing z by ejω in order to find


the frequency response leads to:

( )
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ω )

 FIR filters have a periodic frequency


response and the period is 2π .
Filter
Frequency ( ) ( )
H e jω + 2 kπ = H e jω
response:

x[n] FIR y[n]


x[n]

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

Even symmetry Odd symmetry


Phase Linearity of an FIR
Filter
A causal FIR filter whose impulse response is symmetrical
(i.e. h[n] = h[N-1-n] for n = 0, 1, …, N-1) is guaranteed to
have a linear phase response.

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

I = A cos ω f t + B sin ω r t  π  π IH + Q = 2 B cos ωr t


IH = A cos ω f t +  + B sin ωr t + 
 2  2
Q = A sin ω f t + B cos ω r t = − A sin ω f t + B cos ωr t QH − I = 2 B sin ω f t
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.
Filter Specification - Step 1
|H ( f)| p a s s -b a n d s to p - b a n d

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 )

|H ( f)| p a s s -b a n d t ra n s itio n b a n d s to p - b a n d |H ( f)|


(d B ) ( lin e a r )

p 1 +p δ
0 1
1 −p δ
p a ss -b a n d
-3
r ip p le

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;

fc = 8000/44100; % cut-off frequency


N = 133; % number of taps
n = -((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 function
d = 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 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

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2


Frequency (Hz) 4
x 10
0
Phase (degrees)

-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

 Linear phase structures:


N
−1

∑ ( )
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

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
Implementation - Step 5
Implementation procedure in assembly:
Same set up as fixed-point, however:

N −1
 y[ n] = ∑ bk ⋅ x[ n − k ] is written in assembly.
k =0

(\Links\FIRFixedAsm.pdf)

The ISR is now declared as external.


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 initialized by setting the
appropriate values of the AMR bit fields.
The data is now aligned using:
#pragma DATA_ALIGN (symbol, constant (bytes))

Set the initial value of the circular pointers,


see \Links\FIRFixedAsm.pdf.
Implementation - Step 5

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 -

You might also like