# Convert Digital and Analog values to dB SPL

I am trying to create a sound level meter. I want to use an analog MEMS microphone (INMP510) and a digital microphone with I2S output (SPH0645LM4H). The sensitivity of the INMP510 is -38 dBV and for SPH0645LM4H is -26 dBFS. I am using a PIC32MZ2048EFG100. The ADC module has 12 bits and the voltage for the ADC are 0 and 3.3 V.

I have read this post (How to convert Volts in dB SPL) but I can't find the specifications of the gain of the analog microphone, so I don't know if I am correctly calculating the dB SPL.

Also for the digital microphone, I have no idea how to convert the digital values to dB SPL.

Can somebody help me with mathematical formulas?

• Well, you could always measure a few known sources and characterise your microphone that way. – Hearth May 1 '17 at 16:48

The INMP510 microphone sensitivity is -38 dBV with a sound pressure level of 94 dB at 1 kHz. -38 dBV is 12.6 mV RMS. So if you measure 12.6 mV RMS then your SPL is 94 dB. If you measured twice that voltage then your SPL will be 6 dB higher. If you measured half the voltage your SPL would be 6 dB lower.

Do you know how the decibel works with rising and falling signals?

For the digital microphone, it has a specification of -26 dBFS for the same 94 dB SPL. FS refers to full scale and full scale appears to be 18 bits if you read the small print. So the RMS value it would produce is 26 dB down on a full scale of 18 bits but remember this is likely to be peak to peak. In other words a full scale signal would be +/- 131072 counts.

So, what do you do with the stream of digital numbers after conversion? First you subtract the midpoint because that is the mean numerical value and represents a large dc offset that ruins the calculation. So now you are dealing in signed integers. To calculate RMS (because that's what you need to do), square each value, accumulate many values then divide by the number of values you accumulated. Finally take the square root and that gives you RMS.

However, make sure you accumulate enough samples or there will be an error term. The alternative is to try and be clever and calculate just as many samples as you need to cover one period of the sound source frequency.

Take note - once you have signed integers, the sign becomes unimportant because of the operation of squaring.

Can you take it from here?

• Sorry but I don´t understand it very well. For example if my analog microphone after the conversion gives a digital value of 2048 (the ADC has 12 bits so it has to be 0-4096). I converted to Analog again ((3.3-0/2^12)*2048= 1.65 V). This value is 1.65/0.0126 = 131 times bigger than 0.0126 so it would be 131*6 +94 dB SPL? That can´t be possible. And for the digital one I don´t understand your explanation. The digital output will be 0-262144 (0-2^18) so I have to substract 131072 to the digital value and then how I convert them to dB SPL. Do I need to take more than 1 value to calculate the SPL? – Sergio Riezu May 2 '17 at 10:28
• Your microphone produces a digital series of values that represent the analogue pressure changes on the diaphragm of the microphone - it doesn't produce DC values unless there is no sound present. You have to do a load of calculations and number crunching to get digital numbers into an RMS value OR you could just detect the peak value and assume that this represents the RMS via some fixed factor but that is prone to massive error given the nature of sound. – Andy aka May 2 '17 at 10:46
• Ok sorry I don´t know how to delete the answer. And there is no fromula to convert the values. Sorry but it is my first time working with audio and I don´t know how to interpret the outputs of the microphones. – Sergio Riezu May 2 '17 at 12:08
• Come back when you are able to grasp the nature of the signal that an analogue microphone produces when stimulated with audio. Then take that one step further to the digital realm. – Andy aka May 2 '17 at 12:12