Decibel and Logarithms

Introduction

The decibel is a unit to express loudness of sounds, and an important measurement in sound processing.

The decibel is the logarithmic scale of sound intensity. The reason to use the logarithm is that human hearing is logarithmic rather than linear.

The decibel is also not an absolute metric but a relative ratio of intensity of one sound compared to another. This part is very confusing because we think that familiar measurements like lengths "cm, m, km" and weight "g, kg..." are absolute units.

There are many online resources that explain the logarithms or the decibel. I don't see resources that explain both the logarithms and the decibel. This is my motivation to create this post: keeping information about the logarithms and the decibel in one page. 

Logarithms

The logarithms are inverse operation of an exponent (power). \[ 2^3 = 8 \]
\[ \log_28 = 3 \]
The log of 8 to the base 2 is 3, and 2 to the power of 3 is 8. The log of <number> is the exponent that makes the base number into <number>.

Here are more properties of the logarithms and examples (a > 0, a not equal to 1; M > 0; N > 0).
\[ \log_a a = 1 \]
\[ \log_a 1 = 0 \]
For example, 2 to the power of 1 is 2 and 2 to the power of 0 is 1.
\[ \log_a MN = \log_aM + \log_aN \]
\[ \log_a M/N = \log_aM - \log_aN \]
Log multiplication is addition and log division is subtraction. Examples:
\[ \log_2 2 \times \log_2 8 = 1 + 3 = 4 \]
\[ \log_2 2 / \log_2 8 = 1 - 3 = -2 \]
The power of the logarithms is multiplication:
\[ \log_a M^n = n \times log_aM \]
\[ \log_2 8^2 = 2 \times \log_28 = 2 \times 3 = 6 \]
Finally, there is a rule to change the base of the log. 
\[ \log_a M = \log_bM / \log_ba \]
\[ \log_2 8 = \log_{10}8 / \log_{10}2 \]
Python can do this example of base conversion for us.

>>> import math

>>> math.log2(8)

3.0

>>> math.log10(8) / math.log10(2)

3.0


As mentioned earlier, the logarithms are relevant to exponents. The powers can perform addition like below and this is very similar to the example of log multiplication.
\[ a^m \times a^n = a^{m+n} \]
\[ 2^1 \times 2^3 = 2^{1+3} = 2^4 \]
\[ \log_2 2 \times \log_2 8 = 1 + 3 = 4 \]
The figure clearly illustrates that the logarithmic function and the exponential function are a mirror image (inverse). 

Decibel

Now, we are ready to look at the formula of the decibel.
\[ dB = 10 \times \log_{10}(P_1/P_0) \]
\( P_1 \) is the power of a signal to measure its intensity. \( P_0 \) is the power of a reference signal which is going to be explained soon. The part of \( (P_1 / P_0) \) shows the proportion of powers of two sounds. The log of this value to the base of 10 is the unit Bel. Multiplied by 10, the value is finally a decibel (0.1 B = 1 dB).

Decibel: Physical vs Digital signal

So far so good. Except that we don't know what the reference signal \( P_0 \) is. The power of the reference signal turns out to be variable, depending on whether a signal is physical or digital.

When the signal is physical, the power of the reference signal is:
\[ P_0 = 10^{-12} W/m^2 \]
\( W/m^2 \) is the unit, Watt per square meter. This is approximately the softest sound perceivable for human hearing.

When the signal is digital, \( P_0 \) is the power of the maximum value possible in the normalised digital signal, which is \( 1^2 = 1 \).

An interesting observation is the output values of the decibel: 
  • Physical dB uses the smallest possible value for human hearing. Physical dBs are usually positive numbers 30 dB for a whisper and 80 dB for traffic. This is referred to as dB Sound Intensity Level (dBSIL).
  • Digital dB uses the largest possible value for normalised digital signals. Therefore, the value of the decibel of the digital signal is mostly a negative number like -6 dB. This is referred to as dB Full Scale (dBFS).

Decibel: Intensity (power/energy) vs Pressure (amplitude/magnitude)

