简体   繁体   English

C#MathNet FFT定义

[英]C# MathNet FFT Definition

I have some problem when testing FFT from MathNet: The idea is that if I apply FFT to the characteristic function of a gaussian variable I should find the gaussian density function. 从MathNet测试FFT时,我遇到一些问题:这个想法是,如果将FFT应用于高斯变量的特征函数,我应该找到高斯密度函数。

When I plot VectorFFT the figure does seems a density function but in zero it does not have value 1, it has value 1.4689690914109. 当我绘制VectorFFT时,该图看起来确实是一个密度函数,但在零值处它没有值1,在值1.4689690914109中。

There must be some problems with the scaling. 缩放必须存在一些问题。 I tried out all type of FourierOptions in Fourier.Inverse and all type of divisions/multiplications for PI, 2PI, sqrt(2PI) but nothing gives me the value 1 at the center of the density function. 我在Fourier中尝试了所有类型的FourierOptions.Inverse和PI,2PI,sqrt(2PI)的所有除法/乘法类型,但没有任何东西让我在密度函数的中心得到值1。

Also, since various definitions of Fourier Transform and its inverse exists, I was wondering which one is implemented by MathNet, I could not find it in the documentation. 另外,由于存在傅立叶变换及其逆的各种定义,所以我想知道MathNet实现了哪个定义,所以在文档中找不到它。

Any ideas? 有任何想法吗?

public void DensityGaussian()
    {
        double eta = 0.1;   //step in discrete integral
        int pow2 = 256;     // N^2
        double mu = 0;      // centred gaussian
        double sigma = 1;   // with unitary variance

        //FFT
        double lambda = 2 * System.Math.PI / (pow2 * eta);
        double b = 0.5 * pow2 * lambda;

        Complex[] VectorToFFT = new Complex[pow2];
        for (int j = 0; j < pow2; j++)
        {
            double z = eta * j;

            if (z == 0) { z = 0.00000000000001; }

            VectorToFFT[j] = System.Numerics.Complex.Exp(new Complex(0, b * z));
            VectorToFFT[j] *= (System.Numerics.Complex.Exp(new Complex(
                              -sigma*sigma*z*z, mu * z))); //char function of gaussian
        }

        Fourier.Inverse(VectorToFFT, FourierOptions.NoScaling);

        //scaling
        for (int i = 0; i < pow2; i++)
        {
            VectorToFFT[i] /= (2 * System.Math.PI); //test
        }


        Console.WriteLine("Is density?");
        Assert.IsTrue(1 == 1);
    }

Math.NET Numerics supports all common DFT definitions, controllable with the FourierOptions flags enum. Math.NET Numerics支持所有常见的DFT定义,可通过FourierOptions标志枚举来控制。 They essentially vary on the exponent and on the scaling. 它们实质上在指数和缩放比例上有所不同。

The FourierOptions docs give some hints on how the options affect the effective definition, essentially: FourierOptions文档本质上给出了有关选项如何影响有效定义的提示:

  • InverseExponent: use a negative sign in the exponent (default uses a positive sign). InverseExponent:在指数中使用负号(默认情况下使用正号)。 A prominent implementation with a negative sign is numerical recipes. 带有负号的突出实现是数字配方。
  • AsymmetricScaling/NoScaling: instead of the default symmetric scaling sqrt(1/N) either only scale in the inverse transformation 1/N (like Matlab) or no scaling at all (like numerical recipes). AsymmetricScaling / NoScaling:代替默认的对称缩放sqrt(1/N) ,仅以逆变换1/N缩放(如Matlab),或者根本不进行缩放(如数值配方)。 Obviously, without scaling ifft(fft(x)) != x . 显然,无需缩放ifft(fft(x)) != x

Maybe the answer in Calculating a density from the characteristic function using fft in R can help on the specific use case. 也许在R中使用fft从特征函数计算密度中的答案可以对特定用例有所帮助。

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

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