DSPRelated.com
Forums

FFTW plans

Started by katz April 17, 2005
hello

i'm really sorry for what will seem to most people in this forum as a
trivial question, but i am having trouble using the FFTW library.
everything compiles correctly, but for some reason when i run the program
it crashes. i worked out that the problem comes from when i read the data
into the input array, but i really don't know what i am doing wrong. here
is the code. i know that this forum isn't supposed to check code...but i
am really stuck. 

           // FFT the text vector
           double *text_in, *text_out;
           fftw_plan p1; 
           int nx = Element.size();
              
           // Allocate the input and output arrays, and create the plan 
           text_in = (double*)fftw_malloc(sizeof(double) * nx );
           text_out = (double*)fftw_malloc(sizeof(double) * nx);
           
           fftw_plan_dft_r2c_1d(nx, text_in, text_out, FFTW_FORWARD);
           fftw_plan_dft_c2r_1d(nx, text_in, text_out, FFTW_BACKWARD);
           
           // Fill the input array with the input data
           for (int i = 0; i < Element.size(); i++)
           {  text_in[i] = Element[i]; // Real part
              text_in[i] = 0.0; /* Imaginary part */
           }
                                                                      
           // Execute plan on the input data i.e FFT the data
           fftw_execute(p1);
                   
           // destroy plan
           fftw_destroy_plan(p1);
           fftw_free(text_in); 
           fftw_free(text_out);        
   
have i misunderstood how to use the fftw plans? am i right in assuming
that the only problem is in filling the input array with the input data,
or are there more problems? 

thanx in advance, and really sorry once again, but i don't know who else
to ask. 
		
This message was sent using the Comp.DSP web interface on
www.DSPRelated.com
katz wrote:
> hello > > i'm really sorry for what will seem to most people in this forum as a > trivial question, but i am having trouble using the FFTW library. > everything compiles correctly, but for some reason when i run the program > it crashes. i worked out that the problem comes from when i read the data > into the input array, but i really don't know what i am doing wrong. here > is the code. i know that this forum isn't supposed to check code...but i > am really stuck. > > // FFT the text vector > double *text_in, *text_out; > fftw_plan p1;
p1 is never assigned the value of a plan
> int nx = Element.size(); > > // Allocate the input and output arrays, and create the plan > text_in = (double*)fftw_malloc(sizeof(double) * nx ); > text_out = (double*)fftw_malloc(sizeof(double) * nx);
You need nx+2 to account for the nyquist bin.
> > fftw_plan_dft_r2c_1d(nx, text_in, text_out, FFTW_FORWARD); > fftw_plan_dft_c2r_1d(nx, text_in, text_out, FFTW_BACKWARD);
The forward, or backward direction is implied by the 'r2c' or 'c2r'. You want something like FFTW_ESTIMATE for the last arg.
> > // Fill the input array with the input data > for (int i = 0; i < Element.size(); i++) > { text_in[i] = Element[i]; // Real part > text_in[i] = 0.0; /* Imaginary part */ > }
The first assignment is overwritten by the second.
> > // Execute plan on the input data i.e FFT the data > fftw_execute(p1);
again, nothing was ever assigned to p1
> > // destroy plan > fftw_destroy_plan(p1); > fftw_free(text_in); > fftw_free(text_out); > > have i misunderstood how to use the fftw plans? am i right in assuming > that the only problem is in filling the input array with the input data, > or are there more problems? > > thanx in advance, and really sorry once again, but i don't know who else > to ask.