Arduino pitch detection in realtime (using autocorrelation and peak detection)

barthulsen:
MrMark, what I mean with a frequency sweep is to put a lot of different, known frequencies on the input and determine a formula that could be used as a correction. However, you made clear to me that the resolution becomes a problem. Is that why I'm getting very constant results?

The algorithm without interpolation will only return certain discrete values. The possible values are the sample rate divided by an integer value because the lag value must be integer.

It's reassuring that the derivation I did for quadratic interpolation matches the code at your link. :slight_smile:

If I understand correctly, that code takes the measured frequency and maps it to specific notes which seems appropriate for music transcription, but wouldn't make sense for a tuning aid. It appears to be a nicely done project.

I'm going to take a look at continuous sampling, try to convert the peak state machine and see how interpolation is implemented in the link above. (There is a link to GitHub on the website for the code of the project).

It turns out to be pretty simple. The formula is 0.5 * (right - left) / (2 * mid - left - right) where "mid" is the correlation amplitude at the detected peak, "right" and "left" are the correlation amplitude of the correlation amplitude at the lags immediately following and preceding the detected peak respectively. This gives a fractional offset that is added to the lag at the detected peak.