db()

audmath.db(x, *, bottom=-120)[source]

Convert value to decibels.

The decibel of a value xRx \in \R is given by

db(x)={20log10x,if x>10bottom20bottom,else\text{db}(x) = \begin{cases} 20 \log_{10} x, & \text{if } x > 10^\frac{\text{bottom}}{20} \\ \text{bottom}, & \text{else} \end{cases}

where bottom\text{bottom} is provided by the argument of same name.

Parameters
  • x (Union[int, float, Sequence, ndarray]) – input value(s)

  • bottom (Union[int, float]) – minimum decibel value returned for very low input values. If set to None it will return -np.Inf for values equal or less than 0

Return type

Union[floating, ndarray]

Returns

input value(s) in dB

Examples

>>> db(1)
0.0
>>> db(0)
-120.0
>>> db(2)
6.020599913279624
>>> db([0, 1])
array([-120.,    0.])