コード例 #1
0
        void ComputeFFT()
        {
            if (FftQueue.Count > 0)
            {
                System.Numerics.Complex[] samples = new System.Numerics.Complex[NumberOfSamples];

                int index = 0;
                if (LeftOver != null)
                {
                    int count = Math.Min(LeftOver.Length, NumberOfSamples);
                    for (; count > index; index++)
                    {
                        samples[index] = new System.Numerics.Complex(LeftOver[index], 0);
                    }

                    if (index + 1 == LeftOver.Length)
                    {
                        LeftOver = null;
                    }
                    else
                    {
                        LeftOver = LeftOver.Skip(index + 1).ToArray();
                    }
                }

                if (index + 1 < NumberOfSamples)
                {
                    while (index + 1 < NumberOfSamples)
                    {
                        if (FftQueue.Count == 0)
                        {
                            break;
                        }
                        float[]  array   = FftQueue.Dequeue();
                        double[] hamming = Window.Hamming(array.Length);

                        array = array.Select((f, i) => (float)(hamming[i] * f)).ToArray();

                        int count = Math.Min(array.Length, NumberOfSamples - index);
                        for (int i = 0; count > i; i++)
                        {
                            samples[index] = new System.Numerics.Complex(array[i], 0);
                            index++;
                        }

                        if (array.Length > count)
                        {
                            int diff = array.Length - count;
                            LeftOver = array.Skip(count).ToArray();
                        }
                    }
                }

                FourierOptions options = FourierOptions.Matlab;
                Fourier.Forward(samples, options);
                FftFinished?.Invoke(this, new FourierEventArgs(samples, options));
            }
        }
コード例 #2
0
 private void Fft_FftFinished(object sender, FFT.FourierEventArgs e)
 {
     FftFinished?.Invoke(this, e);
 }