Search code examples
algorithmaudioinstruments

Robust algorithm for chromatic instrument tuner?


Who knows the most robust algorithm for a chromatic instrument tuner?

I am trying to write an instrument tuner. I have tried the following two algorithms:

  1. FFT to create a welch periodogram and then detect the peak frequency

  2. A simple autocorrelation (http://en.wikipedia.org/wiki/Autocorrelation)

I encountered the following basic problems:

  1. Accuracy 1: in FFT the relation between samplerate, recording length and bin size is fixed. This means that I need to record a 1-2 seconds of data to get an accuracy of a few cents. This is not exactly what i would call realtime.

  2. Accuracy 2: autocorrelation works a bit better. To get the needed accuracy of a few cents I had to introduced linear interpolation of samples.

  3. Robustness: In case of a guitar I see a lot of overtones. Some overtones are actually stronger than the main tone produced by the string. I could not find a robust way to select the right string played.

Still, any cheap electronic tuner works more robust than my implementation. How are those tuners implemented?


Solution

  • You can interpolate FFTs also, and you can often use the higher harmonics for increased precision. You need to know a little bit about the harmonics of the instrument that was produced, and it's easier if you can assume you're less than half an octave off target, but even in the absence of that, the fundamental frequency is usually much stronger than the first subharmonic, and is not that far below the primary harmonic. A simple heuristic should let you pick the fundamental frequency.

    I doubt that the autocorrelation method will work all that robustly across instruments, but you should get a series of self-similarity scores that is highest when you're offset by one fundamental frequency. If you go two, you should get the same score again (to within noise and differential damping of the different harmonics).