librosax.feature.spectral_bandwidth

spectral_bandwidth(*, y: Array | None = None, sr: float = 22050, S: Array | None = None, n_fft: int = 2048, hop_length: int = 512, win_length: int | None = None, window: str = 'hann', center: bool = True, pad_mode: str = 'constant', freq: Array | None = None, centroid: Array | None = None, norm: bool = True, p: float = 2) Array[source]

Compute p’th-order spectral bandwidth.

The spectral bandwidth at frame t is computed by:

(sum_k S[k, t] * (freq[k, t] - centroid[t])**p)**(1/p)

Users should ensure S is real-valued and non-negative.

Parameters:
  • y

    Audio time series. The last axis must be time.

    • (T,) - single waveform

    • (B, T) - batch of waveforms

  • sr – Audio sampling rate

  • S – (optional) Pre-computed spectrogram magnitude with shape (..., F, N)

  • n_fft – FFT window size

  • hop_length – Hop length for STFT

  • win_length – Window length

  • window – Window function

  • center – If True, pad the signal

  • pad_mode – Padding mode

  • freq – Center frequencies for spectrogram bins. If None, FFT bin center frequencies are used.

  • centroid – Pre-computed centroid frequencies

  • norm – Normalize per-frame spectral energy (sum to one)

  • p – Power to raise deviation from spectral centroid

Returns:

Frequency bandwidth with shape (..., 1, N).

  • (T,)(1, N)

  • (B, T)(B, 1, N)