《基于DSP的快速傅立叶变换FFT的实现汇编语言.doc》由会员分享,可在线阅读,更多相关《基于DSP的快速傅立叶变换FFT的实现汇编语言.doc(11页珍藏版)》请在课桌文档上搜索。
1、-快速傅立叶变换FFT的实现一、实验目的1.了解FFT的原理及算法;2.了解DSP中FFT的设计及编程方法;3.熟悉FFT的调试方法;二、实验原理FFT是一种高效实现离散付立叶变换的算法,把信号从时域变换到频域,在频域分析处理信息。对于长度为N的有限长序列x(n),它的离散傅里叶变换为:,称为旋转因子,或蝶形因子。 在x(n)为复数序列的情况下,计算X(k): 对某个k值,需要N次复数乘法、(N-1)次复数加法;对所有N个k值,需要次复数乘法和N(N-1)次复数加法。对于N相当大时如1024来说,直接计算它的DFT所作的计算量是很大的,FFT的根本思想在于:利用的周期性即: 对称性:将原有的N
2、点序列分成两个较短的序列,这些序列的DFT可以很简单的组合起来得到原序列的DFT。按时间抽取的FFTDITFFT信号流图如图5.1所示:图5.1 时间抽取的FFTDITFFT信号流图FFT算法主要分为以下四步。第一步 输入数据的组合和位倒序把输入序列作位倒序是为了在整个运算最后的输出中得到的序列是自然顺序。第二步 实现N点复数FFT 第一级蝶形运算;第二级蝶形运算;第三级至log2N级蝶形运算;FFT运算中的旋转因子是一个复数,可表示:为了实现旋转因子的运算,在存储空间分别建立正弦表和余弦表,每个表对应从0度到180度,采用循环寻址来对正弦表和余弦表进展寻址。 第三步 功率谱的计算 X(k)是
3、由实部和虚部组成的复数:;计算功率谱时只需将FFT变换好的数据,按照实部和虚部求它们的平方和,然后对平方和进展开平方运算。 第四步 输出FFT结果。三、实验容与步骤. 本实验要求使用FFT变换求一个时域信号的频域特性,并从这个频域特性求出该信号的频率值,然后使用DSP汇编语言对FFT的DSP编程。.将计算机与DES-320PPA教学实验系统连接好,翻开实验箱电源,然后运行CCS软件。2.新建fft.pjt工程文件,并输入FFT的DSP程序及命令文件。如下:*Radix-2,DIT,Real-input FFT Program * fft.asm *.mmregs.global reset,st
4、art,sav_sin,sav_idx,sav_grp .def start,_c_int00 .data DATA.space1024 .copy fft.inc N.set128LOGN.set7 sav_grp.usecttempv,3sav_sin.setsav_grp+1sav_idx.setsav_grp+2OUTPUT.usectOUTPUT,256BOS.usectstack,0FhTOS.usectstack,1 .copy twiddle1.inc .copy twiddle2.inc.text_c_int00b start nopnopstart:STM#TOS,SPLD
5、#0,DPSSBXFRCT STM #2*N,BK STM#INPUT,AR3STM#DATA,AR7MVMMAR7,AR2STM#N-1,BRCRPTBDplend-1STM #N,AR0LDM AR3,A READA *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,ASU
6、B*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+SU
7、B*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,AR2LDsav_idx,AADD*(AR2),ASTLMA,AR3MVDKsav_grp,AR1group: MVMDAR6,BRCRPTBDbend-1LD*AR4,TMPY*AR3+,
8、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_grpLDs
9、av_sin,ASTLA,ASM,sav_sinBANZDstage,*AR7-MVDKsav_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,*A
10、R3-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*A
11、R4,*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;块循环计数器设置为255 RPTBD power_end-1;带延迟方式的重复执行指令 STM #DATA,AR2;AR2指向AR0 SQUR*AR2+,A;A := AR2 SQURA *AR2+,A;A := AR2 +
12、AI2 STH A,7,*AR3;将A中的数据存入输出缓冲中, ANDM#7FFFH,*AR3+;防止输出数据过大在虚拟示波器中显示错误power_end: Bpower_end .end命令文件:/*fft d*/fft.obj-m fft.map-o fft.outMEMORY PAGE 0:ROM(RIX):origin=8000h,length=1000h ROM1 :origin=9000h,length=0200h PAGE 1:B2A(RW):origin=0060h,length=10h B2B(RW):origin=0070h,length=10h INTRAM1(RW) :
13、origin=0400h,length=0200h INTRAM2(RW) :origin=0800h,length=0200h INTRAM3(RW) :origin=1400h,length=0800h OTHER:origin=2000h,length=800hSECTIONS.text:ROMPAGE 0 INPUT : ROM1PAGE 0 .data:INTRAM3PAGE 1twiddle1: INTRAM1PAGE 1twiddle2: INTRAM2PAGE 1 tempv:B2APAGE 1 stack:B2BPAGE 1 OUTPUT:OTHERPAGE 1 .stack
14、:OTHERPAGE 1三角因子:TWI1: .sect twiddle1 .int 0,201,402,603 .int 804,1005,1206,1407 .int 1607,1808,2009,2210 .int 2410,2611,2811,3011 .int 3211,3411,3611,3811 .int 4011,4210,4409,4609 .int 4808,5006,5205,5403 .int 5602,5800,5997,6195 .int 6392,6589,6786,6983 .int 7179,7375,7571,7766 .int 7961,8156,8351
15、,8545 .int 8739,8933,9126,9319 .int 9512,9704,9896,10087 .int 10278,10469,10659,10849 .int 11039,11228,11416,11605 .int 11793,11980,12167,12353 .int 12539,12725,12910,13094 .int 13278,13462,13645,13828 .int 14010,14191,14372,14552 .int 14732,14912,15090,15269 .int 15446,15623,15800,15976 .int 16151,
16、16325,16499,16673 .int 16846,17018,17189,17360 .int 17530,17700,17869,18037 .int 18204,18371,18537,18703 .int 18868,19032,19195,19358 .int 19519,19681,19841,20001 .int 20159,20318,20475,20631 .int 20787,20942,21097,21250 .int 21403,21555,21706,21856 .int 22005,22154,22301,22448 .int 22594,22740,2288
17、4,23027 .int 23170,23312,23453,23593 .int 23732,23870,24007,24144 .int 24279,24414,24547,24680 .int 24812,24943,25073,25201 .int 25330,25457,25583,25708 .int 25832,25955,26077,26199 .int 26319,26438,26557,26674 .int 26790,26905,27020,27133 .int 27245,27356,27466,27576 .int 27684,27791,27897,28002 .i
18、nt 28106,28208,28310,28411 .int 28511,28609,28707,28803 .int 28898,28993,29086,29178 .int 29269,29359,29447,29535 .int 29621,29707,29791,29874 .int 29956,30037,30117,30196 .int 30273,30350,30425,30499 .int 30572,30644,30714,30784 .int 30852,30919,30985,31050 .int 31114,31176,31237,31298 .int 31357,3
19、1414,31471,31526 .int 31581,31634,31685,31736 .int 31785,31834,31881,31927 .int 31971,32015,32057,32098 .int 32138,32176,32214,32250 .int 32285,32319,32351,32383 .int 32413,32442,32469,32496 .int 32521,32545,32568,32589 .int 32610,32629,32647,32663 .int 32679,32693,32706,32718 .int 32728,32737,32745
20、,32752 .int 32758,32762,32765,32767 .int 32767,32767,32765,32762 .int 32758,32752,32745,32737 .int 32728,32718,32706,32693 .int 32679,32663,32647,32629 .int 32610,32589,32568,32545 .int 32521,32496,32469,32442 .int 32413,32383,32351,32319 .int 32285,32250,32214,32176 .int 32138,32098,32057,32015 .in
21、t 31971,31927,31881,31834 .int 31785,31736,31685,31634 .int 31581,31526,31471,31414 .int 31357,31298,31237,31176 .int 31114,31050,30985,30919 .int 30852,30784,30714,30644 .int 30572,30499,30425,30350 .int 30273,30196,30117,30037 .int 29956,29874,29791,29707 .int 29621,29535,29447,29359 .int 29269,29
22、178,29086,28993 .int 28898,28803,28707,28609 .int 28511,28411,28310,28208 .int 28106,28002,27897,27791 .int 27684,27576,27466,27356 .int 27245,27133,27020,26905 .int 26790,26674,26557,26438 .int 26319,26199,26077,25955 .int 25832,25708,25583,25457 .int 25330,25201,25073,24943 .int 24812,24680,24547,
23、24414 .int 24279,24144,24007,23870 .int 23732,23593,23453,23312 .int 23170,23027,22884,22740 .int 22594,22448,22301,22154 .int 22005,21856,21706,21555 .int 21403,21250,21097,20942 .int 20787,20631,20475,20318 .int 20159,20001,19841,19681 .int 19519,19358,19195,19032 .int 18868,18703,18537,18371 .int
24、 18204,18037,17869,17700 .int 17530,17360,17189,17018 .int 16846,16673,16499,16325 .int 16151,15976,15800,15623 .int 15446,15269,15090,14912 .int 14732,14552,14372,14191 .int 14010,13828,13645,13462 .int 13278,13094,12910,12725 .int 12539,12353,12167,11980 .int 11793,11605,11416,11228 .int 11039,108
25、49,10659,10469 .int 10278,10087,9896,9704 .int 9512,9319,9126,8933 .int 8739,8545,8351,8156 .int 7961,7766,7571,7375 .int 7179,6983,6786,6589 .int 6392,6195,5997,5800 .int 5602,5403,5205,5006 .int 4808,4609,4409,4210 .int 4011,3811,3611,3411 .int 3211,3011,2811,2611 .int 2410,2210,2009,1808 .int 160
26、7,1407,1206,1005 .int 804,603,402,201TWI2: .sect twiddle2 .int 32767,32767,32765,32762 .int 32758,32752,32745,32737 .int 32728,32718,32706,32693 .int 32679,32663,32647,32629 .int 32610,32589,32568,32545 .int 32521,32496,32469,32442 .int 32413,32383,32351,32319 .int 32285,32250,32214,32176 .int 32138
27、,32098,32057,32015 .int 31971,31927,31881,31834 .int 31785,31736,31685,31634 .int 31581,31526,31471,31414 .int 31357,31298,31237,31176 .int 31114,31050,30985,30919 .int 30852,30784,30714,30644 .int 30572,30499,30425,30350 .int 30273,30196,30117,30037 .int 29956,29874,29791,29707 .int 29621,29535,294
28、47,29359 .int 29269,29178,29086,28993 .int 28898,28803,28707,28609 .int 28511,28411,28310,28208 .int 28106,28002,27897,27791 .int 27684,27576,27466,27356 .int 27245,27133,27020,26905 .int 26790,26674,26557,26438 .int 26319,26199,26077,25955 .int 25832,25708,25583,25457 .int 25330,25201,25073,24943 .
29、int 24812,24680,24547,24414 .int 24279,24144,24007,23870 .int 23732,23593,23453,23312 .int 23170,23027,22884,22740 .int 22594,22448,22301,22154 .int 22005,21856,21706,21555 .int 21403,21250,21097,20942 .int 20787,20631,20475,20318 .int 20159,20001,19841,19681 .int 19519,19358,19195,19032 .int 18868,
30、18703,18537,18371 .int 18204,18037,17869,17700 .int 17530,17360,17189,17018 .int 16846,16673,16499,16325 .int 16151,15976,15800,15623 .int 15446,15269,15090,14912 .int 14732,14552,14372,14191 .int 14010,13828,13645,13462 .int 13278,13094,12910,12725 .int 12539,12353,12167,11980 .int 11793,11605,1141
31、6,11228 .int 11039,10849,10659,10469 .int 10278,10087,9896,9704 .int 9512,9319,9126,8933 .int 8739,8545,8351,8156 .int 7961,7766,7571,7375 .int 7179,6983,6786,6589 .int 6392,6195,5997,5800 .int 5602,5403,5205,5006 .int 4808,4609,4409,4210 .int 4011,3811,3611,3411 .int 3211,3011,2811,2611 .int 2410,2
32、210,2009,1808 .int 1607,1407,1206,1005 .int 804,603,402,201 .int 0,201,-402,-603 .int -804,-1005,-1206,-1407 .int -1607,-1808,-2009,-2210 .int -2410,-2611,-2811,-3011 .int -3211,-3411,-3611,-3811 .int -4011,-4210,-4409,-4609 .int -4808,-5006,-5205,-5403 .int -5602,-5800,-5997,-6195 .int -6392,-6589,
33、-6786,-6983 .int -7179,-7375,-7571,-7766 .int -7961,-8156,-8351,-8545 .int -8739,-8933,-9126,-9319 .int -9512,-9704,-9896,-10087 .int -10278,-10469,-10659,-10849 .int -11039,-11228,-11416,-11605 .int -11793,-11980,-12167,-12353 .int -12539,-12725,-12910,-13094 .int -13278,-13462,-13645,-13828 .int -
34、14010,-14191,-14372,-14552 .int -14732,-14912,-15090,-15269 .int -15446,-15623,-15800,-15976 .int -16151,-16325,-16499,-16673 .int -16846,-17018,-17189,-17360 .int -17530,-17700,-17869,-18037 .int -18204,-18371,-18537,-18703 .int -18868,-19032,-19195,-19358 .int -19519,-19681,-19841,-20001 .int -201
35、59,-20318,-20475,-20631 .int -20787,-20942,-21097,-21250 .int -21403,-21555,-21706,-21856 .int -22005,-22154,-22301,-22448 .int -22594,-22740,-22884,-23027 .int -23170,-23312,-23453,-23593 .int -23732,-23870,-24007,-24144 .int -24279,-24414,-24547,-24680 .int -24812,-24943,-25073,-25201 .int -25330,-25457,-25583,-25708 .int -25832,-25955,-26077,-26199 .int -26319,-26438,-26557,-26674 .int -26790,-26905,-27020,-27133 .int -27245,-27356,-27466,-27576 .int -27684,-27791,-27897,-28002 .int -28106,-28208,-28310,-28411