1
$\begingroup$

I am trying to make a plot of a sound file similar to Audacity's FFT plot which looks like this when the x-axis is on a log scale:

Audacity FFT

My plot of the same sound file (below) has the problem that the units are in absolute amplitude, not decibels. How can I fix this?

fft2

$\endgroup$
  • 1
    $\begingroup$ You've tried ListLogLogPlot? $\endgroup$ – Mr.Wizard Apr 23 '15 at 0:23
  • 1
    $\begingroup$ "By default, Periodogram shows the decibel values of magnitude" $\endgroup$ – Kuba Apr 23 '15 at 6:25
5
$\begingroup$

decibel is a relative unit. I'm pretty sure there is no implied standard reference in audio processing, (it looks like audiologists have a few go-to's e.g. dB HL, but I don't know what Audacity does). That said, you need a reference value. Since you're looking at FFT's the total power might be a good choice. Then decibels will tell you how strong a particular frequency is relative to the signal.

signal = RandomReal[{0,1},1000];(*A random signal*)
fft    = signal//Fourier//Abs;
fft    = fft[[1;;Ceiling[Length@signal/2]]]; (*Since we're looking at power only take the first N/2 points.*)
fftPowerRef = Total[fft^2]; (* Power is amplitude squared. *)
inDecibels = 10*Log[10, fft^2/fftPowerRef ];

In this case you will always have <0dB since a pure tone would concentrate all the power at one fft sample, and you'd be taking Log[10,1]

If you do the same thing with a signal like signal = Sin[2*pi*#/200]&/@Range[1000] you should see one main peak with most of the power.


Alternate Reference Power

Using the total power as a reference means that from song to song a value of -10dB won't have much meaning except to give you the relative strength of a particular tone in that data set. You could calibrate your plots by always referencing the same power, for example the power in pure sine wave played at some particular volume, to make the axis meaningful from sample to sample.

You could also get crazy and take the FFT power of a wave that fully utilizes the dynamic range of a particular digitizer. You can reference relative to RMS power, or peak power, etc. etc. etc. It really depends on what your end goal is.

$\endgroup$
  • $\begingroup$ Hmm, I see, I will give this a try later tonight. $\endgroup$ – Tyler Durden Apr 23 '15 at 0:51
0
$\begingroup$

Take your $y$ values (in a list myData) and convert them by the definition for decibels:

20 Log[10, #/Min[myData]] & /@ myData

If your data is in the form of {{t1, v1}, {t2, v2}, ...} then in a simple (but inefficient) method:

myData = {{3, 6}, {4, 8}, {5, 2}};

myMin = Min[myData[[All, 2]]];

fixedData = {#[[1]], 20 Log[10, #[[2]]/myMin]} & /@ myData;

ListPlot[fixedData]
$\endgroup$
  • $\begingroup$ It is not really clear how this expression is to be used. If I insert it into the expression shown in the question errors result. $\endgroup$ – Tyler Durden Apr 23 '15 at 0:40
  • $\begingroup$ I get lots of "Indeterminate" values and things like that. $\endgroup$ – Tyler Durden Apr 23 '15 at 0:45

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.