快速傅立叶变换对信号频谱的分析-C语言

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#include<graphics.h>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<conio.h>#include<math.h>constintmaxsize=1600;constdoublepi=3.1416;constintN=32;voidss(doublexr[],doublexi[],intn){inti=0,j,s1;floata,bj;for(j=1;j<n;j++){for(s1=n/2;s1<=i;s1=s1/2){i=i-s1;}i=i+s1;if(i>j){a=xr[i];bj=xi[i];xi[i]=xi[j];xr[i]=xr[j];xr[j]=a;xi[j]=bj;}}}voidfft(doublexr[],doublexi[],intm,intn){intloop1,loop2,loop3,le,le1,ip,i=1;floatwr,wi,tr,ti,ur,ur1,ui,ls;ls=log(n)/log(2);ss(xr,xi,n);for(loop1=1;loop1<=ls;loop1++){ur=1.0;ui=0.0;le=pow(2,loop1);le1=le/2;wr=cos(pi*m/le1);wi=-sin(pi*m/le1);for(loop2=0;loop2<le1;loop2++){for(loop3=loop2;loop3<n;loop3=loop3+le){ip=loop3+le1;tr=ur*xr[ip]-ui*xi[ip];ti=ur*xi[ip]+ui*xr[ip];xr[ip]=xr[loop3]-tr;xi[ip]=xi[loop3]-ti;xr[loop3]=tr+xr[loop3];xi[loop3]=ti+xi[loop3];}ur1=wr*ur-ui*wi;ui=wr*ui+ur*wi;ur=ur1;}}if(m==-1){for(i=0;i<n;i++){xr[i]=xr[i]/n;xi[i]=xi[i]/n;}}}voidhua(doublex[]){intd=DETECT,m=VGAHI;initgraph(&d,&m,"");inti,j;for(i=0;i<maxsize;i++)line(50+i,200-100*x[i],i+51,200-100*x[i+1]);}voidhua2(doublex[]){intd=DETECT,m=VGAHI;initgraph(&d,&m,"");inti,j;for(i=0;i<maxsize;i++)line(i+40,200-10*x[i],i+41,200-10*x[i+1]);}voidgaoshi(){inti,j;floatp,q;doublexx[maxsize];doublexe[maxsize];doublex1[maxsize];for(i=0;i<maxsize;i++)xx[i]=0;printf("ÊäÈëP\n");scanf("%f",&p);printf("ÊäÈëq\n");scanf("%f",&q);for(i=0;i<maxsize;i++){if(i<N)x1[i]=exp(-(i-p)*(i-p)/q);elsex1[i]=0;}fft(x1,xx,1,256);for(i=0;i<maxsize;i++)xe[i]=sqrt(x1[i]*x1[i]+xx[i]*xx[i]);hua2(xe);getchar();}sin(){inti,j;floatf;doublexx[maxsize];doublexe[maxsize];doublex1[maxsize];for(i=0;i<maxsize;i++)xx[i]=0;printf("ÊäÈëf\n");scanf("%f",&f);for(i=0;i<maxsize;i++){if(i<N)x1[i]=sin(2*pi*i*f);elsex1[i]=0;}fft(x1,xx,1,64);for(i=0;i<maxsize;i++)xe[i]=sqrt(x1[i]*x1[i]+xx[i]*xx[i]);hua2(xe);getchar();}sinart(){inti,j;floatf;doublexx[maxsize];doublexe[maxsize];doublex1[maxsize];for(i=0;i<maxsize;i++)xx[i]=0;printf("ÊäÈëf\n");scanf("%f",&f);for(i=0;i<maxsize;i++){if(i<N)x1[i]=exp(-0.1*i)*sin(2*pi*i*f);elsex1[i]=0;}fft(x1,xx,1,512);for(i=0;i<maxsize;i++)xe[i]=sqrt(x1[i]*x1[i]+xx[i]*xx[i]);hua2(xe);getchar();}angle(){inti,j;floatf;doublexx[maxsize];doublexe[maxsize];doublex1[maxsize];for(i=0;i<maxsize;i++)xx[i]=0;for(i=0;i<maxsize;i++){if(i<=3)x1[i]=i+1;if(i>=4&&i<=7)x1[i]=8-i;elsex1[i]=0;}fft(x1,xx,1,512);for(i=0;i<maxsize;i++)xe[i]=sqrt(x1[i]*x1[i]+xx[i]*xx[i]);hua2(xe);getchar();}reangle(){inti,j;floatf;doublexx[maxsize];doublexe[maxsize];doublex1[maxsize];for(i=0;i<maxsize;i++)xx[i]=0;for(i=0;i<maxsize;i++){if(i<=3)x1[i]=4-i;if(i>=4&&i<=7)x1[i]=i-3;elsex1[i]=0;}fft(x1,xx,1,512);for(i=0;i<maxsize;i++)xe[i]=sqrt(x1[i]*x1[i]+xx[i]*xx[i]);hua2(xe);getchar();}voidmain(){/*gaoshi()*/;sin();/*sinart();*//*angle();*//*reangle();*/getchar();}

1 / 6
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功