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

时间:2013-11-27 19:11:16

标签: c++ fftw

我试图通过在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

有谁能告诉我我做错了什么?我将衷心感谢您的帮助。非常感谢。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

预计这些振荡。在实践中,需要使用窗函数来减少这些振荡。 http://en.wikipedia.org/wiki/Window_function

相关问题