/// <summary> /// Pitch estimation: from spectral peaks /// </summary> /// <param name="signal"></param> /// <param name="startPos"></param> /// <param name="endPos"></param> /// <returns></returns> public static float FromSpectralPeaks(DiscreteSignal signal, int startPos = 0, int endPos = -1, float low = 80, float high = 400, int fftSize = 0) { if (endPos == -1) { endPos = signal.Length; } if (startPos != 0 || endPos != signal.Length) { signal = signal[startPos, endPos]; } signal.ApplyWindow(WindowTypes.Hann); var size = fftSize > 0 ? fftSize : MathUtils.NextPowerOfTwo(signal.Length); var fft = new RealFft(size); var spectrum = fft.PowerSpectrum(signal, false).Samples; return(FromSpectralPeaks(spectrum, signal.SamplingRate, low, high)); }