I need someone with experience using FFTW
I am writing a program which needs to do a real to complex transform, but my planning routine returns back null and I am not sure why. I am passing valid integer parameters for the size, and non-NULL pointers for the array. I have consulted the documentation but all it says is that if it cannot make the plan it returns NULL, but besides doing the opposite of what I mentioned above, it does not list any other reasons for my plan failing. Below is piece of sample code
int size ={64, 128, 256};
float *spatial = malloc(size[1]*size[1]*sizeof(float));
fftwf_complex *fourier = fftwf_alloc_complex(size[1]*size[1]);
for(int i=0; i< size[1]; i++){
    for(int j=0; j<size[1]; j++){
        spatial = //fill spatial array;
    }
}
for(int i=0; i< size[1]; i++){
    for(int j=0; j<size[1]; j++){
        fourier = //fill fourier array;
    }
}
fftwf_plan plan = fftwf_plan_dft_r2c_2d(size[1], size[1], spatial, fourier, FFTW_FORWARD);
fftwf_execute(plan);
the  fftwf_plan_dft_r2c_2d() continually returns back NULL for plan and I am not sure why
Note: I am using Windows 8.1 with Visual Studios 2012
                        
I was able to reproduce your problem on ubuntu... The problem comes from the flag
FFTW_FORWARDused byfftwf_plan_dft_r2c_2d. I don't know where it is documented, but it is not working. The reason is thatfftwf_plan_dft_r2c_2dis always a forward transform, the backward transform beingfftwf_plan_dft_c2r_2dMoreover, you can reduce the memory footprint of your program. Indeed, in case of r2c transforms, only half the complex coefficients are computed and stored. Hence, the array allocated by
fftwf_alloc_complex(size[1]*size[1]);is about twice the needed size. Take a look at the documentation to know more about the extra padding and the layout of frequencies.Here is a program compiled by
gcc main.c -o main -lfftw3f -lm -std=c99(may be different on your computer...). The flagFFTW_FORWARDis replaced byFFTW_ESTIMATE. And#include <complex.h>is placed before#include <fftw3.h>so that fftw can use the float complex type ofcomplex.h