woheller69 / audio-analyzer-for-android

A fork of audio-analyzer-for-android in Google code, with a lot of enhancement.
Apache License 2.0
197 stars 13 forks source link

Please tell me which formula is used in this paragraph #20

Closed Pannarrow closed 9 months ago

Pannarrow commented 9 months ago

This code is in "STFT.java", "spectrumAmpOutDB[i] = 10.0 log10(spectrumAmpOut[i]);". I found the dbfs formula "20.0 log10(sample/65535)", Why do we use 10.0

woheller69 commented 9 months ago

Good point, I have not written that part of the code. Maybe @bewantbe can explain?

woheller69 commented 9 months ago

As far as I understand, the code is calculating the power spectrum (squared magnitudes of complex amplitudes).

Therefore the factor of 10 used in the line:

spectrumAmpOutDB[i] = 10.0 * log10(spectrumAmpOut[i]);

is appropriate. This line converts the power spectrum values to decibels. The factor of 10 is commonly used when calculating decibels for power, and it aligns with the standard practice in audio signal processing.

Pannarrow commented 9 months ago

Don't we end up with dbfs?

woheller69 commented 9 months ago

Yes, I think so

Pannarrow commented 9 months ago

thank you very match!

bewantbe commented 8 months ago

Apologize for the late response.

spectrumAmpOutDB[i] = 10.0 * log10(spectrumAmpOut[i]);

The code here is calculating DB of the amplitude (Amp) of the "spectrum". The power spectrum, or more precisely Spectral density, is already the square of the wave amplitude, this calculation can be seem in function fftToAmp.

Pannarrow commented 8 months ago

对于迟到的回复,我们深表歉意。

spectrumAmpOutDB[i] = 10.0 * log10(spectrumAmpOut[i]);

这里的代码是计算“频谱”振幅()的DB。功率谱,或者更准确地说是光谱密度,已经是波幅的平方,这个计算似乎是函数Amp

Why do I get dbfs less than -96

bewantbe commented 8 months ago

Why do I get dbfs less than -96

The overall "DBFS" should not less that -96dB in general, although specially crafted data could break it, e.g. RMS([1, -1, 1, -1, ...]/2^16) = -96.33dB; RMS([1, 0, -1, 0, ...]/2^16) = -99.3dB).

In your case, I believe you are referring to DBFS in the spectrum. The level of the spectrum can be lower than -96dB because -96dB only limits the sum of the energy across all frequencies in the spectrum.

Say, FFT length is 1024, then for -96dB white noise, the spectrum level should be around -96dB + 10*log10(1/1024) = -126 dB.