librosa.feature.zero_crossing_rate

librosa.feature.zero_crossing_rate(y, *, frame_length=2048, hop_length=512, center=True, **kwargs)[source]

Compute the zero-crossing rate of an audio time series.

Parameters:
ynp.ndarray [shape=(…, n)]

Audio time series. Multi-channel is supported.

frame_lengthint > 0

Length of the frame over which to compute zero crossing rates

hop_lengthint > 0

Number of samples to advance for each frame

centerbool

If True, frames are centered by padding the edges of y. This is similar to the padding in librosa.stft, but uses edge-value copies instead of zero-padding.

**kwargsadditional keyword arguments to pass to librosa.zero_crossings
thresholdfloat >= 0

If specified, values where -threshold <= y <= threshold are clipped to 0.

ref_magnitudefloat > 0 or callable

If numeric, the threshold is scaled relative to ref_magnitude. If callable, the threshold is scaled relative to ref_magnitude(np.abs(y)).

zero_posboolean

If True then the value 0 is interpreted as having positive sign. If False, then 0, -1, and +1 all have distinct signs.

axisint

Axis along which to compute zero-crossings. .. note:: By default, the pad parameter is set to False, which differs from the default specified by librosa.zero_crossings.

Returns:
zcrnp.ndarray [shape=(…, 1, t)]

zcr[..., 0, i] is the fraction of zero crossings in frame i

See also

librosa.zero_crossings

Compute zero-crossings in a time-series

Examples

>>> y, sr = librosa.load(librosa.ex('trumpet'))
>>> librosa.feature.zero_crossing_rate(y)
array([[0.044, 0.074, ..., 0.488, 0.355]])