gpt4 book ai didi

c++ - CUFFT 输出与 FFTW 输出不对齐

转载 作者:太空狗 更新时间:2023-10-29 21:49:53 28 4
gpt4 key购买 nike

我正在进行一维 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);

袖口:

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

最佳答案

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

关于c++ - CUFFT 输出与 FFTW 输出不对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7558384/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com