def autocorrelate(data, unbias=2, normalize=2):
    """
        Compute the autocorrelation coefficients for time series data.
        Here we use scipy.signal.correlate, but the results are the same as in
        Yang, et al., 2012 for unbias=1:


        "The autocorrelation coefficient refers to the correlation of a time
        series with its own past or future values. iGAIT uses unbiased
        autocorrelation coefficients of acceleration data to scale the regularity
        and symmetry of gait.
        The autocorrelation coefficients are divided by :math:`fc(0)`,
        so that the autocorrelation coefficient is equal to :math:`1` when :math:`t=0`:

        .. math::

            NFC(t) = \\frac{fc(t)}{fc(0)}


        Here :math:`NFC(t)` is the normalised autocorrelation coefficient, and :math:`fc(t)` are
        autocorrelation coefficients."

        :param data: time series data
        :type data: numpy array
        :param unbias: autocorrelation, divide by range (1) or by weighted range (2)
        :type unbias: integer or None
        :param normalize: divide by 1st coefficient (1) or by maximum abs. value (2)
        :type normalize: integer or None
        :return coefficients: autocorrelation coefficients [normalized, unbiased]
        :rtype coefficients: numpy array
        :return N: number of coefficients
        :rtype N: integer


        :Examples:

        >>> import numpy as np
        >>> from mhealthx.signals import autocorrelate
        >>> data = np.random.random(100)
        >>> unbias = 2
        >>> normalize = 2
        >>> plot_test = True
        >>> coefficients, N = autocorrelate(data, unbias, normalize, plot_test)
    """

    # Autocorrelation:
    coefficients = correlate(data, data, 'full')
    size = np.int(coefficients.size/2)
    coefficients = coefficients[size:]
    N = coefficients.size

    # Unbiased:
    if unbias:
        if unbias == 1:
            coefficients /= (N - np.arange(N))
        elif unbias == 2:
            coefficient_ratio = coefficients[0]/coefficients[-1]
            coefficients /= np.linspace(coefficient_ratio, 1, N)
        else:
            raise IOError("unbias should be set to 1, 2, or None")

    # Normalize:
    if normalize:
        if normalize == 1:
            coefficients /= np.abs(coefficients[0])
        elif normalize == 2:
            coefficients /= np.max(np.abs(coefficients))
        else:
            raise IOError("normalize should be set to 1, 2, or None")

    return coefficients, N
Compute the autocorrelation coefficients for time series data.
        Here we use scipy.signal.correlate, but the results are the same as in
        Yang, et al., 2012 for unbias=1:


        "The autocorrelation coefficient refers to the correlation of a time
        series with its own past or future values. iGAIT uses unbiased
        autocorrelation coefficients of acceleration data to scale the regularity
        and symmetry of gait.
        The autocorrelation coefficients are divided by :math:`fc(0)`,
        so that the autocorrelation coefficient is equal to :math:`1` when :math:`t=0`:

        .. math::

            NFC(t) = \\frac{fc(t)}{fc(0)}


        Here :math:`NFC(t)` is the normalised autocorrelation coefficient, and :math:`fc(t)` are
        autocorrelation coefficients."

        :param data: time series data
        :type data: numpy array
        :param unbias: autocorrelation, divide by range (1) or by weighted range (2)
        :type unbias: integer or None
        :param normalize: divide by 1st coefficient (1) or by maximum abs. value (2)
        :type normalize: integer or None
        :return coefficients: autocorrelation coefficients [normalized, unbiased]
        :rtype coefficients: numpy array
        :return N: number of coefficients
        :rtype N: integer


        :Examples:

        >>> import numpy as np
        >>> from mhealthx.signals import autocorrelate
        >>> data = np.random.random(100)
        >>> unbias = 2
        >>> normalize = 2
        >>> plot_test = True
        >>> coefficients, N = autocorrelate(data, unbias, normalize, plot_test)