How to best determine volume of a signal?

2.9k views Asked by At

I want to determine the volume of an audio signal.

I have found two options:

  1. Compute Root Mean Squared of the amplitude
  2. find the maximum amplitude

Are there advantages to using #1 or #2?

Here is what I am trying to do: I want my Android to analyze audio from the microphone. I want the device to detect a loud noise. The input is a short [].

2

There are 2 answers

0
Han On BEST ANSWER

If you use the maximum amplitude (2), then your volume level would be determined by a single sample (which you might not even be able to hear). When calculating a value that correlates with your impression of the loudness of the sound such as the Sound Pressure Level or the Sound Power Level you need to use the RMS (1).

Because you ear is not equally sensitive to all frequencies, a better correlate of your perception can be had by using an A-weighting on the signal. Split (filter) the signal in octave bands, calculate the RMS for each band and apply the A-weighting.

0
vitakot On

If you want to check volume level, just compute its dB Value (I assume the signal is normalized i.e. 1 == maximum level):

level[n] = - 20 x log(1/signal[n]); 

However, detecting audio noise is not a trivial task. The most common and simple technique is to use algorithm called NoiseGate which basically compares the signal level with some dB Threshold value - if the signal level is above threshold, then the output is zeroed. But it is unusable in practice; there must be also some Attack and Release times for smooth thresholding otherwise it would affect also a real signal (music, speech) and produce some kind of clipping.

Check Google, it will give you a lot of resources about NoiseGate algorithm and noise removal techniques:

http://en.wikipedia.org/wiki/Noise_gate

http://www.developer.com/java/other/article.php/3599661/Adaptive-Noise-Cancellation-using-Java.htm