0

I have a working FFT, but my question is how do I convert it into an IFFT? I was told that an IFFT should be just like the FFT that you are using. so how do I make an ifft from a fft i c#? I was told there should only be a few changes made to get the ifft.

I tried to do it myself, but I am not getting the same values back that I put in...

so I made an array of values and put it in to the fft and then the ifft and I can not getting the same values I put in...

so I do not think I changed it the right way.

this is the FFT I have:

    public Complex[] FFT(Complex[] x )
   {
       int N2 = x.Length;
       Complex[] X = new Complex[N2];
       if (N2 == 1)
       {
           return x;
       }
       Complex[] odd = new Complex[N2 / 2];
       Complex[] even = new Complex[N2 / 2];
       Complex[] Y_Odd = new Complex[N2 / 2];
       Complex[] Y_Even = new Complex[N2 / 2];
       for (int t = 0; t < N2 / 2; t++)
       {
           even[t] = x[t * 2];    
           odd[t] = x[(t * 2) + 1];
       }
       Y_Even = FFT(even);
       Y_Odd = FFT(odd);
       Complex temp4;

       for (int k = 0; k < (N2 / 2); k++)
       {
           temp4 = Complex1(k, N2);
           X[k] = Y_Even[k] + (Y_Odd[k] * temp4);
           X[k + (N2 / 2)] = Y_Even[k] - (Y_Odd[k] * temp4);  
           }
       return X;
   }



    public Complex Complex1(int K, int N3)
    {
        Complex W = Complex.Pow((Complex.Exp(-1 * Complex.ImaginaryOne * (2.0 * Math.PI / N3))), K);
        return W;

    }
  • A quick and easy way to get an IFFT if you only have an FFT is to do `conjugate -> FFT -> conjugate -> scale (optional)`. – Paul R Jul 21 '14 at 21:21
  • Most cell phones only have 1 FFT chip, and the reason being that chip can do FFT and IFFT. To obtain the IFFT you need to do the FFT, scale the result, and shift the result. More info on [Wikipedia](http://en.wikipedia.org/wiki/Fast_Fourier_transform) "Since the inverse DFT is the same as the DFT, but with the opposite sign in the exponent and a 1/N factor, any FFT algorithm can easily be adapted for it." – Chris Jul 21 '14 at 22:34
  • Chris can you show me an example? I do not understand what you mean by just add an 1/N and do you mean that Complex W = Complex.Pow((Complex.Exp(-1 * Complex.ImaginaryOne * (2.0 * Math.PI / N3))), K); should be Complex W = Complex.Pow((Complex.Exp(1 * Complex.ImaginaryOne * (2.0 * Math.PI / N3))), K); Also you cant just add 1/N can you? do you need to do double t1 = Math.Cos(Math.PI * k / (double)N2); double t2 = Math.Sin(Math.PI * k / (double)N2);? – Brandon Boone Jul 22 '14 at 02:51

1 Answers1

0

Depending on the FFT, you may have to scale the entire complex vector (multiply either the input or result vector, not both) by 1/N (the length of the FFT). But this scale factor differs between FFT libraries (some already include a 1/sqrt(N) factor).

Then take the complex conjugate of the input vector, FFT it, and do another complex conjugate to get the IFFT result. This is equivalent to doing an FFT using -i instead of i for the basis vector exponent.

Also, normally, one does not get the same values out of a computed IFFT(FFT()) as went in, as arithmetic rounding adds at least some low level numerical noise to the result.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153