MADjestic Posted November 1, 2006 Share Posted November 1, 2006 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[N]; double *data_d, array_d[N]; 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]=i;} cout <<"******pointer *data_d values*********" << endl; for(i=0;i<N;i++)cout<< data_d[i]<< 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[i]<< 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[i]<< endl; return EXIT_SUCCESS; } Quote Link to comment Share on other sites More sharing options...
MADjestic Posted November 1, 2006 Author Share Posted November 1, 2006 For anybody interested - I found this link - http://www.scs.fsu.edu/~burkardt/c_src/fftw3/fftw3.html it apparently answers my question, nevertheless if you've got somethingto share - I'll appreciate this. cheers. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.