Pitch Identification

This page contains a bunch of research on pitch identification. This is useful for mostly analysis, but it can be used for other things as well.

AMDF

AMDF (Average Magnitude Difference Function) is a method of detecting cycle length in repeating signals. This can be used for a bunch of stuff, like pitch detection and things like that. A desmos link that graphs an AMDF for a sine based signal. The definition as far as I know is:

$$ Q(k, n_0) = \frac{1}{N}\sum_{n=0}^{N} |x_0[n + n_0]-x_0[n + n_0 + k]| $$

where $k$ is the amount of “lag”, $n_0$ is the phase offset of the windows and $N$ is the size of the window.

The desmos graph shows the correlation between a window starting after point $p$ and a window at lag $k$. The way this works is you provide the function with a window size (in the case of our desmos graph $N$), as well as a “lag” value ($k$, which is plotted on the x-axis), that determines the offset of the lookup window. The AMDF function then returns a value based on how much the two windows correlate. This means that with a $k$ of $0$, the AMDF function will also return $0$, because both windows are identical.

The way you would use this to find a cycle point in a buffer is as follows: Lets say you’re trying to loop as smoothly as possible within a buffer. The first thing you do is choose a starting point in your buffer, this can be done fairly arbitrarily. The next step would be to go through the rest of the buffer and calculate the AMDF for every sample and take the index of the highest collerating sample. This would be a good point to loop with the initial sample. TODO: Add code example in either C++ or Rust.

ASDF

Slightly related, but there’s also the ASDF (Average Squared Difference Function), which sums squared versions of the comparison. Robert Bristow-Johnson has said that he prefers this one because “Turns out you can do calculus with that because the square function has continuous derivatives, but the absolute value function does not.”.

The ASDF is similar to the AMDF, and is defined as follows:

$$ Q(k, n_0) = \frac{1}{N}\sum_{n=0}^{N} (x_0[n + n_0]-x_0[n + n_0 + k])^2 $$

YIN autocorrelation

Yin autocorrelation is a technique for correlating a signal with itself, used in pitch detection. It is similar to the AMDF and the ASDF but the paper decribes a couple of steps to make this process way more accurate.

Example on desmos

Bitstream Autocorrelation

see this This has not been battletested, and seems to be developed for guitar pitch tracking, so I don’t know how well it would work on other sources.

References

Studies about or using the subject.

Blog posts

Reference implementations

Here are some examples of implementation in code:

  • TarsosDSP - Implementation in Java which is fairly easy to read.
  • ashokfernandez/Yin-Pitch-Tracking - A C program detailing it’s implementation of the YIN algorithm, describing how the steps relate to the paper.