我尝试用FFTW3在C++中计算高斯函数的傅里叶变换。下面是我代码的主要部分
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
有人能告诉我我做错了什么吗?我非常感谢你的帮助。非常感谢。
发布于 2013-11-27 19:30:24
在C编程或FFTW调用的意义上,您没有做任何错误的事情:这些是正确的值。高斯曲线的FFT的真实部分在零附近振荡。如果你画出绝对值,那可能看起来更像你所期望的那样。
发布于 2014-02-17 12:38:07
这些振荡是预料之中的。实际上,我们需要使用一个窗口函数来减少这些振荡。function
https://stackoverflow.com/questions/20251068
复制相似问题