# Get Y-Axis of FFT in decibels

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: 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? • You've tried ListLogLogPlot? Apr 23 '15 at 0:23
• "By default, Periodogram shows the decibel values of magnitude"
– Kuba
Apr 23 '15 at 6:25

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 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.

• Hmm, I see, I will give this a try later tonight. Apr 23 '15 at 0:51

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 = {#[], 20 Log[10, #[]/myMin]} & /@ myData;

ListPlot[fixedData]

• 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. Apr 23 '15 at 0:40
• I get lots of "Indeterminate" values and things like that. Apr 23 '15 at 0:45