Go Down

### Topic: Convert voltage to dB (Read 34781 times)previous topic - next topic

#### louisbourdon

##### Jan 04, 2014, 05:28 pm
Hi
I'm looking at this link (http://www.sengpielaudio.com/calculator-gainloss.htm) to get the formula for converting voltage to dB. I use a sound sensor connected to Arduino (0-1024) and I want to convert this to acoustic energy (dB) (for display, etc).

As I understand this, 1024 values (or 0 to 5V) would equal to 60 decibel units, so if I use the formula -> (20*log10)*V/V0, I will get from 0 to 60 - and then I can offset by an amount if I want to match proper settings (i.e. 0 would then equal approximately 20-30 dB).

Does this sound alright?

#### robtillaart

#1
##### Jan 04, 2014, 07:25 pm
yep except that Arduino goes from 0..1023
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### Magician

#2
##### Jan 04, 2014, 08:04 pm
Quote
As I understand this, 1024 values (or 0 to 5V) would equal to 60 decibel units, so if I use the formula -> (20*log10)*V/V0, I will get from 0 to 60
No. Voltage is RMS value in the formula, your range 0-1023 is peak-to-peak. You have to divide by 2 in the first, and than by sqrt(2). 1024 / 2 * sqrt(2) = 362.  Roughly, you can get about 53-54 dB at the best - perfectly centered steady sine wave.  Less than 40 dB for normal audio content.
Options: use ADC with more bits, or averaging.
http://coolarduino.wordpress.com/2013/01/09/audio-vu-meter/

#### louisbourdon

#3
##### Jan 04, 2014, 11:57 pm
I try this code, but it doesn't give correct results. Someone can help to fix the formula?

Code: [Select]
`const int analogInPin = A0;int sensorValue = 0;void setup() {  Serial.begin(9600); }void loop() {  sensorValue = analogRead(analogInPin);              Serial.print("sensor = " );                         Serial.println(sensorValue);        double db = (20. * log(10)) * (sensorValue / 5.);    Serial.print("db = ");  Serial.println(db);      delay(500);                     }`

#### Magician

#4
##### Jan 05, 2014, 12:25 am
Try:
Code: [Select]
`double db =  20.0  * log10 (sensorValue  +1.);`

#### MarkT

#5
##### Jan 05, 2014, 03:34 am

Quote
As I understand this, 1024 values (or 0 to 5V) would equal to 60 decibel units, so if I use the formula -> (20*log10)*V/V0, I will get from 0 to 60
No. Voltage is RMS value in the formula, your range 0-1023 is peak-to-peak. You have to divide by 2 in the first, and than by sqrt(2). 1024 / 2 * sqrt(2) = 362.  Roughly, you can get about 53-54 dB at the best - perfectly centered steady sine wave.  Less than 40 dB for normal audio content.
Options: use ADC with more bits, or averaging.
http://coolarduino.wordpress.com/2013/01/09/audio-vu-meter/

But the smallest signal you can see is 1 count peak-to-peak, not 1 count RMS,
so its 1023 times smaller than the max, ie 60.2dB less.
[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]

#### Magician

#6
##### Jan 05, 2014, 04:34 am
Quote
1 count peak-to-peak, not 1 count RMS,
so its 1023 times smaller than the max, ie 60.2dB less.
I never heard someone would measure DC voltage in dB. For AC there is an offset,  and full span is only 512 , it gets to 6.02 * 9 + 1.76 = 55.94
I agree, that 512 is higher than 362, which I counted in integer math term, and basically isn't always the case

#### louisbourdon

#7
##### Jan 19, 2014, 03:42 pm
So, is there any formula that works to convert the voltage in dB SPL? I have tried many different ways, but I always get false results. There has to be something out there - or if could someone direct me to resources?

Again, I want to convert the voltage in db SPL (sound pressure level), with a minimum value of around 30dB, and a maximum at around 90dB.
Thanks!

#### Magician

#8
##### Jan 20, 2014, 02:01 am
Quote
So, is there any formula that works to convert the voltage in dB SPL?
No, otherwise it has to include mic sensitivity , amplification coef. and arduino reference voltage.  You have to calibrate with a standard device, in special soundproof chamber.

#### juanernesto40

#9
##### Jul 08, 2014, 06:29 pm

maybe can try with this:
double db = 20. * (log10 (soundSensor));

#### KeithRB

#10
##### Jul 08, 2014, 06:35 pm
Is your sensor just a microphone? If so, you cannot just convert any single value to dB, you need to know the amplitude of your signal, and possibly filter it for A-weighting if this is for an SPL meter.

#### louisbourdon

#11
##### Oct 03, 2014, 04:49 pm
After some time I returned to finish this project. So far, still, no answer to make it work as closely as possible to as a dB meter.

I'm reading this article (http://www.inmotion.pt/store/phidgets-sound-sensor) saying that there is a formula that can be used to get the dB conversion (for 1kHz sound for example).

SPL at 1kHz tone (dB) = 16.801 x ln(sensorValue/1023) + 9.872

I tried the formula but I got nothing. I don't know what the ln stands for

Maybe someone could help?

#### KeithRB

#12
##### Oct 03, 2014, 04:53 pm
The *second* hit if you google "ln" tells you it is the natural logarithm. (i.e., base e, not base 10)

#### louisbourdon

#13
##### Oct 03, 2014, 05:23 pm
Sure thing, but how this is implemented in code? Cause this is not working...

double db = 16.801 * log (sensorValue/1023) + 9.872;

#### KeithRB

#14
##### Oct 03, 2014, 06:08 pm
You probably need to cast sensor value to a float so that the division is done in floating point.

Go Up