dimanche 28 juin 2015

How to perform fftw on a split row-major complex 2D matrix

I'm trying to do FFT on a 2D matrix of complex numbers, where the real and the imaginary parts are held in different locations (not interleaved). The data is organized in row-major.

The program crashes (segfault) on fftw_execute_split_dft.

This is the code I use, based on (PDF): http://ift.tt/1GERuIH

bool FFTNDSplit(int NumDims, const int N[], double *XReal, double *XImag, double *YReal, double *YImag, int Sign)
{
  fftw_plan  Plan;
  fftw_iodim Dim[NumDims];
  int k, NumEl;
  for(k = 0, NumEl = 1; k < NumDims; k++)
  {
    Dim[k].n  = N[k];
    Dim[k].is = Dim[k].os =  1;
    NumEl *= N[k];
  }

  if(!(Plan = fftw_plan_guru_split_dft(NumDims, Dim, 0, NULL, XReal, XImag, YReal, YImag, FFTW_ESTIMATE)))
    return false;

  if (Sign == -1) {     // FFT
    fftw_execute_split_dft(Plan, XReal, XImag, YReal, YImag);
  } else {              // IFFT
    fftw_execute_split_dft(Plan, XImag, XReal, YImag, YReal);
    DivideArray(YReal, NumEl, static_cast<double>(NumEl));
    DivideArray(YImag, NumEl, static_cast<double>(NumEl));
  }

  fftw_destroy_plan(Plan);
  return true;
}

I suspect it has something to do with Dim configuration of strides, that's the part of the code I changed from the example, since row-major data is used rather than col-major.

How should a 2D matrix row-major should be configured to use the guru interface?

Aucun commentaire:

Enregistrer un commentaire