librosax.autocorrelate¶
- autocorrelate(y: Array, *, max_size: int | None = None, axis: int = -1) Array[source]¶
Bounded-lag auto-correlation.
This function computes the autocorrelation of a signal using FFT for efficiency. The autocorrelation is bounded to a maximum lag specified by
max_size.- Parameters:
y – Array to autocorrelate.
max_size – Maximum correlation lag. If None, defaults to
y.shape[axis](unbounded).axis – Axis along which to autocorrelate. Default is -1 (last axis).
- Returns:
Autocorrelated array. If
max_sizeis specified, the shape alongaxiswill bemax_size. Otherwise, it matchesy.shape[axis].
Examples
Compute full autocorrelation of a white noise signal
>>> import numpy as np >>> y = np.random.randn(256) >>> z = librosax.autocorrelate(y) >>> z.shape (256,)
Compute autocorrelation with a maximum lag of 32 samples
>>> z = librosax.autocorrelate(y, max_size=32) >>> z.shape (32,)
Autocorrelate along the time axis of a batch of signals
>>> y = np.random.randn(10, 256) # 10 signals of length 256 >>> z = librosax.autocorrelate(y, axis=-1) >>> z.shape (10, 256)