FFT算法在單片機(jī)中的使用&&LCD12864驅(qū)動(dòng)
void clear(uchar dat) //清屏函數(shù)
{
uchar i,j,k;
uchar addr=0x80;
for(i=0;i<2;i++)
{
for(j=0;j<32;j++)
{
for(k=0;k<8;k++)
{
WriteCommandLCM(0x36);
WriteCommandLCM(0x80+j);
WriteCommandLCM(addr+k);
WriteDataLCM(dat);
WriteDataLCM(dat);
}
}
addr=0x88;
}
WriteCommandLCM(0x36);
WriteCommandLCM(0x30);
}
void heng(uchar a)
{
uchar i;
for(i=0;i<127;i++)
point(i,a);
}
void su(uchar a)
{
uchar i;
for(i=0;i<63;i++)
point(a,i);
}
void FFT()
{
int i,j,k,t,P,B,m;
complex up,down,product;
for (i=0;i<7;i++)
{
B=1<for (j=0;j{
t=1<<(6-i);
P=t*j;
for (k=j;k complex product; product.real=x[k+B].real*cos(2*PI*P/N)+x[k+B].img*sin(2*PI*P/N); product.img=x[k+B].real*(-1)* sin(2*PI*P/N)+x[k+B].img*cos(2*PI*P/N); x[k+B].real=x[k].real-product.real; x[k+B].img=x[k].img-product.img; x[k].real=x[k].real+product.real; x[k].img=x[k].img+product.img; } } } } void initw() //初始化旋轉(zhuǎn)因子 { int i; for (i=0;i } void bitReverse() //比特反轉(zhuǎn) { int i,j=0; int k=0; int q=0; complex tmp3; for (i=0;i int tmp=i,tmp2=0,j; for(j=0;j<7;j++) tmp2+=((tmp>>j)&1)*(1<<(6-j)); if(vis[i]==0) { tmp3=x[i]; x[i]=x[tmp2]; x[tmp2]=tmp3; vis[i]=1; vis[tmp2]=1; } } } void xian(uchar x,uchar y) { uchar i; for(i=63;i>=y;i--) point(x,i); } //主函數(shù) void main(void) { uchar ii,y; float tmp; //端口初始化 DDRA=0xff; PORTA=0xff; DDRB=0xff; PORTB=0xff; DDRD=0xff; PORTD=0x00; delayms(20); delayms(20); LCMInit(); //LCM初始化 //液晶初始化 delayms(100); clear(0x00); heng(0); heng(63); su(0); su(127); for (ii=0;ii<20;ii++) { x[ii].real=3; x[ii].img=0; } for (ii=20;ii<128;ii++) { x[ii].real=0; x[ii].img=0; } initw(); bitReverse(); FFT(); for(ii=64;ii<128;ii++) { tmp=sqrt((x[ii].real*x[ii].real)+(x[ii].img*x[ii].img)); y= 63-(int)tmp; point(ii-64,y); xian(ii-64,y); } for(ii=0;ii<64;ii++) { tmp=sqrt((x[ii].real*x[ii].real)+(x[ii].img*x[ii].img)); y= 63-(int)tmp; point(ii+64,y); xian(ii+64,y); } while(1); }
評(píng)論