# Frequency decomposition of an mp3 file?

After loading an mp3 file

test = Import["test.mp3"]


I would like to make a plot with x-axis being the frequency of waveforms contained in test, and y-axis being the average amplitude of the respective frequency throughout the mp3 duration. Can I use Mathematica to do that?

• should the x-axis be logarithmic ? Mar 27, 2017 at 0:36
• @andre I am mostly interested in voice frequencies, 300 - 3600 Hz, so logarithmic might be a bit crammed. But any solution would do, I would adjust the axes later. Mar 27, 2017 at 0:41

Assuming we have three sine waves:

audio = Audio[Array[0.2*Sin[2 \[Pi] 3000 #] + 0.5*Sin[2 \[Pi] 5000 #] + 0.1 Sin[2 \[Pi] 7000 #] &, 44100, {0, 1}]]
Spectrogram@audio


View the Spectrogram you can verify it really have three sine waves.

SpectrogramArray[audio] do the same thing,the row is represent time,the column is represent frequency.

ListLogPlot[#[[;; Round[Length@#/2]]] &@Total@Abs@SpectrogramArray[audio], PlotRange -> All, Joined -> True,DataRange -> {0,QuantityMagnitude[AudioSampleRate@audio/2]}]


if you use *.mp3 file:

audio = Import["ExampleData/car.mp3"];
Spectrogram@audio
ListLogPlot[#[[;; Round[Length@#/2]]] &@Total@Abs@SpectrogramArray[audio], PlotRange -> All, Joined -> True, DataRange -> {0,QuantityMagnitude[AudioSampleRate@audio/2]}]


Also do fourier analysis in all audio data.

Periodogram[Flatten@AudioData[audio], 1024, 1024, BlackmanHarrisWindow,
SampleRate -> QuantityMagnitude@AudioSampleRate[audio],
Ticks -> {Range[0, 22000, 1000], Range[0, -160, -20]},
TicksStyle -> Italic, AspectRatio -> 1/3,
AxesLabel -> {"Hz", "dB"}, ImageSize -> 900,
Background -> Black, PlotStyle -> Green,
AxesStyle -> White, PlotRange -> All]