# Getting bpm of song with fft [duplicate]

I would like to get the bpm of a song analyzing the spectrum of the volume. Doing a fft what I get is a peak at the origin and of course that can't be the frequency corresponding to the bpm, so I do the following:

$\overline{h} = h - \frac{1}{l}\sum_0^l h$

where $h$ is the fft of the volume and $l$ is the length of the signal.

Now I expect the bpm frequency to show up in the interval $[1 Hz,3Hz]$ but how can I recognize it?

• This is a rather poor BPM detection method, but on music with a strong rhythm, you should see a peak in the magnitude of the FFT in the range of interest. The mean subtraction you are doing doesn't do anything besides zeroing the first FFT component, so it is not needed. – pichenettes Feb 28 '14 at 17:07

Unless your FFT is very large you're not going to get much resolution in the range of interest since each FFT bin holds Fs/N Hz of spectrum. ( Fs = sample rate, N=FFT size).

I have successfully got very accurate BPM values by using two FFT's in series and then picking the biggest peak in the region of interest in the final averaged spectrum.

IME this works well for signals with a reasonably prominent beat. e.g. typical modern pop & rock music.

• the method won't work anyway. there is a large volume of papers written about beat-onset or BPM detection. – robert bristow-johnson Feb 28 '14 at 18:49
• It works quite well for Tempo Detection, but not at all for beat/onset detection. If you only want the tempo and not the onsets it's quick, easy and effective. – Andy J Buchanan Feb 28 '14 at 19:03
• put in a choral piece or a string ensemble. something without a back-beat. see how well it works with that. – robert bristow-johnson Feb 28 '14 at 19:11
• Of course. I've edited the answer to clarify. – Andy J Buchanan Feb 28 '14 at 19:27

The BPM of only certain limited styles or forms of music or music performance is represented by periodicity in volume. Make sure you are testing with one of those by inspecting a volume vs. time graph.