【发布时间】:2013-11-27 19:11:16
【问题描述】:
我尝试在 C++ 中使用 FFTW3 计算高斯函数的傅立叶变换。这是我的代码的主要部分
main(int argc, char** argv)
{
fftw_plan p;
complex<double> *in,*out;
long N=8;
//allocation of in and the fftw plan called
in=(complex<double>*) calloc(N,sizeof(complex<double>));
p=fftw_plan_dft_1d(N,(fftw_complex*)in,(fftw_complex*)in,FFTW_BACKWARD,FFTW_ESTIMATE);
//initialize the array in with the values of a Gaussian function
gaussianf(in,N);
//Fourier transform in
fftw_execute(p);
//write the result into a file
writeft(in,N);
fftw_destroy_plan(p);
}
由于数组已经用高斯的值初始化,我希望输出也是高斯的,但实际上只有包络具有高斯形状。正如我在下面的数据中所示,可以看到出现了一些负值。
#input values
#x real part imag part
-10 3.72008e-44 0
-7.5 3.72336e-25 0
-5 1.38879e-11 0
-2.5 0.00193045 0
0 1 0
2.5 0.00193045 0
5 1.38879e-11 0
7.5 3.72336e-25 0
#output
#x real part imag part
-10 1.00386 0
-7.5 -1.00273 0
-5 1 0
-2.5 -0.99727 0
0 0.996139 0
2.5 -0.99727 0
5 1 0
7.5 -1.00273 0
谁能告诉我我做错了什么?我将衷心感谢您的帮助。非常感谢。
【问题讨论】:
-
您是否刚刚使用了如图所示的开箱即用命令?我使用的是同一个库,但在转换实数和偶数数据时得到非零虚部。