2

I have a problem calculating the FFT from my data set, using Math.NET with .NET4.0.

I used .NET 3.5 with Math.NET like this without any errors:

    public Ergebnisse_FFT_Abs_PSD_MNF FFT_Abs_PSD_MNF(double[] data) 
    {
       Complex[] samples = new Complex[data.Length];
       double[] FFT_abs_1d = new double[data.Length / 2];

       int zaehler = 0;
       foreach(double val in data)
       {
          samples[zaehler] = new Complex(val, 0);
          Fenster[zaehler] = Math.Exp(-0.5 * Math.Pow(((zaehler - (samples.Length - 1) / 2) / (sigma * (samples.Length - 1) / 2)), 2)); // Gauß
          samples[zaehler] = samples[zaehler].Real * Fenster[zaehler];
          zaehler++;
       }   
       MathNet.Numerics.IntegralTransforms.Fourier.BluesteinForward(samples, MathNet.Numerics.IntegralTransforms.FourierOptions.Matlab);
    }

Now I want to use .NET 4.0 and Complex[] is no longer known - only Complex32. When I now change Complex[] to Complex32[]:

    public Ergebnisse_FFT_Abs_PSD_MNF FFT_Abs_PSD_MNF(double[] data) 
    {
       Complex32[] samples = new Complex32[data.Length];
       double[] FFT_abs_1d = new double[data.Length / 2];

       int zaehler = 0;
       foreach(double val in data)
       {
          samples[zaehler] = new Complex32((float)val, 0);
          Fenster[zaehler] = Math.Exp(-0.5 * Math.Pow(((zaehler - (samples.Length - 1) / 2) / (sigma * (samples.Length - 1) / 2)), 2)); // Gauß
          samples[zaehler] = samples[zaehler].Real * (float)Fenster[zaehler];
          zaehler++;
       }       

       MathNet.Numerics.IntegralTransforms.Fourier.BluesteinForward(samples, MathNet.Numerics.IntegralTransforms.FourierOptions.Matlab);
    }

this error-message occurs:

Error 7 The best overloaded method match for 'MathNet.Numerics.IntegralTransforms.Fourier.BluesteinForward(System.Numerics.Complex[], MathNet.Numerics.IntegralTransforms.FourierOptions)' has some invalid arguments

Does anyone has an idea, how to solve this problem under .NET 4.0?

JoMa
  • 25
  • 5

1 Answers1

1

The comment from Hans Passant is correct - simply add a reference to System.Numerics. Technically this is declared in the NuGet package and should be added automatically to the project once the package gets reinstalled (which is required when changing the target framework of a project).

There is no System.Numerics in .Net 3.5, that's why Math.NET Numerics brings its own implementation there, but for .Net 4.0 and newer it uses the built-in type from System.Numerics in order to be compatible with the ecosystem.

Christoph Rüegg
  • 4,626
  • 1
  • 20
  • 34