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?

  • $\begingroup$ should the x-axis be logarithmic ? $\endgroup$ – andre314 Mar 27 '17 at 0:36
  • $\begingroup$ @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. $\endgroup$ – Kagaratsch Mar 27 '17 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}]]

View the Spectrogram you can verify it really have three sine waves. enter image description here

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]}]

enter image description here

if you use *.mp3 file:

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

enter image description here

Also do fourier analysis in all audio data.

enter image description here

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]

enter image description here

| improve this answer | |

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.