BPM Counting: Measuring the Tempo of a Song


BPM = Beats/Minute

Beats per minute are defined as the number of beats (bass drums) encountered per minute. There are a lot of BPM measure programs at hand, (either automatic or semi-auto -matic). In any case, they're not good. Trying to match two songs with the same BPM, as reported by these programs, is impossible. The reason therefore is that BPM's can be an unbelievable inaccurate way of measuring the tempo of music.


How accurate should we measure the BPM's ?

How accurate should we measure the BPM's ? This of course depends on how long you want to play two songs over each other. Let's say that we need 20 seconds to switch and 10 seconds for 'matching' the beats. So, over 30 seconds we don't want any audible tempo-shifts. In the upcoming discussion: time 0, measure 0, is always the moment at which you finally got two beats on top of each other. If we have a small error epsilon in the BPM measurement in both songs we have with every measure a possible difference of 2*epsilon. This error becomes larger with every beat, so after n beats we have a total error of 2*n*epsilon. Assume, we have a song of x BPM's. People recognize 1/64 notes. So the maximum tempo shift can only be 1/16 beat (at x BPM). Over 30 seconds we have x/2 beats, this means that we only have a mismatch of
epsilon = (1/16 beat at x BPM) over (x/2)
Expressed in milliseconds this is
x beat/1min = x beat/60sec = x beat/60000 msec ~ 60000 msec/x beat
The period for one beat is p=60000msec/x; 1/16 beat takes 3750/x msec. Hence, epsilon = 7500msec/x*x
120 BPM 7500 / 14400 = 0.52  ms
130 BPM 7500 / 16900 = 0.44  ms
140 BPM 7500 / 19600 =  0.38 ms
150 BPM 7500 / 22500 =  0.33  ms
160 BPM 7500 / 25600 =  0.29  ms
These values are very small. If we want these errors we need to measure the BPM with an accuracy of 0.0625 BPM. This is very small. Translated to some more understandable language:
  • If you measure raw BPM's to 1 BPM accurate, two songs will stay synchronized during  1.875", practically this is useless, since this is barely a measure.
  • If you measure BPM's to  0.1  accurate, two songs will stay synchronized during  18.75", still requires some nudging.
  • If you measure BPM's to  0.05  accurate, two songs will stay synchronized during  37.5", normally you don't have to nudge with this since song A is removed before song B is going out of sync.
  • If you measure BPM's to  0.01  accurate, two songs will stay synchronized during  3', 7.5", an accuracy where you don't have to nudge anymore :)
  • Of course, now we can conclude that measuring BPM's up to this tempo solves all our problems. This is not true, when measuring BPM's to 0.05 or even 0.01 accurate, we will encounter some technical problems.
  • Some music has a changing rhythm.
  • Not all music is accurate to 0.05 BPM, even if it is the intention.
  • We will now go into details of measuring beats per minute. The first technique is 'tapping the beat'

    Tapping the Beat

    This technique is a semi-automatic technique where a listener hits the space-bar every time a beat sounds. The program marks the start time, the stop time and counts the number of total beats.

    Most synthesizers have a 'tap' button, where you can tap three times and the synthesizer will synchronize to this tempo. This form of measurement is unbelievable inaccurate. I really wonder why they add stupid useless features like this. Let's assume that the human latency is small to 200 ms. The first beat is marked on time T0. The moment at which the user hits 'tap' is T0 +/- epsilon, where 0 < epsilon < 200 msec. The second third second and third tap will be more accurate since it is a sequence. Lets say we have an error of 50 ms at the last tap. The third beat is placed at time T1+/- gamma, where 0< gamma < 50msec. The largest error which can occur is thus 250 msec for two beats. For one beat this is 125 msec. Now assume, we're matching a 138BPM song. The period of a beat = 434.8 ms. The period we will measure lies between 309.8 and 559.8. Translated to BPM's this is between 193.7 BPM and 107.2BPM. We have an estimated accuracy of 86.5 BPM. Bwaargh.. In practice it's a bit better, lets say, an accuracy of 10 BPM. So, lets forget these 3-tap buttons because they simply do not work.

    Let's look at another branch of programs. Programs in which you hit beat after beat. With every beat the accuracy becomes better. Let's do an estimation as above. The total error is reduced by half to 125 msec. (so, the user has a latency of only 100 ms, which is less). Let's say we are working at x BPM. The period of a beat at this tempo is p=60000 msec/x. If we have tapped n times, we have a total time of n*p. If we add the error we get n*p +/-  125msec. Per beat this error is 125/n. Switching back to BPM's gives x=60000msec / (p +/- (125/n) msec). The table below shows how accurate we can get with such a tool. The results are not even close to the required results. An extra disadvantage of this method are jumps in the stream. If there is a gap in the data flow (scratch on the CD or break in the music) the measurement will be even more inaccurate.
     

    x BPM
    n-1 taps min max accuracy
    120 
    10 
    117
    123
    6
    120 
    50 
    119
    121
    1.2
    120
    100 
    119.7
    120.3
    0.6
    130 
    100 
    129.6 
    130.4 
    0.7
    140 
    100 
    139.6 
    140.4 
    0.82
    150 
    100 
    149.5
    150.5 
    0.94
    160 
    100
    159.5
    160.5 
    1.06
    150 
    150 
    149.7
    150.3 
    0.63
    150 
    200 
    149.8
    150.2 
    0.47
    150 
    250
    149.8
    150.2 
    0.38

    Marking the Beat

     
    A possibility to measure BPM's more accurately is pointing out a start & stop beat in a sample. In these kind of programs the sample-data is shown on the screen. The user can scroll trough the song and place start & stop markers at the beginning of phrases (8 measures). After this is done the program shows other markers at 8-measure (and eventually 4) positions. If these are correct the BPM's can be calculated. This method is very accurate, if  the user has some accuracy of course. The disadvantage of this method are the difficulties with gaps in the music.

    Filtering the Beat

     
    Automatic BPM Counting programs are programs which do a fast Fourier transform (FFT) upon the input signal and try to develop a peak response to the lower frequencies (eventually with a trained neural net). The problem with these automatic programs is that the are never free and don't work too well.
    The first person offering me a GPL-ed and good working BPM finder which uses only an FFT with peak detector will be mentioned.
    A major disadvantage of these programs is their complete lack of feeling for bass drums. If a fill in occurs these programs often fail. If there is a break in which there is no bass drum, they fail, and so on.. Most of the time they are not even remotely correct. An extra problem with them is their lack of accuracy. If they use a 256 sample buffer they place a beat somewhere in a time slice of 5.8 ms. Which is at least 10 times larger than the accuracy we need. My opinion (which a lot of people wont like) about these programs is that they are inaccurate, and have a very low result to no-result ratio.

    Phase Shifting the Beat

    A much much better technique I invented is based upon phase shifting the music. With this technique we take the complete sample and shift it 4 beats over itself at 120BPM. Afterwards we shift it over 4 beats at 120.01BPM, and so on until we reach 160BPM. With every shift we measure the difference between the shift and the original. The absolute differences over the whole sample are added and stored. At the end of the process we have a list of BPM's and how well a phase-shift at this tempo matches the song itself (autocorrelates), as can be seen in the figure above. Some technicalities for people who want to implement this:
  • Reduce two channels to 1 channel
  • Reduce 16 bits to 8 bits
  • Remove the sign of the resulting byte.
  • The advantages of this technique are
  • Correct in 95% of the songs.
  • Works fully automatically, absolutely no human interaction required.
  • Works even in passages where there is no bass drum
  • An accuracy of 0.02 ms which is 10 times more accurate than required.
  • Can handle gaps and jumps in the music very well !!!
  • Tempo changes at the beginning or the end of the music will be neglected.
  • The disadvantage of this technique is  that the algorithm cannot say  where  a bass drum is placed.

    Copyright (c) Werner Van Belle December 2001
    e-mail: werner.van.belle@vub.ac.be
    Tel: +32 486 68 84 48; Fax: +32 2 629 35 25
    http://bpmdj.sourceforge.net/