对 2D 复数 FFTW 使用 FFTW_EXHAUSTIVE 标志后的错误结果
Wrong results after using FFTW_EXHAUSTIVE flag for 2D complex FFTW
我正在使用 FFTW 计算二维复数到复数 FFT,代码如下:
#include <stdlib.h>
#include "defines.h"
#include <math.h>
#include <fftw3.h>
int main(void)
{
fftw_complex *in,*out;
fftw_plan plan;
int rows=64;
int cols=64;
int i;
in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*rows*cols);
out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*rows*cols);
for (i=0; i<rows*cols; i++)
{
in[i][0] = input_data[2*i];
in[i][1] = input_data[2*i+1];;
}
printf("### Setting plan ###\n");
plan = fftw_plan_dft_2d(rows, cols, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
printf("### Executing plan ###\n");
fftw_execute(plan);
for ( i = 0; i <rows*cols; i++ )
{
printf ( "RE = %f \t IM = %f\n",in[i][0], in[i][1] );
}
fftw_destroy_plan(plan);
fftw_free(in);
fftw_free(out);
return 0;
}
现在,我将 FFTW 标志从 ESTIMATE
更改为 EXHAUSTIVE
以允许规划器为这个 2D FFT 选择最佳算法,但我得到了全零结果。有人能告诉我哪里出了问题吗?
使用标志 FFTW_ESTIMATE
,函数 fftw_plan_dft_2d()
尝试猜测在没有 运行 任何算法的情况下哪个 FFT 算法最快。使用标志 FFTW_EXHAUSTIVE
,该函数运行所有可能的算法,并且 select 运行最快的算法。
问题是输入过程中被覆盖了
解决方案是在创建计划后填充输入数组!
参见documentation of planner flags:
Important: the planner overwrites the input array during planning unless a saved plan (see Wisdom) is available for that problem, so you should initialize your input data after creating the plan. The only exceptions to this are the FFTW_ESTIMATE and FFTW_WISDOM_ONLY flags, as mentioned below.
我正在使用 FFTW 计算二维复数到复数 FFT,代码如下:
#include <stdlib.h>
#include "defines.h"
#include <math.h>
#include <fftw3.h>
int main(void)
{
fftw_complex *in,*out;
fftw_plan plan;
int rows=64;
int cols=64;
int i;
in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*rows*cols);
out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*rows*cols);
for (i=0; i<rows*cols; i++)
{
in[i][0] = input_data[2*i];
in[i][1] = input_data[2*i+1];;
}
printf("### Setting plan ###\n");
plan = fftw_plan_dft_2d(rows, cols, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
printf("### Executing plan ###\n");
fftw_execute(plan);
for ( i = 0; i <rows*cols; i++ )
{
printf ( "RE = %f \t IM = %f\n",in[i][0], in[i][1] );
}
fftw_destroy_plan(plan);
fftw_free(in);
fftw_free(out);
return 0;
}
现在,我将 FFTW 标志从 ESTIMATE
更改为 EXHAUSTIVE
以允许规划器为这个 2D FFT 选择最佳算法,但我得到了全零结果。有人能告诉我哪里出了问题吗?
使用标志 FFTW_ESTIMATE
,函数 fftw_plan_dft_2d()
尝试猜测在没有 运行 任何算法的情况下哪个 FFT 算法最快。使用标志 FFTW_EXHAUSTIVE
,该函数运行所有可能的算法,并且 select 运行最快的算法。
问题是输入过程中被覆盖了
解决方案是在创建计划后填充输入数组!
参见documentation of planner flags:
Important: the planner overwrites the input array during planning unless a saved plan (see Wisdom) is available for that problem, so you should initialize your input data after creating the plan. The only exceptions to this are the FFTW_ESTIMATE and FFTW_WISDOM_ONLY flags, as mentioned below.