Exemplo n.º 1
0
 public void Simple_example()
 {
     Complex[] time = Arrays.New <Complex>(8, t => t == 1 ? 1 : 0);
     Complex[] freq =
     {
         new Complex(0.125,      0), new Complex(0.088, -0.088), new Complex(0,     -0.125), new Complex(-0.088, -0.088), new Complex(-0.125, 0),
         new Complex(-0.088, 0.088), new Complex(0,      0.125), new Complex(0.088, 0.088)
     };
     Assert.That(fft.Forward(time), Is.EqualTo(freq).Using(Complex.Within(1E-6)));
 }
        private static Tuple <double[], double[]> Calculate(IList <double> data, int window, int step, int startF, int endF, Action <double> progress)
        {
            var res   = new double[endF - startF];
            var res2  = new double[endF - startF];
            int count = 0;

            var n = 1 + (data.Count - window) / step;

            for (int i = 0; i < data.Count - window; i += step)
            {
                var w = new double[window];
                for (int j = 0; j < window; j++)
                {
                    w[j] = data[i + j];
                }

                var cur = Fft.Forward(w);

                for (int q = startF; q < endF; q++)
                {
                    var mag = cur[q].Magnitude;
                    res[q - startF]  += mag;
                    res2[q - startF] += mag * mag;
                }

                count++;
                progress((double)count / n * 100.0);
            }

            for (int i = 0; i < res.Length; i++)
            {
                res[i]  /= count;
                res2[i] /= count;
            }

            return(new Tuple <double[], double[]>(res, res2));
        }