DSPRelated.com
Forums

fftw in C++

Started by Kamran March 29, 2010
Hi,
Sorry if this is not the right forum but, I didn't know who else to turn to.
I have a quite simple process. I use FFTW library to take a forward fft 
of a one dimensional signal and then do some multiplication in freq. 
domain and then a backward (inverse) fft.  (called in a C++ code).
I check the result with matlab (as I understand matlab uses the same 
library). The forward result is identical in both matlab and my C++ 
code, but the backward fft is completely off mark, this is the relevant 
code: (I use the number of samples in the signal for number of frequency 
samples, nfft)

fftwf_complex* m_array;

for (int i= 0; i < ns; i++)
   m_array[i][0] = some_values;
   m_array[i][1] = some_other_values;
}

// take forward fft
fftwf_plan p = 0;
p = fftwf_plan_dft_1d(size, (fftwf_complex*) 
&m_array[0][0],(fftwf_complex*) &m_array[0][0],FFTW_FORWARD, FFTW_ESTIMATE);
fftwf_execute(p);
fftwf_destroy_plan(p);
 

// m_array now contains correct coefficients

// take backward fft, this should get me back to my original data
// but it doesn't

fftwf_plan p = 0;
p = fftwf_plan_dft_1d(size, (fftwf_complex*) 
&m_array[0][0],(fftwf_complex*) &m_array[0][0],FFTW_BACKWARD, 
FFTW_ESTIMATE);
fftwf_execute(p);
fftwf_destroy_plan(p);

// m_array is now filled with rubbish

appreciate any help,

Kamran
Sorry guys, disregard the whole thing. Id forgotten to normalize after 
taking inverse. stupid.

Kamran wrote:
> > Hi, > Sorry if this is not the right forum but, I didn't know who else to turn > to. > I have a quite simple process. I use FFTW library to take a forward fft > of a one dimensional signal and then do some multiplication in freq. > domain and then a backward (inverse) fft. (called in a C++ code). > I check the result with matlab (as I understand matlab uses the same > library). The forward result is identical in both matlab and my C++ > code, but the backward fft is completely off mark, this is the relevant > code: (I use the number of samples in the signal for number of frequency > samples, nfft) > > fftwf_complex* m_array; > > for (int i= 0; i < ns; i++) > m_array[i][0] = some_values; > m_array[i][1] = some_other_values; > } > > // take forward fft > fftwf_plan p = 0; > p = fftwf_plan_dft_1d(size, (fftwf_complex*) > &m_array[0][0],(fftwf_complex*) &m_array[0][0],FFTW_FORWARD, > FFTW_ESTIMATE); > fftwf_execute(p); > fftwf_destroy_plan(p); > > > // m_array now contains correct coefficients > > // take backward fft, this should get me back to my original data > // but it doesn't > > fftwf_plan p = 0; > p = fftwf_plan_dft_1d(size, (fftwf_complex*) > &m_array[0][0],(fftwf_complex*) &m_array[0][0],FFTW_BACKWARD, > FFTW_ESTIMATE); > fftwf_execute(p); > fftwf_destroy_plan(p); > > // m_array is now filled with rubbish > > appreciate any help, > > Kamran
On Mar 29, 2:50&#4294967295;pm, Kamran <kam...@uio.no> wrote:
> Hi, > Sorry if this is not the right forum but, I didn't know who else to turn to. > I have a quite simple process. I use FFTW library to take a forward fft > of a one dimensional signal and then do some multiplication in freq. > domain and then a backward (inverse) fft. &#4294967295;(called in a C++ code). > > > Kamran
Great that you could figure that out. Just to help others who might be having issues, here's link to my CFFTWWrapper class (includes usage code as well) that uses FFTW. Made it as a plugin for Image Apprentice couple of years ago. http://code.google.com/p/cfftwwrapper/ best regards, Divya Rathore www.adislindia.com