用FFTW3和C++评估高斯的傅立叶变换

Evaluating Fourier transform of a Gaussian with FFTW3 and C++

本文关键字:傅立叶 变换 高斯 评估 FFTW3 C++      更新时间:2023-10-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

有人能告诉我我做错了什么吗?我真的很感谢你的帮助。非常感谢。

从C编程或FFTW调用的意义上讲,您没有做错任何事情:这些都是正确的值。高斯曲线FFT的实部确实在零附近振荡。如果绘制绝对值,它可能看起来更像您所期望的。

这些振荡是意料之中的。在实践中,需要使用窗口函数来减少这些振荡。http://en.wikipedia.org/wiki/Window_function