def xcorr(x, y=None, maxlags=None, norm='<STR_LIT>'):
N = len(x)<EOL>if y is None:<EOL><INDENT>y = x<EOL><DEDENT>assert len(x) == len(y), '<STR_LIT>'<EOL>if maxlags is None:<EOL><INDENT>maxlags = N-<NUM_LIT:1><EOL>lags = np.arange(<NUM_LIT:0>, <NUM_LIT:2>*N-<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>assert maxlags <= N, '<STR_LIT>'<EOL>lags = np.arange(N-maxlags-<NUM_LIT:1>, N+maxlags)<EOL><DEDENT>res = np.correlate(x, y, mode='<STR_LIT>')<EOL>if norm == '<STR_LIT>':<EOL><INDENT>Nf = float(N)<EOL>res = res[lags] / float(N)    <EOL><DEDENT>elif norm == '<STR_LIT>':<EOL><INDENT>res = res[lags] / (float(N)-abs(np.arange(-N+<NUM_LIT:1>, N)))[lags]<EOL><DEDENT>elif norm == '<STR_LIT>':<EOL><INDENT>Nf = float(N)<EOL>rms = pylab_rms_flat(x) * pylab_rms_flat(y)<EOL>res = res[lags] / rms / Nf<EOL><DEDENT>else:<EOL><INDENT>res = res[lags]<EOL><DEDENT>lags = np.arange(-maxlags, maxlags+<NUM_LIT:1>)<EOL>return res, lags<EOL>
Cross-correlation using numpy.correlate

    Estimates the cross-correlation (and autocorrelation) sequence of a random
    process of length N. By default, there is no normalisation and the output
    sequence of the cross-correlation has a length 2*N+1.

    :param array x: first data array of length N
    :param array y: second data array of length N. If not specified, computes the
        autocorrelation.
    :param int maxlags: compute cross correlation between [-maxlags:maxlags]
        when maxlags is not specified, the range of lags is [-N+1:N-1].
    :param str option: normalisation in ['biased', 'unbiased', None, 'coeff']

    The true cross-correlation sequence is

    .. math:: r_{xy}[m] = E(x[n+m].y^*[n]) = E(x[n].y^*[n-m])

    However, in practice, only a finite segment of one realization of the
    infinite-length random process is available.

    The correlation is estimated using numpy.correlate(x,y,'full').
    Normalisation is handled by this function using the following cases:

        * 'biased': Biased estimate of the cross-correlation function
        * 'unbiased': Unbiased estimate of the cross-correlation function
        * 'coeff': Normalizes the sequence so the autocorrelations at zero
           lag is 1.0.

    :return:
        * a numpy.array containing the cross-correlation sequence (length 2*N-1)
        * lags vector

    .. note:: If x and y are not the same length, the shorter vector is
        zero-padded to the length of the longer vector.

    .. rubric:: Examples

    .. doctest::

        >>> from spectrum import xcorr
        >>> x = [1,2,3,4,5]
        >>> c, l = xcorr(x,x, maxlags=0, norm='biased')
        >>> c
        array([ 11.])

    .. seealso:: :func:`CORRELATION`.