1

I am using C++ function to find inverse Fourier transform.

int inYSize = 170; int inXSize = 2280;

float* outData = new float[inYSize*inXSize];
fftwf_plan mReverse = fftwf_plan_dft_c2r_2d(inYSize, inXSize,(fftwf_complex*)temp, outdata,  
FFTW_ESTIMATE);
fftwf_execute(mReverse);

My input is 2D array temp with complex numbers. All the elements have real value 1 and imaginary 0.

So I am expecting InverseFFT of such an array should be 2D array with real values. Output array should have SPIKE at 0,0 and rest all values 0. But I am getting all different values in the output array even after normalizing with total size of an array. What could be the reason?

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
MShah
  • 11
  • 4

2 Answers2

2

FFTW is not that trivial to deal with when it comes to multidimensional DFT and Complex to Real transform.

  1. When doing a C2R transform of a MxN row-major array, the second dimension is cut in half because of the symmetry of the result : outData is twice bigger than needed, but it's not the reason of your problem (and not you're case as you are doing C2R and not R2C). More info about this tortuous matter : http://www.fftw.org/doc/One_002dDimensional-DFTs-of-Real-Data.html

    "Good Guy Advice" : Use only the C2C "easier" way of doing things, take the modulus of the output if you don't know how to process the results, but don't waste your time on n-D Complex to Real transforms.

  2. Because of limited precision, because of the numerical implementation of the DFT, because of unsubordinated drunk bits, you can get values that are not 0 even if they are very small. This is the normal behavior of a FFT algorithm.

Besides reading carefully the user manual (http://www.fftw.org/doc/) even if it's a real pain (I lost few days around this library just to get a 3D transform working, just to understand how data was scaled)

  • You should try with a C2C 1D transform before going C2C 2D and C2R 2D, just to be sure you have somehow an idea of what you're doing.
  • What's the inverse FFT of a planar constant something where every bin of the "frequency-plane" is filled with a one ? Are you looking for a new way to define +inf or -inf ? In that case I would rather start with the easier division by 0 ^^. The direct FFT should be a as you described, with the SPIKE correctly scaled being 1, pretty sure the inverse is not.

Do not hesitate to add precision to your question, and good luck with FFTW

Pascail
  • 374
  • 2
  • 11
  • 1
    good valuable comments but however I would not agree with your +/-inf thing: If it would have been DTFT instead of DFT where we have continuous frequency and discrete time, we would have got INF. But since DFT is discrete in both axis, we would at the maximum will get Total size of array and not +inf. Anyways it is more into DSP and I was basically asking for C++ related help and your first two points will help me. Thanks – MShah Apr 25 '13 at 00:48
  • No offense intended :). You may also want to check if the data type you're using can handle the output, even if 10^+38 seems ok, doubles may give a different behaviour (?) – Pascail Apr 25 '13 at 08:10
  • If you think my answer somehow helped you, accepting it would be really nice :) – Pascail May 03 '13 at 12:03
0

With this little information it is hard to tell. What i could imagine would be that you get spectral leakage due to the window selection (See This Wikipedia article for details about leakage).

What you could do is try using another windowing function to reduce leakage or redefine your windowing size.

MatthiasB
  • 1,759
  • 8
  • 18