3

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

在 CUFFT 中,FFT 的结果是看起来相同的数据,但是,输出中的零点不是“居中”的,所以我的算法的其余部分会中断。(在错误的移位之后,数据左对齐的移位仍然有一个“间隙”)。

谁能给我任何见解?我认为这与那些兼容性标志有关,但即使与 cufftSetCompatibilityMode(plan, CUFFT_COMPATIBILITY_FFTW_ALL); 我仍然得到一个不好的结果。

下面是第一行数据的大小图。左边的数据是逆CUFFT的输出,右边的输出是逆FFTW的输出。

谢谢!在此处输入图像描述

这是 FFTW 和 CUFFT 计划的设置代码

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

                  reinterpret_cast<fftwf_complex*>(outdata), 

                  FFTW_BACKWARD, FFTW_ESTIMATE);

袖口:

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

并执行代码:

fftwf_execute(ifft);

袖口:

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。那是对的吗?

4

1 回答 1

2

看起来您可能已将输入中复杂数据的实部和虚部交换到 IFFT 之一。这种交换将时域中的偶函数变为奇函数。

于 2011-09-26T20:31:17.537 回答