how to invert log10 to control waveform amplitude with dB value

Status
Not open for further replies.

fred_france

Active member
Hello,

I want to change the amplitude of the waveForm signal from a value in dB.
I know how to transform the level into dB : 20 * log10 (level * 2),
but not the other way around.

example:
6dB => waveform.amplitude(1.0)
-20 dB => waveform.amplitude( ? )


thanks you
 
If using Teensy 4.x and you want the math done entire with fast 32 bit float, then:

exp10f(((float)dB - 6.0f) / 20.0f)

If you're not careful, it's easy to accidentally promote to 64 bit double precision, which is still fast because it's done by the FPU, but not as fast as only 32 bit float.
 
Normally, where 0 dB -> 1.0

exp10(dB / 20)


For 6dB -> 1.0

exp10((dB - 6) / 20)

I don't understand why when I connect the waweform object to the peak object, I get 6dB with an amplitude set to 1.0?
to get the dB, I do:

Code:
wavefom1.amplitude(1.0);
....
while (!peak1.available()) delay(10); 
double dB = 20*log10(peak1.read()*2.0)
 
I corrected the factor of 2, thank you

on the other hand I still can not find the value after convertion:
Code:
float amplitude = 1.0;
float dB =  20*log10(amplitude);
Serial.println(dB);

float invertLog = exp10f(((float)dB - 6.0f) / 20.0f);
Serial.println(invertLog);
=> 0.00
=> 0.50 (I expected to have 1.0)
 
see post #2
now you have to remove the -6.0f
(6db is equivalent to a amplitude factor of 2)
 
Code:
float amplitude = 1.0;
float dB =  20*log10(amplitude);
Serial.println(dB);

float invertLog = exp10f(((float)dB) / 20.0f);
invertLog = invertLog;
Serial.println(invertLog);

that works well ! thank you

(for my understanding, what does the letter f mean after 20.0f)
 
Ok thank you for this info.
I did not know that it was necessary to specify the type of a number on the other hand for a variable it seemed obvious to me
 
Status
Not open for further replies.
Back
Top