用fftw/C++和联机计算器(http://calculator-fx.com/calculator/fast-fourier-transform-calculator-fft/1d-discrete-fourier-transform)计算了阵列{1,2,3,4,5,6}的FFT。结果似乎有点不同。
fftw产出:
21.000000 0.000000 1 -3.000000 5.196152 2 -3.000000 1.732051 3 -3.000000 0.000000 4 0.000000 0.000000 5 0.000000
在线计算器输出:
21 + 0j -3 + 5.196152j -3 + 1.732051j -3 + 0j -3 - 1.732051j -3 - 5.196152j
如上文所示,fftw的后两个结果变为零。不知道为什么。有人能帮我吗?谢谢。
编辑的cpp代码:
int main()
{
fftw_complex *out;
fftw_plan plan;
double arr[]={1,2,3,4,5,6};
int n = sizeof(arr)/sizeof(double);
out = (fftw_complex*)fftw_malloc ( sizeof ( fftw_complex ) * n );
plan = fftw_plan_dft_r2c_1d ( n, arr, out, FFTW_ESTIMATE );
fftw_execute ( plan );
for (int i = 0; i < n; i++ )
{
printf ( " %3d %12lf %12lf\n", i, out[i][0], out[i][1] );
}
fftw_free(out);
fftw_destroy_plan(plan);
return 0;
}发布于 2013-09-11 23:52:51
哦,您正在使用R2C模式(不知道为什么我以前没有想到这一点)。这只写n/2 +1的结果,因为对称性。
这种行为记录在案:002dDimensional-DFTs-of-Real-Data.html。
https://stackoverflow.com/questions/18753064
复制相似问题