We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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):
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 doesFFT.spectrum
relate to power?After looking around some more, to convert from magnitude to dB:
20*Math.log10(fft.spectrum[i]))
(edited to add GoToLoop's comment below)
http://docs.Oracle.com/javase/8/docs/api/java/lang/Math.html#log10-double-
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