I want to do a DFT of a fragment of music,and then plot the magnitude with dB instead of amplitude. For example:
music = ExampleData[{"Sound", "Violin"}];
data = music[[1, 1, 1]];
data = data[[22050*2 ;; 22050*2 + 1024 - 1]];(*length of data:1024*)
maxofdata = data // Abs // Max;
data = data/maxofdata;(*normalize the data*)
ListLinePlot[data, AspectRatio -> 1/8, PlotStyle -> Thick]
xdb = Fourier[data, FourierParameters -> {1, -1}][[;; 512]] // (20 Log10[Abs@#]) &;
xdbMax = Max@xdb;
xdbn = xdb - xdbMax;
xdbn // ListLinePlot[#, Filling -> Axis, FillingStyle -> Purple, DataRange -> {0, 22050/2}, AspectRatio -> 1/3] &
But If I export the fragment of music into Audacity,and then get this plot. You can see the two plot are similar,but a little different on vertical axis. So how to correct my code to get the same result?
And when doing the DFT,I use the Rectangular window. However in order to make the spectrum more smooth,I want to use other window function,How to do it?