Fir V2.07
Fir V2.07
Chapter 14
Finite Impulse Response (FIR)
Filter Implementation
Sampling
frequency
fS
Analog xn yn
x(t) anti- A D Analog y(t)
aliasing D Digital Filter A smoothing
C C filter
filter
xn yn
Digital Filter
1 R
1x1( n ) 2 x2 ( n ) 1 y1( n ) 2 y2 ( n )
2 R
Time Invariance
x ( n ) y ( n ) x ( n n0 ) y ( n n0 )
n 0 un 0
Impulse sequence un u0 1
n 0 u 0
n
un hn
Digital Filter
n=0
k k
yn xk hn k hk xn k
k k
j 0 nTe
xn e
y n xn H (0 )
k
H (0 ) hk e j 0 kTe
k
j arg( H ( 0 )) j ( 0 )
H (0 ) H (0 ) e A(0 )e
( )
( ) arg H ( )
Phase Group
delay
SIEE, Slide 10 Copyrig
Relationship Between Fourier Transforms
of Input and Output
n n
X ( ) xne jnTe
Y ( ) yne jnTe
n n
Y ( ) H ( ) X ( )
H(z) hn z n
n
H ( ) hne jnTe
H ( z ) z e jTe
n
Y( z) X ( z)H( z)
k k
yn xk hnk hk xnk
k k
Y ( ) H ( ) X ( )
Y( z) X ( z)H( z)
N(z)
bi z i
i0
H(z) P
D( z )
1 ak z k
k 1
IIR
N(z)
H(z) With D( z ) constant.
D( z )
SIEE, Slide 15 Copyrig
FIR and IIR
FIR: output yn is a linear combination of a
finite number of input samples.
Q Q
yn hi xn i bi xn i , bi hi .
i 0 i 0
Imaginary Part
1
0.5
Real Part
0
-0.5
-1
-1 -0.5 0 0.5 1
3
0
2.5
-0.5
-1
1.5
-1.5
1
-2
0.5
-2.5
0.05 0.1 0.15 0.2 0.3 0.35 0.4 0.45 0
0 0.25 0.5 0
0.05 0.1 0.15 0.2
0.25
0.3 0.35 0.4 0.45
0.5
Frequency, FS=1 Frequency, FS=1
x is the sum of 1 2
2 frequencies :
0.25 and 0.1.
The filter
0 0
-1 -2
cancels the
frequency 0.25.
y has only the
-2 -4
-3 -6
freq. 0.1.
0 20 40 60 80 100 0 20 40 60 80 100
Time Time
SIEE, Slide 21 Copyrig
Calculation of a FIR using Matlab
For given attenuation and frequency
response characteristics, the transfer
function can be calculated using
different methods:
Mean square error, miniMax (Chebychev)
Empirical window method
Corresponding Matlab functions
firls and remez.
fir and fir1.
f in Hz
1200 2600
SIEE, Slide 23 Copyrig
Example using Matlab
Vector of limited frequencies (normalized)
F=[0 1200 2600 4800]/4800;
Vector of required amplitudes:
A=[1 1 0 0];
Least square calculation of filter:
Bls=firls(23,F,A);
Mini Max calculation of filter:
Bre=remez(21,F,A);
Window method (Hamming):
Bwin=fir1(25,(1200+2600)/9600);
Least square
120
method
100
80 Window
method
60
40
20
Mini Max
0
window
-20
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
hn
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0 n
-0.05
-0.1
0 5 10 15 20 25
( f ) kf
Asymmetrical case:
( f ) kf
2
Transposed structure
yn
bN-1 bN-2 b3 b2 b1 b0
xn
.text
* Initialization of DP and FRCT
LD #0, DP
SSBX FRCT
* Initialization of AR0, AR1, AR2
STM #(adr_debut_dat),AR2
STM #(adr_debut_dat-1),AR1
STM #N, AR0
SIEE, Slide 46 Copyrig
Implementing a FIR Filter with MACD
Program file firmacd.asm: endless loop
debut:
* set AR1 at adr_fin_dat
MAR *AR1+0
* Read x(n) at DRR See files
LDM DRR0, A firmacd.asm
STL A,*AR2 and
fircoef.asm
* Endless filter loop for the test in
RPTZ A, #N-1 directory
MACD *AR1-, adr_coef, A tutorial.
* Write y(n) in DXR
* by saving the high part of ACCU in DXR
STH A,DXR0
* Go back to the beginning of the loop
B debut
ARi
End_address =
xxxxxxxxxxx11111
N .set 32
adr_debut_dat .usect "buf_data", N
adr_debut_coef .usect "buf_coef", N
adr_fin_dat .set adr_debut_dat+N-1
adr_fin_coef .set adr_debut_coef+N-1
.text
* Initialization of BK,AR0,FRCT
STM #N, BK
STM #-1, AR0
SSBX FRCT
* Initialization of AR2, AR3
STM #(adr_debut_dat),AR2
STM #(adr_fin_coef),AR3
SIEE, Slide 63 Copyrig
Implementation of FIR with 2 Circular
Buffers, Program
* Transfer of coefficients from
* program to data memory
STM #adr_debut_coef, AR4
RPT #N-1
MVPD adr_coef, *AR4+
N
1
2
y (n) b(i ) x(n i ) x(n N 1 i ) N even
i 0
N 1
1
2 N 1 N 1
y (n) b(i ) x(n i ) x(n N 1 i ) b x
n N odd
i 0 2 2
adr_debut_dat1
x(n-3)
AR3
x(n-5)
x(n-4)
Example for N = 6
2 circular
buffers
SIEE, Slide 68 Copyrig
Using FIRS for a Symmetrical FIR Filter
BK = N/2
At the beginning AR2 and AR3 point to:
the newest data x(n)
and the oldest data x(n-N+1)
x(n-N/2) x(n-N/2)
x(n-N+1) x(n-N+1)
x(n-N/2-1) x(n-N+2) x(n-N/2-1) x(n-N+2)
.text
* Initialization of BK, AR0,FRCT
STM #Nsur2, BK
STM #-2, AR0
SSBX FRCT
* Initialization of AR2, AR3
STM #(adr_debut_dat0),AR2
STM #(adr_debut_dat1),AR3
Implementation of symmetrical or a
symmetrical FIR filters
MAC
t MAC
AC
A0
AC1
SIEE, Slide 75 Copyrig
Using the 2 MAC Units
Use of block Data Read Buses
filtering in order to
calculate 2 output
samples at a time. MAC
t MA C
N 1
yn m bi xn mi m 0, M 1.
i 0
yn = b0xn+b1xn-1+b2xn-2+b3xn-3
yn-1 = b0xn-1+b1xn-2+b2xn-3+b3xn-4
yn-2 = b0xn-2+b1xn-3+b2xn-4+b3xn-5
SIEE, Slide 78 Copyrig
Block Filter Example
Double loop:
On coefficients and on m
Coefficients accessed by CDP:
CDP (Cmem) modifications limited to:
*CDP, *CDP+, *CDP-, *(CDP+T0).
CDP uses B bus only for dual-MAC.
Because B bus is internal only, coefficients
must also be internal.
Place data operands carefully to avoid
memory conflicts (SA/DARAM).
b0 Xeven : BSAxx
b1
BKzz
b2 ARn/CDP
b3
.sect "code"
.DP a0
start: AMOV #BOS+stklen,XSPc ;set up Stack +
MOV #BOSS+stklen,SSP ;System Stack Ptrs
CALL copy ;copy coeffs
RPTBlocal end
MPYM *AR2+,*CDP ,AC0 ;AC0 1st product
MPYM *AR3+,*CDP+,AC1 ;AC1 gets 2nd prd
RPT #14
MAC *AR2+,*CDP+,AC0 ;form results
:: MAC *AR3+,*CDP+,AC1
MOV pair(hi(AC0)),dbl(*AR4+) ;store AC0/AC1
ASUB #14,AR2 ;wrap data pointers
end ASUB #14,AR3 ;next calculation
RET
These filters may be “folded” and performed with N adds and N/2 MACs
Filters need to be designed as even length
N
1
2
y (n) b(i ) x(n i ) x(n N 1 i ) N even.
i 0