**Theory**

Fundamentally, this algorithm exploits the fact that a periodic signal, even if it is not a pure sine wave, will be similar from one period to the next. This is true even if the amplitude of the signal is changing in time, provided those changes do not occur too quickly.

To detect the pitch, we take a window of the signal, with a length at least twice as long as the longest period that we might detect. In our case, this corresponded to a length of 1200 samples, given a sampling rate of 44,100 KHz.

Using this section of signal, we generate the autocorrelation function r(s) defined as the sum of the pointwise absolute difference between the two signals over some interval, perhaps 600 points.

Graphically, this corresponds to the following:

Shifting the signal |
---|

Intuitively, it should make sense that as the shift value s begins to reach the fundamental period of the signal T, the difference between the shifted signal and the original signal will begin to decrease. Indeed, we can see this in the plot below, in which the autocorrelation function rapidly approaches zero at the fundamental period.

Autocorrelation Function |
---|

We can detect this value by differentiating the autocorrelation function and then looking for a change of sign, which yields critical points. We then look at the direction of the sign change across points (positive difference to negative), to take only the minima. We then search for the first minimum below some threshold, i.e. the minimum corresponding to the smallest s. The location of this minimum gives us the fundamental period of the windowed portion of signal, from which we can easily determine the frequency using

**FAST-Autocorrelation**

Clearly, this algorithm requires a great deal of computation. First, we generate the autocorrelation function r(s) for some positive range of s. For each value of s, we need to compute the total difference between the shifted signals. Next, we need to differentiate this signal and search for the minimum, finally determining the correct minimum. We must do this for each window.

In generating the r(s) function, we define a domain for s of 0 to 599. This allows for fundamental frequencies between about 50 and 22000 Hz, which works nicely for human voice. However, this does require calculating r(s) 600 times for each window.

In effort to improve the efficiency of this algorithm, we created an alternative called FAST Autocorrelation, which has yielded speed improvements in excess of 70%.

We exploit the nature of the signal, specifically the fact that if the signal was generated using a high sampling rate and if the windows are narrow enough, we can assume that the pitch will not vary drastically from window to window. Thus, we can begin calculating the r(s) function using values of s that correspond to areas near the previous minimum. This means that, if the previous window had a fundamental period of 156 samples, we begin calculating r(s) for s = 136. If we fail to find the minimal s in this area, we calculate further and further from the previous s until we find a minimum.

Also, we note that the first minimum (valued below the threshold) is always going to correspond to the fundamental frequency. Thus, we can calculate the difference equation dr(s)/ds as we generate r(s). Then, when we find the first minimum below threshold, we can stop calculating altogether and move on to the next window.

If we use only the second improvement, we usually cut down the range of s from 600 points to around 200. If we then couple in the first improvement, we wind up calculating r(s) for only about 20 values of s, which is a savings of (580) * (1200) = 700000 calculations per window. When the signal may consist of hundreds of windows, this improvement is substantial indeed.

**Limitations of Autocorrelation**

The autocorrelation algorithm is relatively impervious to noise, but is sensitive to sampling rate. Because it calculates fundamental frequency directly from a shift in samples, it follows that if we have a lower sampling rate, we have lower resolution in pitch.

As stated earlier, autocorrelation is also extremely expensive computationally. However, using the adaptive techniques described above, computation can be expedited and run in near-real time.

Comments:"assafdf"