【问题标题】:Differences between FFTW and CUFFT outputFFTW 和 CUFFT 输出的区别
【发布时间】:2011-07-12 01:22:22
【问题描述】:

在我在下面发布的字符中,我正在比较 FFTW 和 CUFFT 中运行的 IFFT 的结果。

出现这种不同的可能原因是什么?舍入误差真的这么大吗?

这里是相关代码sn-p:

cufftHandle plan;
cufftComplex *d_data;
cufftComplex *h_data;
cudaMalloc((void**)&d_data, sizeof(cufftComplex)*W);

complex<float> *temp = (complex<float>*)fftwf_malloc(sizeof(fftwf_complex) * W);
h_data = (cufftComplex *)malloc(sizeof(cufftComplex)*W);
memset(h_data, 0, W*sizeof(cufftComplex));

/* Create a 1D FFT plan. */
cufftPlan1d(&plan, W, CUFFT_C2C, 1);

if (!reader->getData(rowBuff, row))    
    return 0;

// copy from read buffer to our FFT input buffer    
memcpy(indata, rowBuff, fCols * sizeof(complex<float>));

for(int c = 0; c < W; c++)
    h_data[c] = make_cuComplex(indata[c].real(), indata[c].imag());

cutilSafeCall(cudaMemcpy(d_data, h_data, W* sizeof(cufftComplex), cudaMemcpyHostToDevice));
cufftExecC2C(plan, d_data, d_data, CUFFT_INVERSE);
cutilSafeCall(cudaMemcpy(h_data, d_data,W * sizeof(cufftComplex), cudaMemcpyDeviceToHost));

for(int c = 0; c < W; c++)
    temp[c] =(cuCrealf(h_data[c]), cuCimagf(h_data[c]));

//execute ifft plan on "indata"
fftwf_execute(ifft);
 ...
 //dump out abs() values of the first 50 temp and outdata values. Had to convert h_data back to a normal complex

ifft 是这样定义的:

ifft = fftwf_plan_dft_1d(freqCols, reinterpret_cast<fftwf_complex*>(indata),
                         reinterpret_cast<fftwf_complex*>(outdata), 
                         FFTW_BACKWARD, FFTW_ESTIMATE);

为了生成图表,我在 fftw_execute 之后转储了 h_data 和 outdata W 是我正在处理的图像行的宽度。

看到什么明显的东西了吗?

【问题讨论】:

  • 你在密谋什么?实物零件?模数?
  • 复数的大小
  • @Derek:你如何计算它们?你试过|a + bi| = |一个| * (1 + (b/a)^2) 如果 a > b, |b| * (1 + (a / b)^2) 其他?
  • 我刚刚使用了std::complex库的abs()函数
  • 在创建一个简单的案例之后,只生成一个数字 1-50 的数组并在它们上运行前向和后向 FFT,我看到 CUFFT 库的比例因子为 1/sqrt(2 )。知道这是从哪里来的吗?

标签: c++ cuda fftw


【解决方案1】:

所以看起来 CUFFT 正在返回一个实部和虚部,而 FFTW 只返回实部。当我拥有复数的两个部分时,CUFFT 复数库附带的 cuCabsf() 函数会导致它给我一个 sqrt(2) 的倍数

顺便说一句 - 我从来没有能够在 FFTW 和 CUFFT 之间的中间步骤中获得完全匹配的结果。如果你同时进行 IFFT 和 FFT,你应该得到一些接近的结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多