

@cache
def autocorrelate(y, max_size=None, axis=(- 1)):
    "Bounded auto-correlation\n\n    Parameters\n    ----------\n    y : np.ndarray\n        array to autocorrelate\n\n    max_size  : int > 0 or None\n        maximum correlation lag.\n        If unspecified, defaults to `y.shape[axis]` (unbounded)\n\n    axis : int\n        The axis along which to autocorrelate.\n        By default, the last axis (-1) is taken.\n\n    Returns\n    -------\n    z : np.ndarray\n        truncated autocorrelation `y*y` along the specified axis.\n        If `max_size` is specified, then `z.shape[axis]` is bounded\n        to `max_size`.\n\n    Examples\n    --------\n    Compute full autocorrelation of y\n\n    >>> y, sr = librosa.load(librosa.util.example_audio_file())\n    >>> librosa.autocorrelate(y)\n    array([  1.584e+04,   1.580e+04, ...,  -1.154e-10,  -2.725e-13])\n\n\n    Compute onset strength auto-correlation up to 4 seconds\n\n    >>> import matplotlib.pyplot as plt\n    >>> odf = librosa.onset.onset_strength(y=y, sr=sr, hop_length=512)\n    >>> ac = librosa.autocorrelate(odf, max_size=4* sr / 512)\n    >>> plt.plot(ac)\n    >>> plt.title('Auto-correlation')\n    >>> plt.xlabel('Lag (frames)')\n\n    "
    if (max_size is None):
        max_size = y.shape[axis]
    max_size = int(min(max_size, y.shape[axis]))
    powspec = (np.abs(fft.fft(y, n=((2 * y.shape[axis]) + 1), axis=axis)) ** 2)
    autocorr = fft.ifft(powspec, axis=axis, overwrite_x=True)
    subslice = ([slice(None)] * autocorr.ndim)
    subslice[axis] = slice(max_size)
    autocorr = autocorr[subslice]
    if (not np.iscomplexobj(y)):
        autocorr = autocorr.real
    return autocorr

dataset/ETHPy150Open bmcfee/librosa/librosa/core/audio.py autocorrelate/original