0

I am trying to use the Math.NET numerics implementation of the FFT algorithm, but I must be doing something wrong because the output is always unit

The following is the the setup:

open MathNet.Numerics
open MathNet.Numerics.Statistics
open MathNet.Numerics.IntegralTransforms
let rnd = new Random()
let rnddata = Array.init 100 (fun u -> rnd.NextDouble())
let x = rnddata |> Array.Parallel.map (fun d -> MathNet.Numerics.complex.Create(d, 0.0) )

then when I run this:

let tt = MathNet.Numerics.IntegralTransforms.Fourier.BluesteinForward(x, FourierOptions.Default)

I receive an empty output below?

val tt : unit = ()

Any ideas why?

TylerH
  • 20,799
  • 66
  • 75
  • 101
user1129988
  • 1,516
  • 4
  • 19
  • 32

1 Answers1

1

I think the Fourier.BluesteinForward method stores the results in the input array (by overwriting whatever was there originally).

If you do not need the input after running the transform, you can just use x and read the results (this saves some memory copying, which is why Math.NET does that by default). Otherwise, you can clone the array and wrap it in a more functional style code like this:

let bluesteinForward input = 
  let output = Array.copy input
  MathNet.Numerics.IntegralTransforms.Fourier.BluesteinForward
    (output, FourierOptions.Default)
  output
Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • Wouldn't `Array.copy` be more idiomatic than `Array.map id`? Is there a hidden drawback I'm missing? – ildjarn Mar 29 '15 at 16:55
  • @ildjarn You're absolutely right, `Array.copy` is better! I just didn't have VS around and thought it should be "clone" but could not find it! – Tomas Petricek Mar 29 '15 at 17:12