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 as ref(S, axis=axes, keepdims=True), so each slice along axes gets its own reference. Default is 1.0.

  • amin – Minimum threshold for input values. Default is 1e-10.

  • top_db – Threshold the output at top_db below the peak of each slice along axes. Default is 80.0.

  • axes – Axis or axes over which ref and top_db are reduced. If "auto" (default), the axes are inferred from the rank of S: None for a scalar, (-1,) for 1-d, and (-2, -1) otherwise, so that batched inputs are scaled independently. Pass None to reduce over the whole array at once.

Returns:

dB-scaled spectrogram with same shape as input.

Raises:

librosax.util.exceptions.ParameterError – If amin is not strictly positive, if top_db is negative, or if a callable ref does not accept axis and keepdims.