public void PlotFFTFull(PlotView view, WindowType windowType) { var fft = new FFTWrapper(waveList); var result = fft.CalculateMagnitude(windowType); FillFFTView(view, result); }
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); }
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); }
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); }
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); }