librosa.autocorrelate

librosa.autocorrelate(y, max_size=None, axis=-1)[source]

Bounded-lag auto-correlation

Parameters
ynp.ndarray

array to autocorrelate

max_sizeint > 0 or None

maximum correlation lag. If unspecified, defaults to y.shape[axis] (unbounded)

axisint

The axis along which to autocorrelate. By default, the last axis (-1) is taken.

Returns
znp.ndarray

truncated autocorrelation y*y along the specified axis. If max_size is specified, then z.shape[axis] is bounded to max_size.

Notes

This function caches at level 20.

Examples

Compute full autocorrelation of y

>>> y, sr = librosa.load(librosa.ex('trumpet'))
>>> librosa.autocorrelate(y)
array([ 6.899e+02,  6.236e+02, ...,  3.710e-08, -1.796e-08])

Compute onset strength auto-correlation up to 4 seconds

>>> import matplotlib.pyplot as plt
>>> odf = librosa.onset.onset_strength(y=y, sr=sr, hop_length=512)
>>> ac = librosa.autocorrelate(odf, max_size=4* sr / 512)
>>> fig, ax = plt.subplots()
>>> ax.plot(ac)
>>> ax.set(title='Auto-correlation', xlabel='Lag (frames)')
../_images/librosa-autocorrelate-1.png