简体   繁体   中英

Converting fft to ifft in C#

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 ic#? 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;

    }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM