《Chapter-14Finite-Impulse-Response-(FIR)-Filter-Imp.ppt》由会员分享,可在线阅读,更多相关《Chapter-14Finite-Impulse-Response-(FIR)-Filter-Imp.ppt(108页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、DSP C5000Chapter 14Finite Impulse Response(FIR)Filter ImplementationCopyright 2003 Texas Instruments.All rights reserved.Copyright 2003 Texas Instruments.All rights reserved.ESIEE,Slide 2OutlineDigital Filters and FIR filtersImplementation of FIR Filters on C54xImplementation of FIR Filters on C55xC
2、omparison of C54x and C55xESIEE,Slide 3Outline of FIR FiltersGeneralities on Digital FiltersFIR Filters with MatlabImplementation of FIR FiltersESIEE,Slide 4Digital FiltersESIEE,Slide 5ESIEE,Slide 6Impulse ResponseESIEE,Slide 7Input-Output Relationship,ConvolutionESIEE,Slide 8Input-Output Relationsh
3、ip,ConvolutionUsing linearity and time invariance:ESIEE,Slide 9ESIEE,Slide 10Frequency Transfer FunctionFor a digital filter the frequency transfer function is periodic.PhasePhaseGroup Group delaydelayAmplitudeAmplitudeESIEE,Slide 11Relationship Between Fourier Transforms of Input and OutputESIEE,Sl
4、ide 12ESIEE,Slide 13Basic Relationships of a Digital FilterESIEE,Slide 14ESIEE,Slide 15IIR and FIR FiltersIIR=Infinite Impulse ResponseFIR=Finite Impulse ResponseFIRIIRESIEE,Slide 16FIR and IIRFIR:output yn is a linear combination of a finite number of input samples.IIR:output yn is a linear combina
5、tion of a finite number of input and of output samples.Recursive form.ESIEE,Slide 17ESIEE,Slide 18Representation of Poles and Zeroes of H(z)in the Complex PlaneESIEE,Slide 19Some Useful Matlab FunctionsExample for a FIR filter:Enter the filter coefficients vector b:w wb=1 1 1 1;a=1;b=1 1 1 1;a=1;Cal
6、culate transfer function Hf,its amplitude and phase on 256 samples,with fs=1:w wHf,f=freqz(b,a,256,1);Hf,f=freqz(b,a,256,1);w wHfA=abs(Hf);HfA=abs(Hf);w wHfphi=angle(Hf);Hfphi=angle(Hf);ESIEE,Slide 20Some Useful Matlab Functions Plot impulse response:stem(b)Plot amplitude and phase of transfer funct
7、ion:plot(f,HfA)and plot(f,Hfphi)ESIEE,Slide 21Some Useful Matlab FunctionsGenerate a test signal=sum of cosines:w wx=cos(2*pi*0:99*0.25)+2*cos(2*pi*0:99*0.1);x=cos(2*pi*0:99*0.25)+2*cos(2*pi*0:99*0.1);Apply the filter to x.Output is y:Apply the filter to x.Output is y:w wy=filter(b,a,x);y=filter(b,a
8、,x);Plot the results:Plot the results:plot(x);plot(y)plot(x);plot(y)x is the sum of x is the sum of 2 frequencies:2 frequencies:0.25 and 0.1.0.25 and 0.1.The filter The filter cancels the cancels the frequency 0.25.frequency 0.25.y has only the y has only the freq.0.1.freq.0.1.ESIEE,Slide 22Calculat
9、ion of a FIR using MatlabFor given attenuation and frequency response characteristics,the transfer function can be calculated using different methods:w wMean square error,miniMax(Chebychev)Mean square error,miniMax(Chebychev)w wEmpirical window method Empirical window method Corresponding Matlab fun
10、ctionsw wfirlsfirls and and remezremez.w wfirfir and and fir1fir1.ESIEE,Slide 23ESIEE,Slide 24Example using MatlabVector of limited frequencies(normalized)Vector of limited frequencies(normalized)w wF=0 1200 2600 4800/4800;F=0 1200 2600 4800/4800;Vector of required amplitudes:Vector of required ampl
11、itudes:w wA=1 1 0 0;A=1 1 0 0;Least square calculation of filter:Least square calculation of filter:w wBls=firls(23,F,A);Bls=firls(23,F,A);Mini Max calculation of filter:Mini Max calculation of filter:w wBre=remez(21,F,A);Bre=remez(21,F,A);Window method(Hamming):Window method(Hamming):w wBwin=fir1(2
12、5,(1200+2600)/9600);Bwin=fir1(25,(1200+2600)/9600);ESIEE,Slide 25Results of Matlab ExampleThe minimum orders to satisfy the constraints are 23 for LS,21 for minimax and 25 for the window method.Mini Max Mini Max windowwindowLeast square Least square methodmethodWindow Window methodmethodESIEE,Slide
13、26Results of Matlab ExampleImpulse Responsehnhnn nESIEE,Slide 27ESIEE,Slide 28FIR filters with Constant Group Delay or Linear PhaseAsymmetric case:linear phaseAsymmetrical case:ESIEE,Slide 29Fixed Point Implementation of FIR FiltersNumerical IssuesFixed point implementation:w w16 bits for data and c
14、oefficients16 bits for data and coefficientsw wAccumulators have size 40 bitsAccumulators have size 40 bitsFixed point representation of dataw wSize B=16 bits,Format Qk:k fractional bitsSize B=16 bits,Format Qk:k fractional bitsQuantization of coefficientsw wMaximum magnitude coefficient=hmaxMaximum
15、 magnitude coefficient=hmaxw wNumber of bits of the integer part of Number of bits of the integer part of coefficients is Bi:coefficients is Bi:w w Bi=log Bi=log2 2(hmax)(hmax)w wCoefficients in Qk with k=16-BiCoefficients in Qk with k=16-BiESIEE,Slide 30ESIEE,Slide 31Matlab ExampleCan be edited to
16、be used with CCS.ESIEE,Slide 32FIR Implementation,Numerical issues,FRCT bitCommon case:w wData and coefficients in Q15 formatData and coefficients in Q15 formatw wProduct h(i)x(n-i)in Q30(2 sign bits)Product h(i)x(n-i)in Q30(2 sign bits)w wBy shifting products 1 bit left,the product By shifting prod
17、ucts 1 bit left,the product are in Q31 format with only 1 sign bit.are in Q31 format with only 1 sign bit.w wIf the FRCT bit(Fraction)is set to 1,If the FRCT bit(Fraction)is set to 1,products are automatically shifted 1 bit products are automatically shifted 1 bit left.left.ESIEE,Slide 33Structures
18、for FIR ImplementationCommon structures for FIR filtersw wTransversal structures Transversal structures w wTrellis structureTrellis structurew wUseful in some adaptive situations.Useful in some adaptive situations.Transversal structures using:w wLinear buffersLinear buffersw wCircular buffersCircula
19、r buffersSpecial case for symmetrical or asymmetrical FIRs.ESIEE,Slide 34Transversal Structures of FIRStructure with a delay lineTransposed structureESIEE,Slide 35Implementation of a FIR with a Delay LineMost common structure used in DSP.w wThe delay line can be implemented using a The delay line ca
20、n be implemented using a linear or a circular buffer.linear or a circular buffer.Basic operations:w wRead a new data value x(n)every TRead a new data value x(n)every TS Sw wACCU=0ACCU=0w wfor i=0 to N-1:for i=0 to N-1:w wMultiply h(i)by x(n-i)and add it to Multiply h(i)by x(n-i)and add it to accumul
21、atoraccumulatorw wOutput y(n)Output y(n)ESIEE,Slide 36Implementation of FIR Filters on C54xImplementation of General Transversal FIR filtersw wUsing linear buffersUsing linear buffersw wUsing circular buffersUsing circular buffersImplementation of Symmetrical FIR filtersESIEE,Slide 37Operations usin
22、g a Linear Buffer for a FIR with N CoefficientsLength of the delay line=N samplesRead a new sample x(n)and store it in the delay line in the first position.ACCU=0for i=0 to N-1w wRead h(i)and x(n-i)Read h(i)and x(n-i)w wMultiply h(i)by x(n-i)and add it to ACCUMultiply h(i)by x(n-i)and add it to ACCU
23、Output y(n)N-1 Shifts in the delay line.ESIEE,Slide 38Linear Buffer,MACD ModeInstead of shifting N-1 samples at the end,do the shift in the loop one by one.Read a new sample xn and store it in the delay line in the first position.ACCU=0for i=N-1 to 0w wRead h(i)and x(n-i)Read h(i)and x(n-i)w wMultip
24、ly h(i)by x(n-i)and add it to ACCUMultiply h(i)by x(n-i)and add it to ACCUw wShift x(n-i)in the delay line Shift x(n-i)in the delay line Output y(n)ESIEE,Slide 39MACD InstructionMACD:w wMultiply Accumulate and Delay move.Multiply Accumulate and Delay move.w wMACD Smem,pmad,srcMACD Smem,pmad,srcw wsr
25、c=src+Smem*pmad;src=src+Smem*pmad;w wT=Smem;T=Smem;w w(Smem+1)=Smem(Smem+1)=Smemw wIf If MACDMACD used in a loop with used in a loop with RPTRPT the the program memory(pmad)address is program memory(pmad)address is automatically incremented.automatically incremented.w wMACD alone=3 cycle timesMACD a
26、lone=3 cycle timesw wIn a RPT loop 1 cycle timeIn a RPT loop 1 cycle timeESIEE,Slide 40Implementing a FIR with MACDMemory organization of data and coefficientsESIEE,Slide 41Initialization of RegistersSTM Stores#value to the MMR earlyin the pipeline to avoid latencies.w w2 words,2cycles.2 words,2cycl
27、es.Initialization of FRCT bit(fractional mode):w wInstructionsInstructions SSBX SSBX(Set Status Bit)and (Set Status Bit)and RSBXRSBX(Reset Status Bit).(Reset Status Bit).Initialization of ACCUw wUsing Using RPTZRPTZ:RePeaT after initializing :RePeaT after initializing ACCU at 0ACCU at 0w wOr via Or
28、via LD#0,A LD#0,A ESIEE,Slide 42RPT,RPTZ InstructionsRPT#nw wRepeat next instruction n+1 times.Repeat next instruction n+1 times.Repetition counter set to n and decreases Repetition counter set to n and decreases until 0.until 0.w w1 or 2 cycles,not interruptible.1 or 2 cycles,not interruptible.RPTZ
29、 src,#nw wSame as repeat,except that src ACCU is Same as repeat,except that src ACCU is cleared to zero before repeat.cleared to zero before repeat.w w2 cycles,not interruptible.2 cycles,not interruptible.Some instructions execute faster when in repeat mode(pipeline).ESIEE,Slide 43Implementing a FIR
30、 Filter with MACDTest with CCSw wFilter with N=32 coefficients all equal to 1/32Filter with N=32 coefficients all equal to 1/32w wCreate a,address of coefficients in program mem Create a,address of coefficients in program mem=adr_coef=adr_coefESIEE,Slide 44Implementing a FIR Filter with MACD coeffic
31、ients fircoef.asmESIEE,Slide 45Implementing a FIR Filter with MACD with the programw w2 files to compile and link:2 files to compile and link:w wfircoef.asm and firmacd.asmfircoef.asm and firmacd.asmTest by associating files on the ports DRR0 and DXR0w w attached to DRR0 attached to DRR0w w attached
32、 to DXR0 attached to DXR0ESIEE,Slide 46Implementing a FIR Filter with MACDProgram:initializationsESIEE,Slide 47Implementing a FIR Filter with MACDProgram:endless loopSee files See files firmacd.asm firmacd.asm and and fircoef.asm fircoef.asm for the test in for the test in directory directory tutori
33、al.tutorial.ESIEE,Slide 48FIR with MACD,Test with CCSCreate project,create command file,compile and link.To test the impulse response:w wCreate a with:Create a with:w w A value 0.5(0 x4000)then zeros(at least 40)A value 0.5(0 x4000)then zeros(at least 40)w wSet 2 probe pointsSet 2 probe pointsw w1 a
34、t reading of DRR:LDM DRR1 at reading of DRR:LDM DRRw w1 at end of loop:B debut1 at end of loop:B debutw wAttach files to probe pointsAttach files to probe pointsw winfir.dat at 1rst probe point(read value stored infir.dat at 1rst probe point(read value stored at address 0 x20 DRR)at address 0 x20 DR
35、R)w woutfir.dat at second probe point(data at outfir.dat at second probe point(data at address 0 x21 DXR is strored in the file)address 0 x21 DXR is strored in the file)ESIEE,Slide 49ResultsLet program run until end of Load at some address in the DSP data memory()Plot the content of this memory area
36、(View-Graph-Time/Frequency).w wPlot a time graph(Plot a time graph(Single TimeSingle Time)w wPlot a frequency graph(Plot a frequency graph(FFT:Magnitude FFT:Magnitude and Phaseand Phase)ESIEE,Slide 50Results for the impulse response and its FFTESIEE,Slide 51Second TestNew test with a sine input.Repl
37、ace infir.dat by containing 80 samples of a sine with 40 samples per period of sine.Name outsine.dat the result file.Repeat the same operations as in the preceding test.ESIEE,Slide 52Second testObserve that the output is attenuated and is phase Observe that the output is attenuated and is phase shif
38、ted by values corresponding at H(f)at fshifted by values corresponding at H(f)at fS S/40./40.ESIEE,Slide 53Implementation using a Circular BufferA circular buffer of length N is a block of contiguous memory words addressed by a pointer using a modulo N addressing mode.w wThe 2 extreme words of the m
39、emory block The 2 extreme words of the memory block are considered as contiguous.are considered as contiguous.Characteristics of a circular buffer:w wInstead of moving the N data in memory,Instead of moving the N data in memory,just modify the pointers.just modify the pointers.w wWhen a new data x(n
40、)arrives,the pointer When a new data x(n)arrives,the pointer is incremented and the new data is written is incremented and the new data is written in place of the oldest one.in place of the oldest one.ESIEE,Slide 54Trace of Memory and Pointer in a Circular Buffer of Length 3ESIEE,Slide 55FIR with Ci
41、rcular Buffers2 circular buffersw w1 for data1 for dataw w1 for coefficients1 for coefficientsESIEE,Slide 56Operation of FIR with Circular BufferRead a new input sample x(n)Store it at address of pnt_dataACCU=0for i=1 to N-1w wmultiply data pointed by pnt_data by multiply data pointed by pnt_data by
42、 coefficient pointed by pnt_coef.Add coefficient pointed by pnt_coef.Add product to ACCUproduct to ACCUw wdecrement pointers pnt_data and pnt_coefdecrement pointers pnt_data and pnt_coefendoutput y(n)from ACCUincrement pnt_data of 1ESIEE,Slide 57Instruction MAC with 2 operands in Indirect Addressing
43、 ModeMAC:Multiply and Accumulatew wMAC Xmem,Ymem,src,destMAC Xmem,Ymem,src,destw wdst=src+Xmem*Ymemdst=src+Xmem*Ymemw wT=XmemT=Xmemw wWith Xmem,Ymem use only AR2 to AR5With Xmem,Ymem use only AR2 to AR5w wCan be executed in 1 cycle time.Can be executed in 1 cycle time.Dual operand instructions indir
44、ect addressing restricted to:w wAR2,AR3,AR4,AR5AR2,AR3,AR4,AR5w wnone,+,-,+0%none,+,-,+0%ESIEE,Slide 58Circular Buffer with C54xCircular indirect addressing mode:w w*ARi-%,*ARi+%,*ARi-0%,*ARi+0%,*ARi-%,*ARi+%,*ARi-0%,*ARi+0%,*ARi(lk)%*ARi(lk)%w wIn dual operand mode Xmem,Ymem:In dual operand mode Xm
45、em,Ymem:w w*ARi+0%*ARi+0%only valid mode only valid modew wTo perform a decrement,store a negative value To perform a decrement,store a negative value in AR0.in AR0.BK register:w wStores the size N of the circular buffer.Stores the size N of the circular buffer.w wMust be initialized before use.Must
46、 be initialized before use.w wThere may be several circular buffers at There may be several circular buffers at different addresses at the same time but different addresses at the same time but with the same length.with the same length.ESIEE,Slide 59Limitations on Start Addresses of Circular Buffers
47、If N is written on nb bits in binary,the start address must have its nb LSB at 0:w wExamples:Examples:w wfor N=32,6 LSB of start address=0for N=32,6 LSB of start address=0w wfor N=30,5 LSB of start address=0for N=30,5 LSB of start address=0To access a circular buffer:w wInitialize BK with N(nb bits)
48、Initialize BK with N(nb bits)w wChoose 1 ARi as a pointerChoose 1 ARi as a pointerw wThe effective start address of the buffer is the The effective start address of the buffer is the value in ARi with its nb LSB at 0.value in ARi with its nb LSB at 0.w wThe end address=start addess+N-1.The end addre
49、ss=start addess+N-1.ESIEE,Slide 60Circular buffer on C54xESIEE,Slide 61Implementation of FIR Filter with 2 Circular BuffersSame filter as in the preceding example,coefficients in section.coef(in program memory)in.N=322 buffers are allocated in data memory for the coefficients and the data of the fil
50、tersw wStart addresses must be multiple of 64.Start addresses must be multiple of 64.First step of program after initialization:w wTransfer coefficients from program to data Transfer coefficients from program to data memory from adr_coef to adr_debut_coef.memory from adr_coef to adr_debut_coef.ESIEE