Question: I'm trying to find out if it's possible to find the beat of a tune by Fourier analysis with Mathematica. I'm taking a 44.1 kHz sample sound and hoping that I might get a nice peak for a frequency somewhere in the window of reasonable bpm (so, 60 to 100 per minute).

```
s = Import["Eleanorrigbylive.wav"];
raw = First@First@First@s;
avg = Table[Mean[Abs /@ raw[[i ;; i + 127]]], {i, 1, Length@raw/128}];
avg = Drop[avg, Floor[Length@avg/10]];

```

So, I'm importing the raw data and storing one channel's samples into `raw`. Because 44.1 kHz is way to much for what I want to do, I downsample it by averaging over blocks of size 128, so `avg` corresponds to samples at 344.5 Hz (which should be enough for my measurement of a 1 to 2 Hz phenomenon). Then, I'm dropping the intro of the song :)

However, Fourier analysis in the expected window is more than disappointing:

```
ListLinePlot[
 MapIndexed[(First@#2)^2*#1 &, FourierDST@avg[[1 ;; 1000]]]]

```

![enter image description here](https://i.stack.imgur.com/BDFxY.png)

Thus, my questions are:

* am I missing some Mathematica functionality which would not require me to do this the hard way?
* is my analysis incorrect? how could I determine the beat of a sound sample?

Answer: 
Here's a possible starting point for a solution. It splits the sample list into chunks and measures the `Norm` of the sample `Differences` in each chunk, and then does the FFT on that data.

```
bpmplot[snd_, bpmmax_: 300] := 
Module[{samples, minfreq, signal, fft},
samples = snd[[1, 1, 1]];
minfreq = snd[[1, 2]]/Length[samples];
signal = (Norm[Differences[#]]) & /@ Partition[samples, 128];
fft = Abs[Fourier[signal][[;; Floor[bpmmax/(120 minfreq)]]]];
fft[[;; 10]] *= 0; (* remove very low frequencies *)
ListLinePlot[MapIndexed[{120 (#2[[1]] - 1) minfreq, #1} &, fft], 
PlotRange -> All, Frame -> True, FrameLabel -> {"BPM", "Signal"}, 
BaseStyle -> {FontFamily -> "Calibri", 20}]];

snd = Import["C:\\Users\\Simon\\Desktop\\02 - Money For Nothing.wav"];

bpmplot[snd]

```

![enter image description here](https://i.stack.imgur.com/YMnuU.png)

Google tells me that the BPM for this track is 134, and you can see that it has picked that frequency out quite well, though there are many other peaks too, especially the harmonic at 268 bpm.
[Sonic Visualiser](http://www.sonicvisualiser.org/) is a point and click interface for all sorts of audio tasks, from analysis, filtering, beat detection, etc. You should play around with it (does take some getting used to) and download the freeware plugins too. 

Once you get the hang of it, you might want to try [Sonic Annotator](http://omras2.org/SonicAnnotator), which is, I believe, just a text based interface to Sonic Visualiser's capabilities. If so desired, you could perhaps construct a Mathematica function that calls Sonic Annotator to do what you want.

Finally, I'm pretty sure the main project and most of the plugins are open source. (So feel free to trudge through it all and post some interesting stuff — implemented in pure Mathematica — back here...)