dsp方波谐波分析Word文档格式.docx
《dsp方波谐波分析Word文档格式.docx》由会员分享,可在线阅读,更多相关《dsp方波谐波分析Word文档格式.docx(9页珍藏版)》请在冰豆网上搜索。
{
intx0,x1,x2,x3,x4,x5,x6,xx;
inti,j,k,b,p,L;
floatTR,TI,temp;
for(i=0;
i<
SAMPLENUMBER;
i++)
x0=x1=x2=x3=x4=x5=x6=0;
x0=i&
0x01;
x1=(i/2)&
x2=(i/4)&
x3=(i/8)&
x4=(i/16)&
x5=(i/32)&
x6=(i/64)&
xx=x0*64+x1*32+x2*16+x3*8+x4*4+x5*2+x6;
dataI[xx]=dataR[i];
}
dataR[i]=dataI[i];
dataI[i]=0;
for(L=1;
L<
=7;
L++)
b=1;
i=L-1;
while(i>
0)
b=b*2;
i--;
for(j=0;
j<
=b-1;
j++)
p=1;
i=7-L;
0)
p=p*2;
p=p*j;
for(k=j;
k<
128;
k=k+2*b)
TR=dataR[k];
TI=dataI[k];
temp=dataR[k+b];
dataR[k]=dataR[k]+dataR[k+b]*cos_tab[p]+dataI[k+b]*sin_tab[p];
dataI[k]=dataI[k]-dataR[k+b]*sin_tab[p]+dataI[k+b]*cos_tab[p];
dataR[k+b]=TR-dataR[k+b]*cos_tab[p]-dataI[k+b]*sin_tab[p];
dataI[k+b]=TI+temp*sin_tab[p]-dataI[k+b]*cos_tab[p];
SAMPLENUMBER/2;
{
w[i]=sqrt(dataR[i]*dataR[i]+dataI[i]*dataI[i]);
运行后打来Graphics窗口观察信号其及频谱图如下:
图注:
左上为输入信号采样后的波形,可见为方波信号。
右上为根据方波信号由系统自己转换的频谱图。
右下为根据编写的程序计算得出的信号频谱图。
可见计算结果与实际频谱的尖峰分布比较一致。
不同的地方是成份较小的频率部分。
个人认为原因可能有两点:
一是计算频谱图的精度取决于采样点数,采样点越大,谱频越精确;
二是输入信号本身有噪声,因此计算FFT时的对象信号实际上是一个方波信号与高斯噪声信号的叠加,最后的频谱中有白噪声的频谱。
#include"
myapp.h"
ICETEK-VC5509-EDU.h"
scancode.h"
#include<
math.h>
#definePI3.1415926
#defineSAMPLENUMBER256
voidInitForFFT();
//voidMakeWave();
voidFFT();
voidInitADC();
voidwait(unsignedintcycles);
voidEnableAPLL();
unsignedintnADC0[256],nADC1[256];
//intINPUT[SAMPLENUMBER],DATA[SAMPLENUMBER];
floatfWaveR[SAMPLENUMBER],fWaveI[SAMPLENUMBER],w[SAMPLENUMBER];
floatsin_tab[SAMPLENUMBER],cos_tab[SAMPLENUMBER];
main()
inti,j;
unsignedintuWork;
InitForFFT();
EnableAPLL();
SDRAM_init();
InitADC();
PLL_Init(132);
//while
(1)
//{
for(i=0;
256;
{
ADCCTL=0x8000;
//启动AD转换,通道0
do
{
uWork=ADCDATA;
}while(uWork&
0x8000);
nADC0[i]=uWork&
0x0fff;
}
/*for(i=0;
ADCCTL=0x9000;
//启动AD转换,通道1
nADC1[i]=uWork&
asm("
nop"
);
//breakpoint*/
//}
for(j=0;
{
fWaveR[j]=nADC0[j];
fWaveI[j]=0.0f;
w[j]=0.0f;
}
FFT(fWaveR,fWaveI);
DATA[j]=w[j];
while
(1);
//breakpoint
intx0,x1,x2,x3,x4,x5,x6,xx;
inti,j,k,b,p,L;
floatTR,TI,temp;
/**********followingcodeinvertsequence************/
for(i=0;
x0=x1=x2=x3=x4=x5=x6=0;
x0=i&
xx=x0*64+x1*32+x2*16+x3*8+x4*4+x5*2+x6;
dataI[xx]=dataR[i];
dataR[i]=dataI[i];
/**************followingcodeFFT*******************/
for(L=1;
{/*for
(1)*/
b=1;
while(i>
0)
b=b*2;
}/*b=2^(L-1)*/
for(j=0;
j++)/*for
(2)*/
p=1;
while(i>
0)/*p=pow(2,7-L)*j;
*/
p=p*2;
}
p=p*j;
for(k=j;
k=k+2*b)/*for(3)*/
TR=dataR[k];
dataR[k]=dataR[k]+dataR[k+b]*cos_tab[p]+dataI[k+b]*sin_tab[p];
dataI[k]=dataI[k]-dataR[k+b]*sin_tab[p]+dataI[k+b]*cos_tab[p];
dataR[k+b]=TR-dataR[k+b]*cos_tab[p]-dataI[k+b]*sin_tab[p];
dataI[k+b]=TI+temp*sin_tab[p]-dataI[k+b]*cos_tab[p];
}/*ENDfor(3)*/
}/*ENDfor
(2)*/
}/*ENDfor
(1)*/
{
w[i]=sqrt(dataR[i]*dataR[i]+dataI[i]*dataI[i]);
}/*ENDFFT*/
voidInitForFFT()
inti;
sin_tab[i]=sin(PI*2*i/SAMPLENUMBER);
cos_tab[i]=cos(PI*2*i/SAMPLENUMBER);
/*voidMakeWave()
INPUT[i]=sin(PI*2*i/SAMPLENUMBER*3)*1024;
}*/
voidInitADC()
ADCCLKCTL=0x23;
//4MHzADCLK
ADCCLKDIV=0x4f00;
voidwait(unsignedintcycles)
for(i=0;
i<
cycles;
i++){}
voidEnableAPLL()
/*EnusreDPLLisrunning*/
*(ioportvolatileunsignedshort*)0x1f00=4;
wait(25);
*(ioportvolatileunsignedshort*)0x1f00=0;
//MULITPLY
*(ioportvolatileunsignedshort*)0x1f00=0x3000;
//COUNT
*(ioportvolatileunsignedshort*)0x1f00|=0x4F8;
//*(ioportvolatileunsignedshort*)0x1f00|=0x800
//MODE
*(ioportvolatileunsignedshort*)0x1f00|=2;
wait(30000);
//APLLSelect
*(ioportvolatileunsignedshort*)0x1e80=1;
//DELAY
wait(60000);