How can I calculate audio dB level?

AudioSignal Processing

Audio Problem Overview


I want to calculate room noise level with the computer's microphone. I record noise as an audio file, but how can I calculate the noise dB level?

I don't know how to start!

Audio Solutions


Solution 1 - Audio

All the previous answers are correct if you want a technically accurate or scientifically valuable answer. But if you just want a general estimation of comparative loudness, like if you want to check whether the dog is barking or whether a baby is crying and you want to specify the threshold in dB, then it's a relatively simple calculation.

Many wave-file editors have a vertical scale in decibels. There is no calibration or reference measurements, just a simple calculation:

dB = 20 * log10(amplitude)

The amplitude in this case is expressed as a number between 0 and 1, where 1 represents the maximum amplitude in the sound file. For example, if you have a 16 bit sound file, the amplitude can go as high as 32767. So you just divide the sample by 32767. (We work with absolute values, positive numbers only.) So if you have a wave that peaks at 14731, then:

amplitude = 14731 / 32767
          = 0.44

dB = 20 * log10(0.44)
   = -7.13


But there are very important things to consider, specifically the answers given by the others.

  1. As Jörg W Mittag says, dB is a relative measurement. Since we don't have calibrations and references, this measurement is only relative to itself. And by that I mean that you will be able to see that the sound in the sound file at this point is 3 dB louder than at that point, or that this spike is 5 decibels louder than the background. But you cannot know how loud it is in real life, not without the calibrations that the others are referring to.

  2. This was also mentioned by PaulR and user545125: Because you're evaluating according to a recorded sound, you are only measuring the sound at the specific location where the microphone is, biased to the direction the microphone is pointing, and filtered by the frequency response of your hardware. A few feet away, a human listening with human ears will get a totally different sound level and different frequencies.

  3. Without calibrated hardware, you cannot say that the sound is 60dB or 89dB or whatever. All that this calculation can give you is how the peaks in the sound file compares to other peaks in the same sound file.

If this is all you want, then it's fine, but if you want to do something serious, like determine whether the noise level in a factory is safe for workers, then listen to Paul, user545125 and Jörg.

Solution 2 - Audio

You do need reference hardware (i.e., a reference mic) to calculate noise level (dB SPL, or sound pressure level). One thing Radio Shack sells is a $50 dB SPL meter. If you're doing scientific calculations, I wouldn't use it. But if the goal is to get a general idea of a weighted measurement (dBA or dBC) of the sound pressure in a given environment, then it might be useful. As a sound engineer, I use mine all the time to see how much sound volume I'm generating while I mix. It's usually accurate to within 2 dB.

That's my answer. The rest is FYI stuff.

Jorg is correct that dB SPL is a relative measurement. All decibel measurements are. But you've implied a reference of 0 dB SPL, or 20 micropascals, scientifically agreed to be the most quiet sound a human ear can detect (though, understandably, what a person can actually hear is very difficult to determine). This, according to Wikipedia, is about the sound of a flying mosquito from about 10 feet away (http://en.wikipedia.org/wiki/Decibel).

By assuming you don't understand decibels, I think Jorg is just trying to out-geek you. He clearly didn't give you a practical answer. :-)

Unweighted measurements (dB, instead of dBA or dBC) are rarely used, because most sound pressure is not detected by the human ear. In a given office environment, there is usually 80-100 dB SPL (sound pressure level). To give you an idea of exactly how much is not heard, in the U.S., occupational regulations limit noise exposure to 80 dBA for a given 8-hour work shift (80 dBA is about the background noise level of your average downtown street - difficult, but not impossible to talk over). 85 dBA is oppressive, and at 90, most people are trying to get away. So the difference between 80 dB and 80 dBA is very significant -- 80 dBA is difficult to talk over, and 80 dB is quite peaceful. :-)

So what is 'A' weighting? 'A' weighting compensates for the fact that we don't perceive lower frequency sounds as well as high frequency sounds (we hear 20 Hz to 20,000 Hz). There's a lot of low-end rumble that our ears/brains pretty much ignore. In addition, we're more sensitive to a certain midrange (1000 Hz to 4000 Hz). Most agree that this frequency range contains the sounds of consonants of speech (vowels happen at a much lower frequency). Imagine talking with just vowels. You can't understand anything. Thus, the ability of a human to be able to communicate (conventionally) rests in the 1kHz-5kHz bump in hearing sensitivity. Interestingly, this is why most telephone systems only transmit 300 Hz to 3000 Hz. It was determined that this was the minimal response needed to understand the voice on the other end.

