# Finding the strongest beat in a sound wave using autocorrelation

by wildetudor
Tags: autocorrelation, beat, sound, strongest, wave
 P: 22 Hi everyone, I have a sound wave representing a piano piece played at a steady tempo, and would like to get a graph of the saliency of each beat (essentially, a probability distribution for how strong each possible tempo is). I understand that this is done by plotting the autocorrelation function, however I don't quite understand why a graph of r coefficients against each possible lag value (which is, as far as I understand, the deffinition of an autocorrelogram) would have anything to do with beats. The following Matlab code produces a graph that doesn't in any way suggest anything to do with the actual steady beat of the piece (60 BPM): [y,Fs] = wavread('d:\bach.wav'); [r,lags]=xcorr(y,'coeff'); plot(lags,r) Clearly I'm understanding autocorrelation wrongly. For instance, in this very simple example, the frequency of the sine hidden in noise is nowhere visible from the autocorrelation graph - or is it? Furthermore, that frequency would actually be the pitch of the sound, and not any rhythm-related measure! The MIR toolbox for Matlab has a function specifically for finding the tempo of a waveform - however what I'm after now is understanding these things at a theoretical level. Anticipated thanks for any clarifications!!
Mentor
P: 9,588
 Quote by wildetudor For instance, in this very simple example, the frequency of the sine hidden in noise is nowhere visible from the autocorrelation graph - or is it?
You can see a clear sine wave in the autocorrelation function, which corresponds to a "hidden" sine wave in the original function with a period of ~10.

 Furthermore, that frequency would actually be the pitch of the sound, and not any rhythm-related measure!
Can you find the time steps where the frequency in the signal changes? An autocorrelation of that should help.
Alternatively, search for steps in the autocorrelation function, this could help as well.
 PF Patron Sci Advisor P: 10,047 Problem with music is that it can be very subtle. However, to find an 'obvious beat', why not find the short term RMS values (Energy with time) of a long passage and FFT that to find low frequency (sub Hz) energy variations. Some pre-filtering could identify components like cymbal strikes or bass drum beats. (Sound to light 'disco' boxes do this quite well)
P: 22

## Finding the strongest beat in a sound wave using autocorrelation

Thanks for your replies! I'm afraid I still don't fully understand, though, the link between a time signal's (waveform's) periodicity and its autocorrelation function; and, I could also add, the link between the signal's autocorrelation function and its Fourier transform (the latter of which I understand how it relates to pitch but not to rhythm)
PF Patron