2D R2C FFT使用FFTW作为1D FFT

时间:2015-02-03 09:34:04

标签: c signal-processing fft fftw

由于各种原因,我需要对实数据输入进行二维FFT变换(正向和反向)作为一维变换。我使用优秀的FFTW库。

算法应该很简单,首先我对每一行进行1D R2C变换,然后对每个结果列进行1D R2C变换。为此,我使用FFTW的高级接口:

int N = ...; int M = ...; int M2 = M / 2 + 1;
r_array = ... // fftw_malloc'd as NxM array of doubles
c_array = ... // fftw_malloc'd as NxM2 array of fftw_complex

int rank = 1;
int nfr[] = {M}; int nfr2[] = {M2};    
int howmany = N;
int idist = M; int odist = M2;
int istride = 1; int ostride = 1;
int *inembed = nfr, *onembed = nfr2;

plan_forward_row = fftw_plan_many_dft_r2c(rank, nfr, howmany, r_array, inembed, istride, idist,  c_array, onembed, ostride, odist, FFTW_ESTIMATE);
fftw_execute(plan_forward_row);

//do something else...

int nfc[] = {N};
howmany = M2;
idist = 1; odist = 1;
istride = N, ostride = N;
inembed = nfc, onembed = nfc;

plan_forward_col = fftw_plan_many_dft(rank, nfc, howmany, c_array, inembed, istride, idist,  c_array, onembed, ostride, odist, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(plan_forward_col);

//do something else...

//now inverse (backward)...
int nbc[] = {N};
howmany = M2;
idist = 1; odist = 1;
istride = N; ostride = N;
inembed = nbc; onembed = nbc;

plan_backward_col = fftw_plan_many_dft(rank, nbc, howmany, c_array, inembed, istride, idist,  c_array, onembed, ostride, odist, FFTW_BACKWARD, FFTW_ESTIMATE);
fftw_execute(plan_backward_col);

//do something else...

int nbr[] = {M2}; int nbr2[] = {M};    
howmany = Nx;
idist = M2; odist = M;
istride = 1, ostride = 1;
inembed = nbr, onembed = nbr2;

plan_backward_row = fftw_plan_many_dft_c2r(rank, nbr, howmany, c_array, inembed, istride, idist,  r_array, onembed, ostride, odist, FFTW_ESTIMATE);
fftw_execute(plan_backward_row);

但是,结果不正确。问题在于R2C输出只是复数的非冗余数组,还是在使用高级接口时出错?

2 个答案:

答案 0 :(得分:0)

基本FFT算法复杂 - >复杂。使用此部分,您可以按两个1d FFT的顺序划分2d FFT。

通常的FFT接口进行了大量优化:

  1. 将实际输入打包成复杂数组
  2. 执行复杂的>复数FFT
  3. 删除多余的部分
  4. 您需要为行调用第(2)部分,然后是列。

答案 1 :(得分:0)

为什么不直接调用FFTW的2D版本?

请参阅

中的函数fftw_plan_dft_r2c_2d()

http://www.fftw.org/fftw3_doc/Multi_002dDimensional-DFTs-of-Real-Data.html#Multi_002dDimensional-DFTs-of-Real-Data