Hi there,
I am trying to learn to handle properly the fftw library routines, more specifically fftw_plan_dft_r2c_1d (2d) real-to-complex forward and backward transforms. See the simple code – it looks like the whole thing works, however the input data of the array (0,1,2,3…9) turns into zeros after the transform. The in-place transform also results in all zeros. (I assume that forward-backward transform of arbitrary data must result in original unchanged data). Or am I missing something? Does anybody have experience with this and maybe can share a simple piece of code?
#include <cstdlib>
#include <fftw3.h>
#include <stdio.h>
using namespace std;
int main(int argc, char *argv)
{
fftw_plan pf, pb;
int N=10, i, j;
fftw_complex *data, array;
double *data_d, array_d;
data = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
data = array;
data_d = (double*) fftw_malloc(sizeof(fftw_complex) * N);
data_d = array_d;
for(i=0;i<N;i++){array_d=i;}
cout <<“******pointer *data_d values*********” << endl;
for(i=0;i<N;i++)cout<< data_d<< endl;
cout <<“******FFT Forward transform*********” << endl;
pf = fftw_plan_dft_r2c_1d(N, data_d, data, FFTW_FORWARD); fftw_execute(pf);
for(i=0;i<N;i++)cout<< data<< endl;
cout <<“*****FFT Backward transform********” << endl;
pb = fftw_plan_dft_c2r_1d(N, data, data_d, FFTW_BACKWARD); fftw_execute(pb);
for(i=0;i<N;i++)cout<< data_d<< endl;
return EXIT_SUCCESS;
}
thanks