CUFFT输出与FFTW输出的对齐方式不同

时间:2011-09-26 16:47:10

标签: c++ cuda fft fftw

我正在进行一维FFT。我有与FFTW相同的输入数据,但是,CUFFT的返回似乎与FFTW不一样“对齐”。也就是说,在我的FFTW代码中,我可以计算零填充的中心,然后做一些转移到“左对齐”我的所有数据,并且尾随零。

在CUFFT中,FFT的结果是看起来相同的数据,但是,零在输出中没有“居中”,因此算法的其余部分会中断。 (在错误移位后,向左移动对齐数据仍然存在“间隙”)。

任何人都可以给我任何见解吗?我认为它与这些兼容性标志有关,但即使使用cufftSetCompatibilityMode(plan,CUFFT_COMPATIBILITY_FFTW_ALL);我的结果仍然不好。

下面是第一行数据量的图表。左边的数据是反CUFFT的输出,右边的输出是反FFTW的输出。

谢谢!enter image description here

以下是FFTW和CUFFT计划的设置代码

ifft = fftwf_plan_dft_1d(freqCols, reinterpret_cast<fftwf_complex*>(indata), 

                  reinterpret_cast<fftwf_complex*>(outdata), 

                  FFTW_BACKWARD, FFTW_ESTIMATE);

CUFFT:

cufftSetCompatibilityMode(plan, CUFFT_COMPATIBILITY_FFTW_ALL);
cufftPlan1d(&plan, width, CUFFT_C2C, height);

并执行代码:

fftwf_execute(ifft);

CUFFT:

cufftExecC2C(plan, d_image, d_image, CUFFT_INVERSE); //in place inverse

完成了一些测试代码:

complex<float> *input = (complex<float>*)fftwf_malloc(sizeof(fftwf_complex) * 100);
    complex<float> *output = (complex<float>*)fftwf_malloc(sizeof(fftwf_complex) * 100);

    fftwf_plan ifft;
    ifft = fftwf_plan_dft_1d(100, reinterpret_cast<fftwf_complex*>(input), 

                          reinterpret_cast<fftwf_complex*>(output), 

                          FFTW_BACKWARD, FFTW_ESTIMATE);


    cufftComplex *inplace = (cufftComplex *)malloc(100*sizeof(cufftComplex));
    cufftComplex *d_inplace;
    cudaMalloc((void **)&d_inplace,100*sizeof(cufftComplex));
    for(int i = 0; i < 100; i++)
    {
        inplace[i] = make_cuComplex(cos(.5*M_PI*i),sin(.5*M_PI*i));
        input[i] = complex<float>(cos(.5*M_PI*i),sin(.5*M_PI*i));
    }

    cutilSafeCall(cudaMemcpy(d_inplace, inplace, 100*sizeof(cufftComplex), cudaMemcpyHostToDevice));
    cufftHandle plan;
    cufftPlan1d(&plan, 100, CUFFT_C2C, 1);
    cufftExecC2C(plan, d_inplace, d_inplace, CUFFT_INVERSE);
    cutilSafeCall(cudaMemcpy(inplace, d_inplace, 100*sizeof(cufftComplex), cudaMemcpyDeviceToHost));


    fftwf_execute(ifft);

当我从这两个FFT调用中转储输出时,它确实看起来一样。我不确定我在看什么。第75行的数据值为100。这是对的吗?

1 个答案:

答案 0 :(得分:2)

看起来您可能已将输入中复杂数据的实部和虚部交换到其中一个IFFT。此交换会将偶数函数更改为时域中的奇数函数。