fftw

How to use the fftw guru interface to compute real output inverse fourier transforms


I have a 3 x 3 matrix x =

[-1.2190 + 0.0000i 1.0162 - 0.6787i 1.0162 + 0.6787i;

-3.3477 + 1.3537i -1.1505 + 3.4269i -2.8059 - 0.5052i;

-3.3477 - 1.3537i -2.8059 + 0.5052i -1.1505 -3.4269i].

I want to use fftw_plan_guru_dft_c2r function to create plan for doing a symmetric 2d inverse fft of this matrix. I followed the steps discussed in the fftw manual and came up with below code:

#include "fftw3.h"
typedef struct {
    double re;
    double im;
} Complex;
int main() {
    Complex x[9];
    double y[9];
    x[0].re = -1.2190;
    x[0].im = 0.0;

    x[1].re = 1.0162;
    x[1].im = -0.6787;

    x[2].re = 1.0162;
    x[2].im = 0.6787;

    x[3].re = -3.3477;
    x[3].im = 1.3537;

    x[4].re = -1.1505;
    x[4].im = 3.4269;


    x[5].re = -2.8059;
    x[5].im = -0.5052;

    x[6].re = -3.3477;
    x[6].im = -1.3537;

    x[7].re = -2.8059;
    x[7].im = 0.5052;

    x[8].re = -1.1505;
    x[8].im = -3.4269;
    
    int rank = 2;
    fftw_iodim dim[2];

    dim[0].n = 3;
    dim[0].is = 1;
    dim[0].os = 1;
    
    dim[1].n = 3;
    dim[1].is = 3;
    dim[1].os = 3;

    int howmany_rank = 0;
    fftw_iodim* howmany_dim = NULL;

    unsigned int spec_fFlags = (unsigned int)FFTW_PRESERVE_INPUT | (unsigned int)FFTW_ESTIMATE;

    //int sign = FFTW_BACKWARD;
    fftw_plan plan;
    plan = fftw_plan_guru_dft_c2r(rank, &dim[0], howmany_rank, howmany_dim,
        (fftw_complex*)&x[0], &y[0],spec_fFlags);

    fftw_execute_dft_c2r(plan, (fftw_complex*)&x[0], &y[0]);
    for (int i = 0; i < 9; i++) {
        printf("%f \n", y[i] / 9);
    }
    fftw_destroy_plan(plan);
    return 0;



}

However the plan returned by the "fftw_plan_guru_dft_c2r" is NULL resulting in a crash. What is possibly wrong here.

If I disregard the symmetry and use "fftw_plan_guru_dft" which does a complex to complex tranform, I get correct results.


Solution

  • According to the documentation, for multi-dimensional c2r transforms, no input preserving algorithms are implemented and hence the function to create the plan returns a null pointer.

    Removing the FFTW_PRESERVE_INPUT flag from spec_fFlags should get the code working.