librosa.core.autocorrelate

librosa.core.autocorrelate(y, max_size=None, axis=-1)

Bounded auto-correlation

Parameters:

y : np.ndarray

array to autocorrelate

max_size : int > 0 or None

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

axis : int

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

Returns:

z : np.ndarray

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

Examples

Compute full autocorrelation of y

>>> y, sr = librosa.load(librosa.util.example_audio_file())
>>> librosa.autocorrelate(y)
array([  1.584e+04,   1.580e+04, ...,  -1.154e-10,  -2.725e-13])

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)
>>> plt.plot(ac)
>>> plt.title('Auto-correlation')
>>> plt.xlabel('Lag (frames)')

(Source code)

../_images/librosa-core-autocorrelate-1.png