How can I calculate audio dB level?
Asked Answered
K

8

64

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!

Katinakatine answered 15/3, 2010 at 8:5 Comment(3)
You might want to specify the hardware, A-D/sound card, microphone, OS, etc, that you are using.Supposing
For what purpose are you hoping to use this calculated noise level?Middlebreaker
You need to specify "dB (SPL)". "dB" by itself means nothing. en.wikipedia.org/wiki/DecibelCalque
S
100

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.

Subspecies answered 21/3, 2012 at 20:24 Comment(5)
I think amplitude should be 14731 / 32768 in your case.Helen
I'm trying to understand this answer. If I make a 44k wave file with every other value -1 and +1 (or -32767 and + 32768) I'll effectively get a silent file because I can't hear a 22k square wave so how does just looking an amplitude of the file tell me how loud the sound is? Similarly I can fill the file with just 32768 and I'll get a silent fileUniversalism
What about negative amplitude values? Should it be 20 * log10(Abs(amplitude))?Tonguelash
@AhmedAbdelhameed For signed integers, minvalue ≠ -maxvalue. So treat 1 to maxvalue as value/maxvalue and -1 to minvalue as value/minvalue. Either way the result is positive, so you're good. Just doing Abs on amplitude is going to give you slightly off results for negative amplitudes. And for minvalue itself (like -32768), your result will be greater than zero. Zero, however, represents the "loudest" it could possibly be. So that makes no sense.Amadis
@AhmedAbdelhameed and @Universalism - actually amplitude means "range of change" - en.wikipedia.org/wiki/Amplitude - so it makes no sense "pointwise" - you need a chunk and then calculate the log(max(chunk) - min(chunk)).Relations
T
24

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. :-)

Trifolium answered 16/12, 2010 at 18:58 Comment(0)
S
16

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.

Supposing answered 15/3, 2010 at 8:36 Comment(2)
To calculate the A-weight figure, would the relevant weighing be dB_ref? Say if the V_noise / V_ref was the amplitude for 10hz, would dB_ref be -70.4?Vinasse
A weighting adjustment will just be an additional dB correction applied at each frequency of interest. So you would calculate the "flat" dB SPL spectrum and then apply the A weighting correction.Supposing
H
6

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 + 20*log10(1/Vadc) + 20*log10(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.

Headsail answered 12/8, 2015 at 7:39 Comment(0)
H
4

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.

Hufnagel answered 15/3, 2010 at 8:47 Comment(1)
Usually when we talk about measuring sound levels we use dB SPL, which is sound pressure level relative to 20 µPa (rms).Supposing
S
1

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.

Schnauzer answered 14/3, 2014 at 11:48 Comment(0)
P
1

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.

Posehn answered 17/5, 2018 at 15:42 Comment(0)
B
-1

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)

Brahmanism answered 14/2, 2022 at 6:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.