?? d12r2.cpp
字號:
#include <iostream.h>
#include <math.h>
#include <iomanip.h>
#include <stdlib.h>
#include <fstream.h>
#include <string>
#include <process.h>
#include<stdio.h>
int cint(double x)
{
int temp;
double iprt;
if (x>0)
{
x=modf(x,&iprt);
if(fabs(x)<0.5)
temp=int(iprt);
else
temp=int(iprt+1);
}
else if(x==0)
temp=0;
else
{
x=modf(x,&iprt);
if(fabs(x)<0.5)
temp=int(iprt);
else
temp=int(iprt)-1;
}
return temp;
}
void prntft(double data[], double nn2)
{
int n,m,mm;
cout<<"n real(n) imag.(n) real(N-n) imag.(N-n)"<<endl;
cout<<setw(1)<<"0";
cout<<setw(14)<<data[1];
cout<<setw(14)<<data[2];
cout<<setw(14)<<data[1];
cout<<setw(14)<<data[2]<<endl;
for (n = 3; n<=(nn2 / 2) + 1; n=n+2)
{
m = (n - 1) / 2;
mm = nn2 + 2 - n;
cout<<setiosflags(ios::fixed);
cout<<setprecision(0)<<setw(1)<<m;
cout<<setprecision(6)<<setw(14)<<data[n];
cout<<setprecision(6)<<setw(14)<<data[n+1];
cout<<setprecision(6)<<setw(14)<<data[mm];
cout<<setprecision(6)<<setw(14)<<data[mm+1]<<endl;
}
}
void main()
{
//program d12r2
//driver for routine twofft
int n,i,n2,isign;
double data1[33], data2[33], fft1[65], fft2[65],per,x;
n = 32;
n2 = 2 * n;
per = 8.0;
const double pi = 3.1415926;
for( i = 1; i<=n; i++)
{
x = 2.0 * pi * i / per;
data1[i] = cint(cos(x));
data2[i] = cint(sin(x));
}
twofft(data1, data2, fft1, fft2, n);
cout<<setw(1)<<"Fourier transform of first function:"<<endl;
prntft(fft1, n2);
cout<<setw(1)<<"Fourier transform of second function:"<<endl;
prntft(fft2, n2);
//invert transform
isign = -1;
four1(fft1, n, isign);
cout<<setw(1)<<"Inverted transform = first function:"<<endl;
prntft(fft1, n2);
four1(fft2, n, isign);
cout<<setw(1)<<"Inverted transform = second function:"<<endl;
prntft(fft2, n2);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -