music.amp_to_db¶
- music.amp_to_db(amplitude_difference)[source]¶
Converts a difference in amplitude to a difference in decibels.
This function takes a difference in amplitude as input and returns the corresponding difference in decibels.
- Parameters:
- amplitude_difference
float The difference in amplitude to be converted.
- amplitude_difference
- Returns:
floatThe difference in decibels corresponding to the input difference in amplitude. A ratio of zero is minus infinity decibels.
- Raises:
ValueErrorIf the ratio is negative, which no number of decibels is. It came back as NaN behind numpy’s warning, and zero as minus infinity behind another.
- Parameters:
amplitude_difference (float)
- Return type:
Notes
The inverse of
db_to_amp()[1]:\[V_{dB} = 20 \log_{10} A.\]References
[1]Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
Examples
>>> float(amp_to_db(2.0)) 6.020599913279624 >>> float(amp_to_db(0.5)) -6.020599913279624 >>> float(amp_to_db(0)) -inf