31
Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter 1, Slide 1 Chapter 14 Chapter 14 Finite Impulse Response (FIR) Filters Finite Impulse Response (FIR) Filters

Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Embed Size (px)

Citation preview

Page 1: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 1

Chapter 14Chapter 14

Finite Impulse Response (FIR) FiltersFinite Impulse Response (FIR) Filters

Page 2: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Learning ObjectivesLearning Objectives

�� Introduction to the theory behind FIR Introduction to the theory behind FIR filters:filters:

�� Properties (including aliasing).Properties (including aliasing).

�� Coefficient calculation.Coefficient calculation.

�� Structure selection.Structure selection.

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 2

�� Implementation in Matlab, C, assembly Implementation in Matlab, C, assembly and linear assembly.and linear assembly.

Page 3: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

IntroductionIntroduction

�� Amongst all the obvious advantages that Amongst all the obvious advantages that digital filters offer, the FIR filter can digital filters offer, the FIR filter can guarantee linear phase characteristics.guarantee linear phase characteristics.

�� (either analogue or IIR filters can achieve (either analogue or IIR filters can achieve this.this.

There are many commercially available There are many commercially available

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 3

�� There are many commercially available There are many commercially available software packages for filter design. software packages for filter design. However, without basic theoretical However, without basic theoretical knowledge of the FIR filter, it will be knowledge of the FIR filter, it will be difficult to use them.difficult to use them.

Page 4: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Properties of an FIR FilterProperties of an FIR Filter

�� Filter coefficients:Filter coefficients:

[ ] [ ]∑−

=

−⋅=1

0

k

k knxbny

x[n]x[n] representsrepresents thethe filterfilter input,input,

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 4

x[n]x[n] representsrepresents thethe filterfilter input,input,

bbk k represents the filter coefficients,represents the filter coefficients,

y[n]y[n] representsrepresents thethe filterfilter output,output,

�� isis thethe numbernumber ofof filterfilter coefficientscoefficients

(order(order ofof thethe filter)filter)..

Page 5: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Properties of an FIR FilterProperties of an FIR Filter

�� Filter coefficients:Filter coefficients:

[ ] [ ]∑−

=

−⋅=1

0

k

k knxbny

z-1 z-1 z-1 z-1x(n)

FIR equationFIR equation

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 5

z-1

+

z-1 z-1

+ +

z-1

y(n)

x(n)

x xxxb0 b1 b2 bN-1

Filter structureFilter structure

Page 6: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Properties of an FIR FilterProperties of an FIR Filter

�� Filter coefficients:Filter coefficients:

[ ] [ ]∑−

=

−⋅=1

0

k

k knxbny

�� If the signal x[n] is replaced by an impulse If the signal x[n] is replaced by an impulse

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 6

�� If the signal x[n] is replaced by an impulse If the signal x[n] is replaced by an impulse

δδ[n] then:[n] then:

[ ] [ ]∑−

=

−=1

0

k

k knbny δ

[ ] [ ] [ ] [ ]�bbby k −++−+= δδδ L100 10

Page 7: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Properties of an FIR FilterProperties of an FIR Filter

�� Filter coefficients:Filter coefficients:

[ ] [ ]∑−

=

−⋅=1

0

k

k knxbny

�� If the signal x[n] is replaced by an impulse If the signal x[n] is replaced by an impulse

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 7

�� If the signal x[n] is replaced by an impulse If the signal x[n] is replaced by an impulse

δδ[n] then:[n] then:

[ ] [ ]∑−

=

−=1

0

k

k knbny δ

[ ] [ ] [ ] [ ]�nbnbnbny k −++−+= δδδ L110

Page 8: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Properties of an FIR FilterProperties of an FIR Filter

�� Filter coefficients:Filter coefficients:

[ ] [ ]∑−

=

−⋅=1

0

k

k knxbny

�� If the signal x[n] is replaced by an impulse If the signal x[n] is replaced by an impulse

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 8

�� If the signal x[n] is replaced by an impulse If the signal x[n] is replaced by an impulse

δδ[n] then:[n] then:

[ ] [ ]∑−

=

−=1

0

k

k knbny δ

[ ]

≠=

=−kn for 0

knfor 1knδ

Page 9: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Properties of an FIR FilterProperties of an FIR Filter

�� Filter coefficients:Filter coefficients:

[ ] [ ]∑−

=

−⋅=1

0

k

k knxbny

�� FinallyFinally::

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 9

�� FinallyFinally::

[ ][ ]

[ ]khb

hb

hb

k =

=

=

M

1

0

1

0

Page 10: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Properties of an FIR FilterProperties of an FIR Filter

�� Filter coefficients:Filter coefficients:

[ ] [ ]∑−

=

−⋅=1

0

k

k knxbny

WithWith:: [ ]khb =

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 10

WithWith:: [ ]khbk =

�� The coefficients of a filter are the same as the The coefficients of a filter are the same as the

impulse response samples of the filter.impulse response samples of the filter.

Page 11: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Frequency Response of an FIR FilterFrequency Response of an FIR Filter

�� By taking the zBy taking the z--transform of h[n], H(z):transform of h[n], H(z):

�� Replacing z by eReplacing z by ejjωω in order to find the in order to find the

( ) [ ]∑−

=

−=1

0

n

nznhzH

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 11

�� Replacing z by eReplacing z by e in order to find the in order to find the

frequency response leads to:frequency response leads to:

( ) ( ) [ ]∑−

=

−=

==1

0

n

jnj

ezenheHzH j

ωωω

Page 12: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Frequency Response of an FIR FilterFrequency Response of an FIR Filter

�� Since eSince e--j2j2ππππππππkk = 1 then:= 1 then:

�� Therefore:Therefore:

( ) [ ] ( ) [ ]∑∑−

=

−−

=

+−=

==+

1

0

1

0

22

n

jn�

n

jn

ezenhenhzH ωπω

πω

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 12

( ) ( )ωπω jkj eHeH =+ 2

�� FIR filters have a periodic frequency FIR filters have a periodic frequency

response and the period is 2response and the period is 2ππ..

Page 13: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Frequency Response of an FIR FilterFrequency Response of an FIR Filter

�� Frequency Frequency response:response:

( ) ( )ωπω jkj eHeH =+2

FIRFIR y[n]y[n]x[n]x[n]

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 13

FFss/2/2FFss/2/2

FreqFreq

FreqFreq

x[n]

x[n]

y[n]

y[n]

Page 14: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Frequency Response of an FIR FilterFrequency Response of an FIR Filter

�� Solution: Use an antiSolution: Use an anti--aliasing filter.aliasing filter.

FIRFIR y[n]y[n]x[n]x[n]

ADCADC

Analogue Analogue

AntiAnti--AliasingAliasing

x(t)x(t)

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 14

FFss/2/2FFss/2/2FreqFreqFreqFreq

x(t)

x(t)

y[n]

y[n]

Page 15: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Phase Linearity of an FIR FilterPhase Linearity of an FIR Filter

�� A causal FIR filter whose impulse A causal FIR filter whose impulse response is symmetrical is guaranteed to response is symmetrical is guaranteed to have a linear phase response.have a linear phase response.

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 15

0n

h(n)

1 n n+1 2n+12n

N = 2n + 2

0n

h(n)

1 n n+1 2n2n-1n-1

N = 2n + 1

Even symmetryEven symmetry Odd symmetryOdd symmetry

Page 16: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Phase Linearity of an FIR FilterPhase Linearity of an FIR Filter

�� Application of 90Application of 90°° linear phase shift:linear phase shift:

Signal Signal

separationseparation

9090oo

delaydelay

delaydelay

++

++

II

ReverseReverse

IHIH

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 16

separationseparation

9090oo

delaydelay

++

--

QQ

ForwardForward

QHQH

tBtAI rf ωω sincos +=

tBtAQ rf ωω cossin += tBtA

tBtAIH

rf

rf

ωω

πωπω

cossin

2sin

2cos

+−=

++

+= tBQIH rωcos2=+

tBIQH fωsin2=−

Page 17: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Design ProcedureDesign Procedure

�� To fully design and implement a filter five To fully design and implement a filter five steps are required:steps are required:

(1)(1) Filter specification.Filter specification.

(2)(2) Coefficient calculation.Coefficient calculation.

(3)(3) Structure selection.Structure selection.

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 17

(4)(4) Simulation (optional).Simulation (optional).

(5)(5) Implementation.Implementation.

Page 18: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Filter Specification Filter Specification -- Step 1Step 1

(a)

1

f(norm)fc : cut-off frequency

pass-band stop-band

pass-band stop-bandtransition band

fs/2

|H(f)| |H(f)|

|H(f)|

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 18

pass-band stop-bandtransition band

1

pass-bandripple

stop-bandripple

fpb : pass-band frequency

fsb : stop-band frequencyf(norm)

(b)

p1 δ+

s∆

p∆0

-3

p1 δ−

fs/2

fc : cut-off frequency

|H(f)|(dB)

|H(f)|(linear)

Page 19: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Coefficient Calculation Coefficient Calculation -- Step 2Step 2

�� There are several different methods There are several different methods available, the most popular are:available, the most popular are:

�� Window method.Window method.

�� Frequency sampling.Frequency sampling.

�� ParksParks--McClellan.McClellan.

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 19

�� We will just consider the window method.We will just consider the window method.

Page 20: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Realisation Structure Selection Realisation Structure Selection -- Step 3Step 3

( ) ∑−

=

−=1

0

k

k

k zbzH

( ) ( ) ( )zXzHzY ⋅= ( ) ( ) ( ) ( )1....1 110 +−++−+= − �nxbnxbnxbny �

�� Direct form structure for an FIR filter:Direct form structure for an FIR filter:

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 20

z-1 z-1 z-1

+ + +

b0

b2

bN-1

y(n)

x(n)

b1

Page 21: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Realisation Structure Selection Realisation Structure Selection -- Step 3Step 3

( ) ∑−

=

−=1

0

k

k

k zbzH

�� Linear phase structures:Linear phase structures:

�� Direct form structure for an FIR filter:Direct form structure for an FIR filter:

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 21

�� N even:N even:

�� N Odd:N Odd:

( ) ( )∑−

=

−−− +=1

2

0

1

k

k�k

k zzbzH

( ) ( )∑

=

−−

−−−− ++=

2

1

0

2

1

2

1

1

k

k�k

k zbzzbzH

Page 22: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Realisation Structure Selection Realisation Structure Selection -- Step 3Step 3

(a) N even.(a) N even.

(b) N odd.(b) N odd.+

b0+

+

+

+b

1

+b

2

+b

N/2-1

y(n)

(a)

z-1

z-1

z-1

z-1

z-1

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 22

+

b0+

+

+

+b1

+b2

+b(N-3)/2

y(n)

x(n)

b(N-1)/2

+

(b)

z-1

z-1

z-1

z-1

z-1

z-1

Page 23: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Realisation Structure Selection Realisation Structure Selection -- Step 3Step 3

( ) ∑−

=

−=1

0

k

k

k zbzH

�� Cascade structures:Cascade structures:

�� Direct form structure for an FIR filter:Direct form structure for an FIR filter:

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 23

( ) ( )

( )

( )∏

=

−−

−−−−−

−−−

−−−

=

++=

++++=

++++==

M

k

kk

��

k

k

k

zbzbb

zb

bz

b

bz

b

bb

zbzbzbbzbzH

1

2

2,

1

1,0

1

0

12

0

21

0

10

1

1

2

2

1

10

1

0

1

...1

...

Page 24: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Realisation Structure Selection Realisation Structure Selection -- Step 3Step 3

( ) ∑−

=

−=1

0

k

k

k zbzH

�� Cascade structures:Cascade structures:

�� Direct form structure for an FIR filter:Direct form structure for an FIR filter:

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 24

z -1

+b

1,1

x(n)

z -1

+

b1,2

z -1

+b

2,1

z -1

+

b2,2

z -1

+b

M,1

z -1

+

bM,2

y(n)b0

Page 25: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Simulation, Step 4Simulation, Step 4

0 20 40 60 80 100 120 140-0.1

0

0.1

0.2

0.3

0.4

Coefficient number, n

h(n)

Truncated Impulse Response

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 25

0 0.5 1 1.5 2

x 104

-6000

-4000

-2000

0

Frequency (Hz)

Pha

se (

degr

ees)

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

x 104

-60

-40

-20

0

Frequency (Hz)

Mag

nitu

de (

dB)

Page 26: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Implementation Implementation -- Step 5Step 5short fir_filter (short input)

{

int i;

short output;

int acc=0;

int prod;

R_in[0] = input; /* Update most recent sample */

acc = 0; /* Zero accumulator */

for (i=0; i<128; i++) /* 128 taps */

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 26

{

prod = (h[i]*R_in[i]); /* Perform Q.15 multiplication */

acc = acc + prod; /* Update 32-bit accumulator, catering */

} /* for temporary overflow */

output = (short) (acc>>15); /* Cast output to 16-bits */

for (i=127; i>0; i--) /* Shift delay samples */

R_in[i]=R_in[i-1];

return output;

}

Page 27: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Filter coefficientsFilter coefficients-0.0002 0.0002 0.0004 0.0002 -0.0002 -0.0005 -0.0003 0.0003

0.0007 0.0004 -0.0004 -0.0009 -0.0005 0.0005 0.0012 0.0007

-0.0007 -0.0016 -0.0009 0.0009 0.0021 0.0012 -0.0013 -0.0027

-0.0015 0.0016 0.0035 0.0019 -0.0020 -0.0044 -0.0024 0.0026

0.0055 0.0030 -0.0032 -0.0069 -0.0037 0.0040 0.0085 0.0045

-0.0049 -0.0105 -0.0056 0.0061 0.0131 0.0070 -0.0076 -0.0165

-0.0089 0.0097 0.0212 0.0117 -0.0128 -0.0285 -0.0159 0.0180

0.0411 0.0239 -0.0284 -0.0699 -0.0452 0.0634 0.2119 0.3183

0.3183 0.2119 0.0634 -0.0452 -0.0699 -0.0284 0.0239 0.0411

0.0180 -0.0159 -0.0285 -0.0128 0.0117 0.0212 0.0097 -0.0089

-0.0165 -0.0076 0.0070 0.0131 0.0061 -0.0056 -0.0105 -0.0049

0.0045 0.0085 0.0040 -0.0037 -0.0069 -0.0032 0.0030 0.0055

0.0026 -0.0024 -0.0044 -0.0020 0.0019 0.0035 0.0016 -0.0015

-0.0027 -0.0013 0.0012 0.0021 0.0009 -0.0009 -0.0016 -0.0007

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 27

-0.0027 -0.0013 0.0012 0.0021 0.0009 -0.0009 -0.0016 -0.0007

0.0007 0.0012 0.0005 -0.0005 -0.0009 -0.0004 0.0004 0.0007

0.0003 -0.0003 -0.0005 -0.0002 0.0002 0.0004 0.0002 -0.0002

Page 28: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Implementation Implementation -- Step 5Step 5

short R_in[128]; /* Input samples R_in[0] most recent, R_in[127] oldest */

/* coefficient calculated with sampling frequency of 48kHz and cutoff at 8kHz*/

short h[]= /* Impulse response of FIR filter */

{ -7, 7, 14, 7, -8, -17, -9 , 10,

22, 12, -13, -29, -16, 18, 39 , 22,

-24, -52, -29, 31, 69, 38, -41 , -89,

-49, 53, 114, 62, -67, -144, -78 , 84,

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 28

181, 97, -104, -225, -121, 130, 278 , 149,

-160, -345, -185, 199, 429, 231, -250 , -541,

-293, 319, 696, 382, -421, -933, -522 , 589,

1347, 783, -932, -2292, -1480, 2079, 6945 , 10429,

10429, 6945, 2079, -1480, -2292, -932, 783 , 1347,

589, -522, -933, -421, 382, 696, 319 , -293,

-541, -250, 231, 429, 199, -185, -345 , -160,

149, 278, 130, -121, -225, -104, 97 , 181,

84, -78, -144, -67, 62, 114, 53 , -49,

-89, -41, 38, 69, 31, -29, -52 , -24,

22, 39, 18, -16, -29, -13, 12 , 22,

10, -9, -17, -8, 7, 14, 7 , -7};

Page 29: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

void main()

{

DSK6713_AIC23_CodecHandle hCodec;

Int16 OUT_L,OUT_R;

Uint32 IN_L,IN_R;

/* Initialize the board support library, must be called first */

DSK6713_init();

/* Start the codec */

hCodec = DSK6713_AIC23_openCodec(0, &config);

// Set codec frequency to 48KHz

DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_48KHZ );

while (1)

{

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 29

// Read sample from the left channel

while (!DSK6713_AIC23_read(hCodec, &IN_L));

// Read sample from the right channel

while (!DSK6713_AIC23_read(hCodec, &IN_R));

OUT_L = fir_filter(IN_L);

OUT_R = IN_R;

/* Send the FILTERED sample to the left channel */

while (!DSK6713_AIC23_write(hCodec, OUT_L));

/* Send a NON FILTERED sample to the right channel */

while (!DSK6713_AIC23_write(hCodec, OUT_R));

}

/* Close the codec */

DSK6713_AIC23_closeCodec(hCodec);

}

Page 30: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Floating Point ImplementationFloating Point Implementation

float R_in[128]; /* Input samples R_in[0] most recent, R_in[127] oldest. */

float h[]= /* Impulse response of FIR filter. Taken from fir_coef.txt */

{

-0.0001,0.0003,0.0004,0.0002,-0.0002,-0.0005,-0.0004,0.0001,

0.0006,0.0006,0.0001,-0.0006,-0.0010,-0.0005,0.0005,0.0013,

0.0010,-0.0002,-0.0016,-0.0017,-0.0003,0.0016,0.0025,0.0012,

-0.0013,-0.0032,-0.0025,0.0006,0.0036,0.0039,0.0007,-0.0036,

-0.0054,-0.0027,0.0029,0.0068,0.0052,-0.0012,-0.0076,-0.0081,

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 30

-0.0015,0.0074,0.0112,0.0055,-0.0059,-0.0139,-0.0108,0.0026,

0.0159,0.0173,0.0033,-0.0165,-0.0254,-0.0129,0.0145,0.0355,

0.0291,-0.0075,-0.0507,-0.0623,-0.0141,0.0897,0.2093,0.2890,

0.2890,0.2093,0.0897,-0.0141,-0.0623,-0.0507,-0.0075,0.0291,

0.0355,0.0145,-0.0129,-0.0254,-0.0165,0.0033,0.0173,0.0159,

0.0026,-0.0108,-0.0139,-0.0059,0.0055,0.0112,0.0074,-0.0015,

-0.0081,-0.0076,-0.0012,0.0052,0.0068,0.0029,-0.0027,-0.0054,

-0.0036,0.0007,0.0039,0.0036,0.0006,-0.0025,-0.0032,-0.0013,

0.0012,0.0025,0.0016,-0.0003,-0.0017,-0.0016,-0.0002,0.0010,

0.0013,0.0005,-0.0005,-0.0010,-0.0006,0.0001,0.0006,0.0006,

0.0001,-0.0004,-0.0005,-0.0002,0.0002,0.0004,0.0003,-0.0001

};

Page 31: Chapter 14 Finite Impulse Response (FIR) Filtersgalia.fc.uaslp.mx/~rmariela/RTDSP/ch62.pdf · Chapter 1, Slide 1 Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004 Chapter

Floating Point ImplementationFloating Point Implementation

short fir_filter (short sample)

{

int i;

float acc=0;

float prod;

R_in[0] = (float) sample; /* Update most recent sample */

acc = 0; /* Zero accumulator */

for (i=0; i<128; i++) /* 128 taps */

Dr. Naim Dahnoun, Bristol University, (c) Texas Instruments 2004Chapter 1, Slide 31

for (i=0; i<128; i++) /* 128 taps */

{

prod = (h[i]*R_in[i]);

acc = acc + prod;

}

for (i=127; i>0; i--) /* Shift delay samples */

R_in[i]=R_in[i-1];

return (acc);

}