In practical applications, measuring sound intensity is difficult, but a recording device can keep track of an air pressure (amplitude). For this reason, the decibel is often computed as follows:
\[ dB = 20 \times \log_{10}(A_1/A_0) \]
The log value is now multiplied by 20 instead of 10. The relationship between power and amplitude is:
\[ P = A^2 \]
If you remember the rule of the logarithms \( \log_a M^n = n \times log_aM \) and the rule of the exponent \( (a^m/b^m) = (a/b)^m \):
\[ 10 \times \log_{10}(A_1^2/A_0^2) = 10 \times \log_{10}(A_1/A_0)^2 = 20 \times \log_{10}(A_1/A_0) \]
Similar to the power-based decibel, the digital signal uses a maximum possible value of a normalised digital signal for the reference \( A_0 = 1 \). For physical signals, the reference is the softest possible air pressure for human perception and is defined as \( A_0 = 20 \mu Pa = 20 \times 10^{-6} \). This is referred to as dB Sound Pressure Level (dBSPL).

Finally, the signal amplitude can be measured by the maximum value of the signal or the root mean square (RMS) of the signal. The maximum value of the signal can be used to detect clipping of some high values. The RMS is to measure the average amplitude of the signal.

Signal-to-noise ratio (SNR)

Another metrics commonly seen in audio processing is signal-to-noise ratio (SNR). Similar to the decibel, this metric compares a regular signal to a noise signal. The concept of SNR should be easy to grasp after understanding the decibel. The formula is as follows:
\[ SNR = 20 \times \log_{10}(A_{signal}/A_{noise}) = 10 \times \log_{10}(P_{signal}/P_{noise}) \]
The larger noise level leads to a negative value, and the smaller noise level to a positive value.

Examples

Finally, let's look at actual examples of the decibels and SNR. 

30 dB is the pressure level of whisper, and we want to know the pressure of whisper \(A_1\) in Pascal.
\[ 30 = 20 \times \log_{10}(A_1/A_0) \]
\[ 30 = 20 \times \log_{10}(A_1) - 20 \times \log_{10}(A_0) \]
\[ 30/20 = \log_{10}(A_1) - \log_{10}(A_0) \]
\[ \log_{10}(A_1) = 30/20 + \log_{10}(A_0) \]
\[ 10^{\log_{10}(A_1)} = 10^{30/20 + \log_{10}(A_0)} \]
\[ A_1 = 10^{30/20} \times 10^{\log_{10}(A_0)} \]
\[ A_1 = 10^{30/20} \times A_0 \]
This derivation applies many laws of logarithms and exponents!

>>> a_0 = 20 * 10**-6

>>> a_1 = a_0 * 10 ** (30/20)

>>> a_1

0.0006324555320336758

The python interpreter says the pressure of whisper in Pascal is 0.000632 Pa. This is a very small value and no wonder why the decibel is a convenient unit to measure sounds.

The rocket launch is 170 dB. Using the same formula, it is 6324.55 Pascals. 

>>> a_1 = a_0 * 10 ** (170/20)

>>> a_1

6324.555320336758

So the decibel is indeed a unit to express noise of whispering and rocket launch in the convenient scale.

Let's say there's a digital signal whose peak value is 0.5. Its dBFS is -6.02 dBFS.

>>> import math

>>> 20* math.log10(0.5/1.0)

-6.020599913279624


The peak value of the current signal is still 0.5, and there's a noise signal of the peak value 0.3. In this case, SNR is 4.437.

>>> 20*math.log10(0.5/0.3)

4.436974992327128


And if the noise signal is larger, say 0.8, SNR becomes -4.082.

>>> 20*math.log10(0.5/0.8)

-4.082399653118496

Summary

The decibel is a commonly used metric to express loudness of a sound. The decibel is a logarithm of proportion between two signals. We must always define a reference signal to measure loudness of the signal of interest. 

This post hopefully summarised logarithm operations essential for computation of the decibel and provided some examples to compute the decibel of both physical and digital signals.

Comments

Popular posts from this blog

Digital Signal Processing Basics

How wav2vec2.0 takes input audio data

SLT 2022 Notes