librosax.power_to_db¶
- power_to_db(S: Array, *, ref: float | Callable = 1.0, amin: float = 1e-10, top_db: float | None = 80.0, axes: str | int | tuple | None = 'auto') Array[source]¶
Convert a power spectrogram to decibel (dB) units.
This computes the scaling
10 * log10(S / ref)in a numerically stable way.- Parameters:
S – Input power spectrogram. Any shape; applied element-wise.
ref – Reference value for scaling. If scalar, the power is scaled relative to
ref. If callable, the reference value is computed asref(S, axis=axes, keepdims=True), so each slice alongaxesgets its own reference. Default is 1.0.amin – Minimum threshold for input values. Default is 1e-10.
top_db – Threshold the output at
top_dbbelow the peak of each slice alongaxes. Default is 80.0.axes – Axis or axes over which
refandtop_dbare reduced. If"auto"(default), the axes are inferred from the rank ofS:Nonefor a scalar,(-1,)for 1-d, and(-2, -1)otherwise, so that batched inputs are scaled independently. PassNoneto reduce over the whole array at once.
- Returns:
dB-scaled spectrogram with same shape as input.
- Raises:
librosax.util.exceptions.ParameterError – If
aminis not strictly positive, iftop_dbis negative, or if a callablerefdoes not acceptaxisandkeepdims.