Converting FFT Amplitude to dB/Hz

edited June 2016 in Library Questions

Hello, I'm trying to use the Sound library to create a spectrogram. I looked at the FFTSpectrogram example that comes in the library. My goal is to create a spectrogram that looks similar to the output from MATLAB's spectrogram function (image below):

laurance

The whole spectrogram is generated in one image, it is not dynamic with the current audio. The y-axis is frequency (Hz), the x-axis is time (s), and the color axis is Power/frequency (dB/Hz). The FFT class has a spectrum object, but I'm not sure how to convert that value to dB/Hz.

Answers

  • Maybe it is possible...
    My best idea would be to create a two dimensional array and add the values to it. The after some specified time, create the graph, save it and exit.

  • Yes, that's for generating a static spectrogram from an entire file. In that case, the bands of frequency ranges will be on the y-axis, but I'm still not sure how to figure out the color for each value, which is in units of dB/Hz.

  • As I understand, the color is related to power which would be dB and not dB/Hz unless you are trying to do something else. Do you have a working sample that you could post?

    Kf

  • Currently I'm just using Example 5 from the Sound Tutorial. After calling FFT.analyze(), how does FFT.spectrum relate to power?

  • edited June 2016

    After looking around some more, to convert from magnitude to dB:

    20*Math.log10(fft.spectrum[i]))

    (edited to add GoToLoop's comment below)

  • You need to make sure the return for the fft is not negative and non-zero. In the case that the fft returns a complex value, you might need to take the absolute value. In matlab would be

    abs(fft(function_fx))

    I hope this helps,

    Kf

Sign In or Register to comment.