# Identify a note in a song using Mathematica

I'm trying to figure out how to use Mathematica to identify a note from a song. The short .mp3 file found here or here contains a bass-note that I'd like to identify. I can find it through experimentation with a piano, but I'd like to identify mathematically.

I know little about signal processing. I tried implementing a process shown in Plotting Fourier spectrum versus frequency of a signal, but 1) I don't understand signal processing and 2) the result has a lot of noise as the bass note is surrounded by lots of other sound.

How can I use Mathematica to analyze a short audio clip and identify dominant notes?

• Well, unless you have a clear peak in the Fourier near lower frequencies, you probably can't without clearing up the audio. Do you have a plot of the spectrum? – Feyre Jun 23 '16 at 18:47
• AudioReverb may work as you wish – partida Jun 15 '17 at 7:49

## 1 Answer

In order to facilitate an answer (sound - D Cord):

Import["D_vbr.mp3", "Elements"]
Fs = Import["D_vbr.mp3", "SampleRate"]

data = Import["D_vbr.mp3", "Data"];
{nChannel, nSamples} = Dimensions[data]

Py = Fourier[data[[1, All]]];
nUniquePts = Ceiling[(nSamples + 1)/2];
Py = Py[[Range[1, nUniquePts]]];
Py = 2 (Abs[Py]/nSamples)^2;
Py[] = Py[]/2;
f = (Range[0, nUniquePts - 1] Fs)/nSamples;

spectrum = Transpose[{f, Py}];

ListLogLogPlot[Transpose[{f, Py}], Joined -> True, PlotRange -> All,
PlotLabel -> "Power Spectrum of mp3 file",
AxesLabel -> {"Freq. Hz", "power"}, ImageSize -> 400]

thres = 5*^-10;
peakValue = FindPeaks[spectrum[[All, 2]], 0, 0, thres]
peakFreq = Part[spectrum[[All, 1]], peakValue[[All, 1]]] // N Your MP3 file looks like this: {348.359, 467.031, 700.547, 932.148} Hz

• Periodogram[] can be directly used on Sound[] objects. – J. M. is away Jun 23 '16 at 19:04
• It seemed like Fourier[] and FindPeaks[] needed raw data – Young Jun 23 '16 at 19:20
• Your plots might be easier to interpret if you used a logarithmic scale on the x-axis. You could also consider putting the y-axis in dB. – mikado Jun 23 '16 at 22:56
• I changed to a LogLog scale. @GregH Does this get you going in the right direction? – Young Jun 24 '16 at 17:05