Jump to content

Fftw Transforms


Recommended Posts

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;
}

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...