Ejemplo n.º 1
0
        public void PlotFFTFull(PlotView view, WindowType windowType)
        {
            var fft    = new FFTWrapper(waveList);
            var result = fft.CalculateMagnitude(windowType);

            FillFFTView(view, result);
        }
Ejemplo n.º 2
0
        public void PlotBandEnergy(PlotView view, WindowType windowType, int frameLength, double overlap, double minFrequency, double maxFrequency)
        {
            FillDefaultPlotView(view, "", new double[0]);

            var binWidth = sampleRate / frameLength;

            var data = ForEachFrame(windowType, frameLength, overlap, (double[] sample, int idx) => {
                sample = sample.Take(frameLength / 2).ToArray();

                double limiter = 0;
                for (int i = 0; i < sample.Length; i++)
                {
                    var w = i * binWidth;
                    if (w >= minFrequency && w <= maxFrequency)
                    {
                        limiter += sample[i] * sample[i];
                    }
                }

                var window      = FFTWrapper.GetWindow(windowType, frameLength);
                var denominator = window.Sum();
                return(limiter / denominator);
            });

            FillDefaultPlotView(view, "Band Energy", data);
        }
Ejemplo n.º 3
0
        public void PlotFundamentalFrequency(PlotView view, WindowType windowType, int frameLength, double overlap)
        {
            var span    = (int)Math.Round(frameLength * (1.0 - overlap));
            var columns = waveList.Count / span;
            var data    = new double[columns];
            var begin   = 2 * 50 * frameLength / sampleRate;
            var end     = 2 * 400 * frameLength / sampleRate;

            if (begin == end)
            {
                FillDefaultPlotView(view, "Frequency (Hz)", data);
                return;
            }

            for (int i = 0, beginPoint = 0; i < columns; i++, beginPoint += span)
            {
                var sample     = GetSample(frameLength, beginPoint);
                var fft        = new FFTWrapper(sample);
                var forward    = fft.CalculateMagnitude(windowType);
                var inverse    = new FFTWrapper(forward.Select(d => new Complex(Math.Log10(d), 0)).ToArray());
                var result     = inverse.Calculate(windowType, false).Select(d => d.Real);
                var resultSnip = result.Skip(begin).Take(end - begin).ToList();
                var max        = resultSnip.IndexOf(resultSnip.Max());
                var realIdx    = max + begin;
                data[i] = realIdx * sampleRate / (2 * frameLength);
            }

            FillDefaultPlotView(view, "Frequency (Hz)", data);
        }
Ejemplo n.º 4
0
        public void PlotFFTFrame(PlotView view, WindowType type, int frameLength, double beginTime)
        {
            var result     = GetSample(frameLength, beginTime).ToList();
            var fft        = new FFTWrapper(result);
            var calculated = fft.CalculateMagnitude(type);

            FillFFTView(view, calculated);
        }
Ejemplo n.º 5
0
        private double[] ForEachFrame(WindowType windowType, int frameLength, double overlap, Func <double[], int, double> calculationFunc)
        {
            var span    = (int)Math.Round(frameLength * (1.0 - overlap));
            int columns = waveList.Count / span;
            var data    = new double[columns];

            for (int i = 0, beginPoint = 0; i < columns; i++, beginPoint += span)
            {
                var sample = GetSample(frameLength, beginPoint);
                var fft    = new FFTWrapper(sample);
                var result = fft.CalculateMagnitude(windowType);
                data[i] = calculationFunc(result, i);
            }

            return(data);
        }
Ejemplo n.º 6
0
        public void PlotSpectogram(PlotView view, WindowType windowType, int frameLength, double overlap)
        {
            var span    = (int)Math.Round(frameLength * (1.0 - overlap));
            int columns = waveList.Count / span;
            var data    = new double[columns, frameLength / 2];

            for (int i = 0, beginPoint = 0; i < columns; i++, beginPoint += span)
            {
                var sample = GetSample(frameLength, beginPoint);
                var fft    = new FFTWrapper(sample);
                var result = fft.CalculateMagnitude(windowType);
                for (int y = 0; y < frameLength / 2; y++)
                {
                    data[i, y] = 20 * Math.Log10(result[y]);
                }
            }

            FillSpectogram(view, data);
        }