简体   繁体   English

在C#中将fft转换为ifft

[英]Converting fft to ifft in C#

I have a working FFT, but my question is how do I convert it into an IFFT? 我的FFT工作正常,但我的问题是如何将其转换为IFFT? I was told that an IFFT should be just like the FFT that you are using. 有人告诉我,IFFT应该像您正在使用的FFT一样。 so how do I make an ifft from a fft ic#? 那么我该如何从fft ic#进行ifft? I was told there should only be a few changes made to get the ifft. 有人告诉我,应该只进行一些更改以获取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... 所以我制作了一个值数组并将其放入fft中,然后将其放入了ifft中,我无法获得与我输入的相同的值...

so I do not think I changed it the right way. 所以我认为我没有正确地改变它。

this is the FFT I have: 这是我拥有的FFT:

    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). 根据FFT的不同,您可能需要将整个复数矢量(输入或结果矢量,而不是两者)乘以1 / N(FFT的长度)。 But this scale factor differs between FFT libraries (some already include a 1/sqrt(N) factor). 但是此比例因子在FFT库之间有所不同(有些已经包含1 / sqrt(N)因子)。

Then take the complex conjugate of the input vector, FFT it, and do another complex conjugate to get the IFFT result. 然后取输入向量的复共轭,对其进行FFT,然后进行另一个复共轭以获得IFFT结果。 This is equivalent to doing an FFT using -i instead of i for the basis vector exponent. 这等效于对基本矢量指数使用-i而不是i进行FFT。

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. 同样,通常,由于算术舍入将至少一些低电平数值噪声添加到结果中,因此不会从输入的IFFT(FFT())中获得相同的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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