4
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – Feyre Jun 23 '16 at 18:47
  • $\begingroup$ AudioReverb may work as you wish $\endgroup$ – partida Jun 15 '17 at 7:49
6
$\begingroup$

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[[1]] = Py[[1]]/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

enter image description here

Your MP3 file looks like this:

enter image description here

{348.359, 467.031, 700.547, 932.148} Hz

$\endgroup$
  • 1
    $\begingroup$ Periodogram[] can be directly used on Sound[] objects. $\endgroup$ – J. M. is away Jun 23 '16 at 19:04
  • $\begingroup$ It seemed like Fourier[] and FindPeaks[] needed raw data $\endgroup$ – Young Jun 23 '16 at 19:20
  • $\begingroup$ 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. $\endgroup$ – mikado Jun 23 '16 at 22:56
  • $\begingroup$ I changed to a LogLog scale. @GregH Does this get you going in the right direction? $\endgroup$ – Young Jun 24 '16 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.