0

I am developing lumiere application. I have a carrier signal of certain frequency (19.2 kHz if to be more precise) and I need to get the amplitude of it while the audio is being played. I have googled some info on audio processing and found out that in order to get frequency spectrum you have to use FFT algorithm.

I have tried TarsosDSP library and its FFT class.

TarsosDSPAudioFormat format = new TarsosDSPAudioFormat((float) SAMPLE_RATE, 16, 1, true, false);
TarsosDSPAudioFloatConverter converter = TarsosDSPAudioFloatConverter.getConverter(format);

float[] buff = new float[bufferFloatSize];
final float[] amps = new float[fftSize];

converter.toFloatArray(tmpBuffer, buff);

FFT fft = new FFT(bufferFloatSize, new HannWindow());
fft.forwardTransform(buff);
fft.modulus(buff, amps);

Then I get frequency band index and calculate its amplitude

int amp = (int) (10 * Math.log10(amps[index]);

But I get wrong amplitude. I have an audio file with 19.2kHz signal that has constant amplitude of 0 dB but the result value of 19207 Hz amplitude varies from -39 dB to -46 dB. I checked neighboring frequencies, may be some of them have 0 dBs, but no. I also checked files with -36 dB and -60 dB but the results were -39 to -48 dB and -44 to - 61 dB respectively.

As we can see for the last file it is close, but it is not constant and I can't predict when it's right and when it's wrong.

If there is anybody who faced this issue, please help me. If you know any other good FFT lib that is workable for sure - tell me

UPDATE: Ok, I have added TSG's function and call it before my fft.forwardTransform() and after to compare the results; The results were: for 0 dB 19.2kHz audio file: before: -39 dB after - 10 dB

for -36 dB 19.2kHz audio file: before: -75 dB after: -46 dB

for -60 dB 19.2kHz audio file: before: -97.7 dB after: -69 dB

Now the results are constant and don't change with time or try. We also can see that there is a certain pattern in the results. Before fft the result differs from the right one for -39 dBs and after for -10dBs. So the question is: why are we having these mistakes?

1 Answers1

0
    In the TarsosDSP manual , the following example was given sound pressure level in db  where  ,

 db=audioEvent.getdBSPL(); or Amplitude=audioEvent.getRMS() //root mean square of the signal.



    float[] buffer = audioEvent.getFloatBuffer();



    private double soundPressureLevel(final float[] buffer) {
    double power = 0.0D;
    for (float element : buffer) {
    power += element*element;
    }

    double value = Math.pow(power, 0.5)/ buffer.length;;
    return 20.0*Math.log10(value);
    }
    });
  • Could you explain please, why do multiply by 20 in 20.0*Math.log10(value); Because I've seen the same expression multiplied by ten: 10 * Math.log10(value); – Andrey Prokhorenko Feb 14 '17 at 11:30
  • the results for your function on 0 dB 19.2kHz audio file are -39 dB before calling FFT and -10 dB after calling FFT. Log.d("test", "before power level: " + soundPressureLevel(buff) + " dB"); fft.forwardTransform(buff); fft.modulus(buff, amps); Log.d("test", "after power level: " + soundPressureLevel(buff) + " dB"); – Andrey Prokhorenko Feb 14 '17 at 11:35
  • I have also checked that all three files have the same results all the time, what is better, as we have constant values (no variation like before) and the difference between the right result and wrong is approximately 39 dBs(result before fft). Like it should 0 dB and it is -39dB, it should be -36 dB and it is -75dB, it should be -60 dB and it is -98 dB. – Andrey Prokhorenko Feb 14 '17 at 11:38
  • As I know the FFT used by TarsosDSp is JTransforms. – TSG anti SO dark forces Feb 15 '17 at 01:16
  • Formula from TarsosDSP manual , audioEvent.getdBSPL() call exactly match the sound pressure function exhibit generally known as Sound Pressure Level. SPL=20Log10(P(rms) /P0) where P0 is a constant = 2e-5. ,P is rms of acoustic pressure fluctuations your formula apply is known as PWL or sound power level , unit is also dB. Both are actually the same , it is a relative measurement with reference to a common base , In the case of power , base is intensity level 10E-12 W/M2 , Intensity = P sq (rms) divide by pc(densityx sound speed ) pc constant=4e2 kg/m2s for air under atmospheric conditions – TSG anti SO dark forces Feb 15 '17 at 07:05