def CORRELATION(x, y=None, maxlags=None, norm='<STR_LIT>'):
assert norm in ['<STR_LIT>','<STR_LIT>', '<STR_LIT>', None]<EOL>x = np.array(x)<EOL>if y is None:<EOL><INDENT>y = x<EOL><DEDENT>else:<EOL><INDENT>y = np.array(y)<EOL><DEDENT>N = max(len(x), len(y))<EOL>if len(x) < N:<EOL><INDENT>x = y.copy()<EOL>x.resize(N)<EOL><DEDENT>if len(y) < N:<EOL><INDENT>y = y.copy()<EOL>y.resize(N)<EOL><DEDENT>if maxlags is None:<EOL><INDENT>maxlags = N - <NUM_LIT:1><EOL><DEDENT>assert maxlags < N, '<STR_LIT>'<EOL>realdata = np.isrealobj(x) and np.isrealobj(y)<EOL>if realdata == True:<EOL><INDENT>r = np.zeros(maxlags, dtype=float)<EOL><DEDENT>else:<EOL><INDENT>r = np.zeros(maxlags, dtype=complex)<EOL><DEDENT>if norm == '<STR_LIT>':<EOL><INDENT>rmsx = pylab_rms_flat(x)<EOL>rmsy = pylab_rms_flat(y)<EOL><DEDENT>for k in range(<NUM_LIT:0>, maxlags+<NUM_LIT:1>):<EOL><INDENT>nk = N - k - <NUM_LIT:1><EOL>if realdata == True:<EOL><INDENT>sum = <NUM_LIT:0><EOL>for j in range(<NUM_LIT:0>, nk+<NUM_LIT:1>):<EOL><INDENT>sum = sum + x[j+k] * y[j]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>sum = <NUM_LIT:0.> + <NUM_LIT><EOL>for j in range(<NUM_LIT:0>, nk+<NUM_LIT:1>):<EOL><INDENT>sum = sum + x[j+k] * y[j].conjugate()<EOL><DEDENT><DEDENT>if k == <NUM_LIT:0>:<EOL><INDENT>if norm in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>r0 = sum/float(N)<EOL><DEDENT>elif norm is None:<EOL><INDENT>r0 = sum<EOL><DEDENT>else:<EOL><INDENT>r0 =  <NUM_LIT:1.><EOL><DEDENT><DEDENT>else:<EOL><INDENT>if norm == '<STR_LIT>':<EOL><INDENT>r[k-<NUM_LIT:1>] = sum / float(N-k)<EOL><DEDENT>elif norm == '<STR_LIT>':<EOL><INDENT>r[k-<NUM_LIT:1>] = sum / float(N)<EOL><DEDENT>elif norm is None:<EOL><INDENT>r[k-<NUM_LIT:1>] = sum<EOL><DEDENT>elif norm == '<STR_LIT>':<EOL><INDENT>r[k-<NUM_LIT:1>] =  sum/(rmsx*rmsy)/float(N)<EOL><DEDENT><DEDENT><DEDENT>r = np.insert(r, <NUM_LIT:0>, r0)<EOL>return r<EOL>
r"""Correlation function

    This function should give the same results as :func:`xcorr` but it
    returns the positive lags only. Moreover the algorithm does not use
    FFT as compared to other algorithms.

    :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 [0:maxlags]
        when maxlags is not specified, the range of lags is [0:maxlags].
    :param str norm: normalisation in ['biased', 'unbiased', None, 'coeff']

        * *biased*   correlation=raw/N,
        * *unbiased* correlation=raw/(N-`|lag|`)
        * *coeff*    correlation=raw/(rms(x).rms(y))/N
        * None       correlation=raw

    :return:
        * a numpy.array correlation sequence,  r[1,N]
        * a float for the zero-lag correlation,  r[0]

    The *unbiased* correlation has the form:

    .. math::

        \hat{r}_{xx} = \frac{1}{N-m}T \sum_{n=0}^{N-m-1} x[n+m]x^*[n] T

    The *biased* correlation differs by the front factor only:

    .. math::

        \check{r}_{xx} = \frac{1}{N}T \sum_{n=0}^{N-m-1} x[n+m]x^*[n] T

    with :math:`0\leq m\leq N-1`.

    .. doctest::

        >>> from spectrum import CORRELATION
        >>> x = [1,2,3,4,5]
        >>> res = CORRELATION(x,x, maxlags=0, norm='biased')
        >>> res[0]
        11.0

    .. note:: this function should be replaced by :func:`xcorr`.

    .. seealso:: :func:`xcorr`