问题描述
- 麻烦各位帮我改下程序吧,输入#include "stdafx.h"在VC++上面不能运行呀~~
- #include ""stdafx.h""
#include#include
#include
#include
#include
#define N 1000/*定义复数类型*/
typedef struct
{
double real;
double img;
}complex;
void fft(); /*快速傅里叶变换*/
void ifft();
void initW(); /*初始化变换核*/
void change(); /*变址*/
void add(complex complex complex ); /复数加法*/
void mul(complex complex complex ); /复数乘法*/
void sub(complex complex complex ); /复数减法*/
void divi(complex complex complex );/复数除法*/
void output();
/*输出结果*/complex x[N] W; /变换核*/
int size_x=0; /*输入序列的大小,在本程序中仅限2的次幂*/
double PI=atan(1)*4; /*定义圆周率*/
int main()
{
int i X Yflt=0;
int gd=DETECTgm;
system(""cls"");printf(""输入正弦频率X:n"");
scanf(""%d""&X);
printf(""输入采样频率Y(理想情况下应是2的整数次幂):n"");
scanf(""%d""&Y);
if(int(Y)==2||int(Y)==4||int(Y)==8||int(Y)==16||int(Y)==32||int(Y)==64||int(Y)==128||int(Y)==256||int(Y)==512||int(Y)==1024)
flt=1;
if(flt==0)
{ printf(""注意!输入的Y不是2的整数次幂!n"");}
printf(""输入采样点数size_x:n"");
scanf(""%d""&size_x);for(i=0;i<size_x;i++)
{
x[i].real=sin(2*PI*X*i/Y);
x[i].img=0;
}
initW();fft();
output();
for(i=0;i<size_x;i++)
{ //求变换后结果的模值,存入复数的实部部分
x[i].real=sqrt(x[i].real*x[i].real+x[i].img*x[i].img);
}
//registerbgidriver(EGAVGA_driver);
initgraph(&gd&gm");
cleardevice();
setcolor(WHITE);
line(40040040050);
line(4005039555);
line(4005040555);
line(200400600400);
line(600400595395);
line(600400595405);
setcolor(WHITE);
for(i=0;i<size_x;i++)
line(i*10+400-size_x*10/2400i*10+400-size_x*10/2400-(int)x[i].real*10);
getch();
closegraph();
return 0;}
/*快速傅里叶变换*/
void fft()
{
int i=0j=0k=0l=0;
complex updownproduct;
change();
for(i=0;i< log(size_x)/log(2) ;i++)/*一级蝶形运算*/
{
l=1<<i;
for(j=0;j<size_x;j+= 2*l )/*一组蝶形运算*/
{
for(k=0;k<l;k++)/*一个蝶形运算*/
{
mul(x[j+k+l]W[size_x*k/2/l]&product);
add(x[j+k]product&up);
sub(x[j+k]product&down);
x[j+k]=up;
x[j+k+l]=down;
}
}
}
}
/*初始化变换核*/
void initW()
{
int i;
W=(complex *)malloc(sizeof(complex) * size_x);
for(i=0;i<size_x;i++)
{
W[i].real=cos(2*PI/size_x*i);
W[i].img=-1*sin(2*PI/size_x*i);
}
}
/*变址计算,将x(n)码位倒置*/
void change()
{
complex temp;
unsigned short i=0j=0k=0;
double t;
for(i=0;i {
k=i;j=0;
t=(log(size_x)/log(2));
while( (t--)>0 ){
j=j< j|=(k & 1);
k=k>>1;}
if(j>i)
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
}
/*输出傅里叶变换的结果*/
void output()
{
int i;
printf(""The result are as followsn"");
for(i=0;i {
printf(""%.4f""x[i].real);
if(x[i].img>=0.0001)printf(""+%.4fjn""x[i].img);
else if(fabs(x[i].img) printf(""n"");
else
printf(""%.4fjn""x[i].img);
}
}
void add(complex acomplex bcomplex *c)
{
c->real=a.real+b.real;c->img=a.img+b.img;
}
void mul(complex acomplex bcomplex *c)
{
c->real=a.real*b.real - a.img*b.img;
c->img=a.real*b.img + a.img*b.real;
}
void sub(complex acomplex bcomplex *c)
{
c->real=a.real-b.real;
c->img=a.img-b.img;
}
void divi(complex acomplex bcomplex *c)
{
c->real=( a.real*b.real+a.img*b.img )/( b.real*b.real+b.img*b.img);
c->img=( a.img*b.real-a.real*b.img)/(b.real*b.real+b.img*b.img);
}
解决方案
新建一个控制台程序,然后把这些代码粘贴进去,编译。
贴出报的错误来
解决方案二:
不能运行,具体是什么情况呢?编译无法通过,还是运行没在得到想要的结果?
是否要包含预编译头文件:#include ""stdafx.h"",是由工程的属性决定的。
解决方案三:
你选择的是win32的工程?目测你的代码用控制台的共成功就可以了
解决方案四:
新建空白的程序能编译么?如果还不能,就考虑重装VC++吧。
解决方案五:
在这里下载原版的看看
http://download.csdn.net/album/detail/639
解决方案六:
再不行,去msdn.itellyou.cn下载原版的Windows操作系统,重新安装