1快速傅立叶变换(FFT)的实现一、实验目的1.了解FFT的原理及算法;2.了解DSP中FFT的设计及编程方法;3.熟悉FFT的调试方法;二、实验原理FFT是一种高效实现离散付立叶变换的算法,把信号从时域变换到频域,在频域分析处理信息。对于长度为N的有限长序列x(n),它的离散傅里叶变换为:(2/)jNnkNWe,称为旋转因子,或蝶形因子。在x(n)为复数序列的情况下,计算X(k):对某个k值,需要N次复数乘法、(N-1)次复数加法;对所有N个k值,需要2N次复数乘法和N(N-1)次复数加法。对于N相当大时(如1024)来说,直接计算它的DFT所作的计算量是很大的,FFT的基本思想在于:利用2()jnkNNWe的周期性即:kNkNNWW对称性:/2kkNNNWW将原有的N点序列分成两个较短的序列,这些序列的DFT可以很简单的组合起来得到原序列的DFT。按时间抽取的FFT——DITFFT信号流图如图5.1所示:图5.1时间抽取的FFT—DITFFT信号流图FFT算法主要分为以下四步。第一步输入数据的组合和位倒序10)()(NnnkNWnxkX2把输入序列作位倒序是为了在整个运算最后的输出中得到的序列是自然顺序。第二步实现N点复数FFT第一级蝶形运算;第二级蝶形运算;第三级至log2N级蝶形运算;FFT运算中的旋转因子NW是一个复数,可表示:为了实现旋转因子NW的运算,在存储空间分别建立正弦表和余弦表,每个表对应从0度到180度,采用循环寻址来对正弦表和余弦表进行寻址。第三步功率谱的计算X(k)是由实部()RXk和虚部()IXk组成的复数:()()()RIXkXkjXk;计算功率谱时只需将FFT变换好的数据,按照实部()RXk和虚部()IXk求它们的平方和,然后对平方和进行开平方运算。第四步输出FFT结果。三、实验内容与步骤1.本实验要求使用FFT变换求一个时域信号的频域特性,并从这个频域特性求出该信号的频率值,然后使用DSP汇编语言对FFT的DSP编程。2.将计算机与DES-320PP—A教学实验系统连接好,打开实验箱电源,然后运行CCS软件。2.新建fft.pjt工程文件,并输入FFT的DSP程序及命令链接文件。如下:***************************************Radix-2,DIT,Real-inputFFTProgram**fft.asm**************************************.mmregs.globalreset,start,sav_sin,sav_idx,sav_grp.defstart,_c_int00.dataDATA.space1024.copyfft.incN.set128LOGN.set7sav_grp.usecttempv,3sav_sin.setsav_grp+1sav_idx.setsav_grp+2OUTPUT.usectOUTPUT,256BOS.usectstack,0FhTOS.usectstack,1.copytwiddle1.inc.copytwiddle2.inc.text_c_int002/22cossinkjkNNkkWejNN3bstartnopnopstart:STM#TOS,SPLD#0,DPSSBXFRCTSTM#2*N,BKSTM#INPUT,AR3STM#DATA,AR7MVMMAR7,AR2STM#N-1,BRCRPTBDplend-1STM#N,AR0LDMAR3,AREADA*AR2+ADD#1,AREADA*AR2+MAR*AR3+0Bplend:STM#0,BKLD#-1,ASMMVMMAR7,AR2STM#DATA+2,AR3STM#N/2-1,BRCLD*AR2,16,ARPTBDs1end-1STM#3,AR0SUB*AR3,16,A,BADD*AR3,16,ASTHA,ASM,*AR2+STB,*AR3+||LD*AR2,ASUB*AR3,16,A,BADD*AR3,16,ASTHA,ASM,*AR2+0STB,*AR3+0%||LD*AR2,As1end:MVMMAR7,AR2STM#DATA+4,AR3STM#N/4-1,BRCLD*AR2,16,ARPTBDs2end-1STM#5,AR0SUB*AR3,16,A,BADD*AR3,16,ASTHA,ASM,*AR2+STB,*AR3+||LD*AR2,ASUB*AR3,16,A,BADD*AR3,16,ASTHA,ASM,*AR2+STHB,ASM,*AR3+MAR*AR3+ADD*AR2,*AR3,ASUB*AR2,*AR3-,BSTHA,ASM,*AR2+4SUB*AR2,*AR3,ASTB,*AR3||LD*AR3+,BSTA,*AR2||ADD*AR2+0%,ASTA,*AR3+0%||LD*AR2,As2end:STM#512,BKST#128,@sav_sinSTM#128,AR0STM#TWI2,AR4STM#TWI1,AR5STM#-3+LOGN,AR7ST#-1+N/8,@sav_grpSTM#3,AR6ST#8,@sav_idxstage:STM#DATA,AR2LD@sav_idx,AADD*(AR2),ASTLMA,AR3MVDK@sav_grp,AR1group:MVMDAR6,BRCRPTBDbend-1LD*AR4,TMPY*AR3+,AMACR*AR5+0%,*AR3-,AADD*AR2,16,A,BSTB,*AR2||SUB*AR2+,BSTB,*AR3||MPY*AR3+,AMASR*AR3,*AR4+0%,AADD*AR2,16,A,BSTB,*AR3+||SUB*AR2,BLD*AR4,TSTB,*AR2+||MPY*AR3+,Abend:PSHMAR0MVDKsav_idx,AR0MAR*AR2+0MAR*AR3+0BANZDgroup,*AR1-POPMAR0MAR*AR3-LDsav_idx,ASUB#1,A,BSTLMB,AR6STLA,1,sav_idxLDsav_grp,ASTLA,ASM,sav_grpLDsav_sin,ASTLA,ASM,sav_sinBANZDstage,*AR7-5MVDKsav_sin,AR0STM#DATA+2,AR2STM#DATA+2*N-2,AR3STM#DATA+2*N+3,AR7STM#DATA+4*N-1,AR6STM#-2+N/2,BRCRPTBDp3end-1STM#3,AR0ADD*AR2,*AR3,ASUB*AR2,*AR3,BSTHA,ASM,*AR2+STHA,ASM,*AR3+STHB,ASM,*AR6-NEGBSTHB,ASM,*AR7-ADD*AR2,*AR3,ASUB*AR2,*AR3,BSTHA,ASM,*AR2+STHA,ASM,*AR3-0STHB,ASM,*AR6-NEGBSTHB,ASM,*AR7+0p3end:ST#0,*AR6-ST#0,*AR6p3test:STM#DATA,AR2STM#DATA+1,AR4STM#DATA+2*N+1,AR5ADD*AR2,*AR4,ASUB*AR2,*AR4,BSTHA,ASM,*AR2+ST#0,*AR2MVDD*AR2+,*AR5-STHB,ASM,*AR5STM#DATA+4*N-1,AR3STM#TWI2+512/N,AR4STM#TWI1+512/N,AR5STM#N-2,BRCRPTBDp4end-1STM#512/N,AR0LD*AR2+,16,AMACR*AR4,*AR2,AMASR*AR5,*AR3-,ALD*AR3+,16,BMASR*AR5+0%,*AR2-,BMASR*AR4+0%,*AR3,BSTHA,ASM,*AR2+STHB,ASM,*AR2+NEGBSTHB,ASM,*AR3-STHA,ASM,*AR3-p4end:power:STM#OUTPUT,AR3;AR3指向输出缓冲地址STM#255,BRC;块循环计数器设置为255RPTBDpower_end-1;带延迟方式的重复执行指令STM#DATA,AR2;AR2指向AR[0]SQUR*AR2+,A;A:=AR26SQURA*AR2+,A;A:=AR2+AI2STHA,7,*AR3;将A中的数据存入输出缓冲中,ANDM#7FFFH,*AR3+;避免输出数据过大在虚拟示波器中显示错误power_end:Bpower_end.end命令链接文件:/*fft.cmd*/fft.obj-mfft.map-offt.outMEMORY{PAGE0:ROM(RIX):origin=8000h,length=1000hROM1:origin=9000h,length=0200hPAGE1:B2A(RW):origin=0060h,length=10hB2B(RW):origin=0070h,length=10hINTRAM1(RW):origin=0400h,length=0200hINTRAM2(RW):origin=0800h,length=0200hINTRAM3(RW):origin=1400h,length=0800hOTHER:origin=2000h,length=800h}SECTIONS{.text:{}ROMPAGE0INPUT:{}ROM1PAGE0.data:{}INTRAM3PAGE1twiddle1:{}INTRAM1PAGE1twiddle2:{}INTRAM2PAGE1tempv:{}B2APAGE1stack:{}B2BPAGE1OUTPUT:{}OTHERPAGE1.stack:{}OTHERPAGE1}三角因子:TWI1:.secttwiddle1.int0,201,402,603.int804,1005,1206,1407.int1607,1808,2009,2210.int2410,2611,2811,3011.int3211,3411,3611,3811.int4011,4210,4409,4609.int4808,5006,5205,5403.int5602,5800,5997,6195.int6392,6589,6786,6983.int7179,7375,7571,7766.int7961,8156,8351,8545.int8739,8933,9126,9319.int9512,9704,9896,10087.int10278,10469,10659,10849.int11039,11228,11416,11605.int11793,11980,12167,12353.int12539,12725,12910,13094.int13278,13462,13645,13828.int14010,14191,14372,14552.int14732,14912,15090,152697.int15446,15623,15800,15976.int16151,16325,16499,16673.int16846,17018,17189,17360.int17530,17700,17869,18037.int18204,18371,18537,18703.int18868,19032,19195,19358.int19519,19681,19841,20001.int20159,20318,20475,20631.int20787,20942,21097,21250.int21403,21555,21706,21856.int22005,22154,22301,22448.int22594,22740,22884,23027.int23170,23312,23453,23593.int23732,23870,24007,24144.int24279,24414,24547