But I think that's more than you wanted to know. Hope it helps. :-)

Solution 3 - Audio

You can't easily measure absolute dB SPL, since your microphone and analogue hardware are not calibrated. You may be able to do an approximate calibration for a particular hardware set up but you would need to repeat this for every different microphone and hardware set up that you plan to support.

If you do have some kind of SPL reference source that you can use then then it gets easier:

  • use your reference source to generate a tone at a known dB SPL - measure this
  • measure the ambient noise
  • calculate noise level = 20 * log10 (V_noise / V_ref) + dB_ref

Of course this assumes that the frequency response of your microphone and audio hardware is reasonably flat and that you just want a flat (unweighted) noise figure. If you want a weighted (e.g. A-weight) noise figure then you'll have to do rather more processing.

Solution 4 - Audio

You can't. dB is a relative unit, IOW it is a unit for comparing two measurements against each other. You can only say that measurement A is x dB louder than measurement B, but in your case you only have one measurement. Therefore, it simply isn't possible to calculate the dB level.

Solution 5 - Audio

According to Merchant et al. (section 3.2 in the appendix: "Measuring acoustic habitats", Methods in Ecology and Evolution, 2015), you can actually calculate absolute, calibrated SPL values using manufacturer specifications by subtracting a correction term S to your relative (scaled to maximum) SPL values:

S = M + G + 20log10(1/Vadc) + 20log10(2^Nbit-1)

where M is the sensitivity of the transducer (microphone) re 1 V/Pa. G is the gain applied by the user. Vadc is the zero-to-peak voltage, given by multiplying the rms ADC voltage by a conversion factor of squareroot(2). Nbit is the bit sampling depth.

The last term is necessary if your system scales the amplitude by its maximum.

The correction will be more accurate using end-to-end calibration with sound calibrators.

Note that the formula above is dependent on frequency, but you could apply it over a wider frequency range if your microphone has a flat frequency response.

Solution 6 - Audio

I use a sound level calibrator. It produces 94 dB or 114dB at 1 KHz wich is a frecuency where weighting filters share the same level. With calibrator at 114dB I adjust mic gain to reach almost full scale input simply watching a sound card based virtual osciloscope. Now I know Vref @ 114dB. I developed a simple software based SPL meter that can be provided if needed. You can use REW too. You hace to know that PC hardware hardly reaches 60 dB of dynamic range so calibrating @114 dB it wont read less than 54dB, wich is pretty high if you consider that sleeping is good with less than 35 dB A. In this case you can calibrate at 94dB and then you may measure down to 34dB but again you will hit pc and mic self noise wich may you prevent to reach such low levels. Anyway, once calibrated, measures at 114dB and 94dB should read fine. Note: the lab standard pistonphone calibrator operates at 250 Hz.

Solution 7 - Audio

The short answer is: you cannot do sound level measurements with your laptop, nor with your cellphone, etc., for all the reasons outlined previously, plus the fact your cellphone, laptop, etc. use compression algorithms to assure that everything recorded is within the hardware capability. So, if for example you measure a sound then run it through signal processing software such as Head Artemis or LMS Test.Lab, the indicated sound pressure level will always be in the neighborhood of 80 dB(A) regardless of the true level. I can say this from having used cellphone or laptop audio to get an idea of a noise frequency spectrum, while taking level measurements using a calibrated sound level meter. Interestingly, Radio Shack used to sell a microphone intended for speech input while videoconferencing that had very flat frequency response over a broad range, and only cost about $15.

Solution 8 - Audio

Well! I Used RobertT's Method But It Always Giving Me Oveflow Exception, Then I Used:- int dB = -36 - (value * -1), The Exception Gone, I Don't Know Whether It's Telling dB Values, If You Knew Using Code Given Below, Please Comment Me Whether it's A dB Value or not.

VB.NET:-

Dim dB As Integer = -36 - (9 * -1)

C#:-

int dB = -36 - (9 * -1)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionoBlankView Question on Stackoverflow
Solution 1 - AudioRobertTView Answer on Stackoverflow
Solution 2 - Audiouser545125View Answer on Stackoverflow
Solution 3 - AudioPaul RView Answer on Stackoverflow
Solution 4 - AudioJörg W MittagView Answer on Stackoverflow
Solution 5 - AudiokdarrasView Answer on Stackoverflow
Solution 6 - AudioAntonioView Answer on Stackoverflow
Solution 7 - AudioRobert1911View Answer on Stackoverflow
Solution 8 - AudioStackoverflowuserView Answer on Stackoverflow