Go Down

Topic: Analog read value -> dB (Read 11265 times) previous topic - next topic

Xeyow

Hello guys.

I just bought this mic: https://www.sparkfun.com/products/9964

I connected it the arduino, loaded a simple sketch: "analogRead(0)", i get some values between 0 - 1023. But that`s not the problem. I want to know if there is a mathematical formula that can convert this value (0 - 1023) into dB. I need to get that dB value for a project i`m working on..

Any ideas?

TY

DVDdoug

#1
Apr 27, 2015, 04:48 pm Last Edit: Apr 27, 2015, 04:49 pm by DVDdoug
The bad news is we don't know the sensitivity of the mic.....  That means you need an SPL meter to calibrate the SPL meter you are building!

dB = 20 x log(Vreading/Vreference).   (We don't need the actual voltage since we know the ADC reading is proportional to voltage.)

Here's an example:

You play a test tone set to 80dB SPL on your SPL meter.    You Arduino ADC gets a peak reading of 200.*

Change the volume of the tone and your ADC reads 400.    Now we can calculate the relative dB change:   20 log(400/200) = 6dB.   Add that to our 80dB reference and the sound level is 86dB SPL.

If you read 100 your dB calculation will be -6dB, which would correspond to 74dB SPL.



* Of course that's a totally made-up example.   We have no idea what reading you are going to get at 80dB SPL.

And, since sound is pressure waves that go positive & negative and pass through zero, your readings will "look" random, but they will be constrained within a range and you can pick-out the peaks.

Also, the SparkFun board is biased at 2.5V, which means it should read about 512 with silence.    You need to subtract the bias from your readings...   A signal level that peaks at +200 and -200 will read between 312 and 712.



Note:  It's not easy to make a "proper" SPL meter.    Technically, you should be using RMS instead of peak level and you generally "weight" the readings due to the ear's different sensitivity at different frequencies.    But, you can make something that works reasonably well for casual (non-scientific or non-regulatory) use.

CommonRodent

#2
Apr 28, 2015, 03:24 am Last Edit: Apr 28, 2015, 03:26 am by CommonRodent
To further that it might be possible to estimate the sensitivity from the datasheet - but it wont be accurate unless you calibrate it.

The microphone is -46dB (V/Pa)
The op-amp stage gain is stated as 100, which is +40dB
This gives a system sensitivity of: -46+40 = -6dB

This means an input of 100dB,2Pa (amplitude) should produce +-1V (approximately +-200 read from the ADC)

But the readings are biased around approx 2.5V, which is the means you need to subtract this value to find the amplitude. You could first measure the reading for no sound input to get the average, but if this drifts your small signal measurements will be distorted.

If you have the instantaneous ADC reading: adc_reading
The bias_level should be around 480 - 530, as measured when there is no sound input
Code: [Select]

adc_ac = adc_reading - bias_level
volts = (5.0 / 1024.0) * adc_ac
volts_db(peak) = -20.0 * log10(volts)
spl_db(peak) = volts_db + 6


But as DVDdoug said, the SPL for a single sample will vary, the better solution is to find the RMS over a period of time

Code: [Select]

for i in 1 to 100
     capture_ac = adc_reading - bias_level
     sumSquare += capture_ac * capture_ac

rms = sqrt(sumSquare / 100)

JD90

The microphone is -46dB (V/Pa)
The op-amp stage gain is stated as 100, which is +40dB
This gives a system sensitivity of: -46+40 = -6dB


Hey folks,

I bought a SparkFun Electret Microphone Breakout BOB-12758, it's the updated version of the BOB-9964. The op-amp stage gain is now 60 and not 100. What does it mean for dB? Is it now +24dB?

I couldn't find anything in the data sheet.

Thanks!

DVDdoug

#4
Nov 07, 2016, 11:47 pm Last Edit: Nov 08, 2016, 12:06 am by DVDdoug
Quote
stage gain is now 60 and not 100. What does it mean for dB? Is it now +24dB?
A gain of 100 is +40dB =  20 x log(100)
A gain of 60 is +35.56dB

So with a gain of 60 your readings will be 4.44dB lower.   (For the same result, add 4.44dB.)

And, I still recommend you check your calibration with a real SPL meter.   (But even if you calibrate it, it won't work like a "real" SPL meter unless you are able to design-in the proper averaging & frequency-weighting...  You are making something that gives you a general indication of loudness, or you are making an "effect" or a "toy".)

JD90

#5
Nov 10, 2016, 11:45 am Last Edit: Nov 10, 2016, 12:16 pm by JD90
Thanks Doug!

Yes, I actually need just a general indication of loudness. No scientific device. But why I get 4.44dB lower?

The microphone is still -46dB (V/Pa)
The op-amp stage gain is stated as 60, which is +35.56dB
This gives a system sensitivity of: -46+35.5dB = -11dB

And therefore I thought that the readings are approx -11dB lower?

I will see whether I can find a SPL Meter. I've read some of your posts, but still not sure I got it or not.

For example: I measure a value of 300 at 40dB and a value 500 at 60dB, so whats the connection between those measurements. How can I put this into a formula?


Edit1:
I thought about this:

Code: [Select]

adc_ac = adc_reading - bias_level
volts = (5.0 / 1024.0) * adc_ac
volts_db(peak) = -20.0 * log10(volts)
spl_db(peak) = volts_db + 6



Edit2:

I found a db_meter_library at github. https://github.com/enen/db_meter_library

There is a comment that says "Please, calibrate analog sensor with an external "real" SPL meter and set apropiate ADC_SOUND_REF & DB_SOUND_REF values."

So I grab a SPL Meter, and measure for example a value of 300 at 40dB. Put the 300 as a an ADC_SOUND_REF and the 40dB as DB_SOUND_REF and in the best case I would get some dB values for other ADC values?


Thank you a lot!

Go Up