![]() Of course, we must somehow remove the infinitely long tails of the Gaussian window in practice, but this does not cause much deviation from a parabola As a result, quadratic spectral peak interpolation is exact under the Gaussian window. Note that the Gaussian window transform magnitude is precisely a parabola on a dB scale. Print( 'Calculating frequency from harmonic product spectrum:') Print( '%f Hz' % freq_from_autocorr( signal, fs)) Print( 'Calculating frequency from autocorrelation:', end = ' ') Print( '%f Hz' % freq_from_crossings( signal, fs)) Print( 'Calculating frequency from zero crossings:', end = ' ') Print( 'Time elapsed: %.3f s \n' % ( time() - start_time)) Print( '%f Hz' % freq_from_fft( signal, fs)) Print( 'Calculating frequency from FFT:', end = ' ') Print( 'Reading file "%s" \n' % filename) ![]() Print( 'Pass %d: %f Hz' % ( x, fs * true_i / len( windowed))) Windowed = sig * blackmanharris( len( sig))įrom pylab import subplot, plot, log, copy, showĪ = copy( c) # Should average or maximum instead of decimating # Should use a weighting function to de-emphasize the peaks at longer lags.Įstimate frequency using harmonic product spectrum (HPS) ![]() # samples, and other peaks appearing higher. # not reliable for long signals, due to the desired peak occurring between # Find the next peak after the low point (other than 0 lag). # Find all indices right before a rising-edge zero crossing signal import blackmanharris, correlateĮstimate frequency by counting zero crossings Pro: Good at finding the true fundamental even if weak or missingįrom numpy import argmax, mean, diff, log, nonzeroįrom scipy.Con: This implementation has trouble with finding the true peakĬalculate harmonic product spectrum and find the peak.Con: Not as accurate as other methods for precise measurement of sine waves.Pro: This inaccurate result more closely matches the pitch that humans perceive :).Con: Inaccurate result if waveform isn't perfectly repeating, like inharmonic musical instruments (piano, guitar.Pro: Best method for finding the true fundamental of any repetitive wave, even with weak or missing fundamental (finds GCD of all harmonics present).Due to parabolic interpolation being a very good fit for windowed log FFT peaks? Pro: Accurate, usually even more so than zero crossing counter (1000.000004 Hz for 1000 Hz, for instance).Better method would try to be smarter about identifying the fundamental, like template matching using the "two-way mismatch" (TWM) algorithm. Con: Doesn't find the right value if harmonics are stronger than fundamental, which is common.Accuracy also increases with signal/FFT length.Using parabolic interpolation to find a truer peak gives better accuracy.Con: Doesn't work if there are multiple zero crossings per cycle, low-frequency baseline shift, noise, etc.Pro: Accurate (increasing with signal length).Using interpolation to find a "truer" zero-crossing gives better accuracy.Supposedly this is how cheap guitar tuners work.Works well for long low-noise sines, square, triangle, etc.Count zero-crossings, divide average period by time to get frequency None of them work well in all situations, these are "offline", not real-time, and I am sure there are much better methods "in the literature", but here is some sample code for the simple methods at least. Initially I was trying to measure the frequency of long sine waves with high accuracy (to indirectly measure clock frequency), then added methods for other types of signals later. So these are my attempts at implementation. Music - How do you analyse the fundamental frequency of a PCM or WAV sample.These are the methods that everyone recommends when someone asks aboutįrequency estimation or pitch detection. I need to keep them both in sync with each other or delete one. See also, which is mostly the same thing, maybe more up-to-date. A few simple frequency estimation methods in Python
0 Comments
Leave a Reply. |