Many systems contain periodic or quasi-period signals whose periods must be estimated based on measurements of those signals. Examples include power-line communications, which must measure the AC line voltage frequency, guitar and other instrument tuners, music synthesizers that track the frequency of audio input for conversion to control voltage (CV) or MIDI, etc.
The question of how to properly average a succession of N measured periods comes up in these systems for obvious reasons. The more periods we average over, the further we can suppress the noise that afflicts each individual measurement. There is a tradeoff here though because the more periods we average over, the longer it takes for us to arrive at the final “average” period. A well-designed system would average over enough periods to get the data as smooth as desired without suffering any undesired artifacts from the latency of this averaging.
Our initial inclination when faced with N periods is to simply take their arithmetic mean and treat that as the “average” period. The reason why this inclination is incorrect is easy to understand graphically. If we
place these consecutive periods on a time-line we can see that the sum of these N periods is equal to the total length of time that passes between the onset of the first period and the end of the Nth period. So the arithmetic mean amounts to just dividing that time-line into N equal parts and treating those parts as the average period. But this method misses all the information it could potentially make use of in the individual lengths of each period, and consequently misses an opportunity to reduce measurement noise by taking ALL the period measurements into account.
Of course the best way to take all the period measurements into account is using linear regression and fitting a straight line to the collection of N measurements. It turns out there is a convenient way to set up this problem which results in a very elegant result. Let’s consider N consecutive period measurements p0 through pN and
assume that N is an even number (the end result will generalize to odd N as well but the steps would be slightly different). Let’s convert the periods into N+1 times t0 through tN, where time t0 is the onset of the first period measurement, t1 is the end of the first period measurement and onset of the second period measurement, and time tN is the end of the last period measurement. Then let’s subtract an offset from the time so that tN/2= 0. This means that we have: