def corrmtx(x_input, m, method='<STR_LIT>'):
valid_methods = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>']<EOL>if method not in valid_methods:<EOL><INDENT>raise ValueError("<STR_LIT>" % valid_methods)<EOL><DEDENT>from scipy.linalg import toeplitz<EOL>N = len(x_input)<EOL>if isinstance(x_input, list):<EOL><INDENT>x = numpy.array(x_input)<EOL><DEDENT>else:<EOL><INDENT>x = x_input.copy()<EOL><DEDENT>if x.dtype == complex:<EOL><INDENT>complex_type = True<EOL><DEDENT>else:<EOL><INDENT>complex_type = False<EOL><DEDENT>if method in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>Lp = toeplitz(x[<NUM_LIT:0>:m], [<NUM_LIT:0>]*(m+<NUM_LIT:1>))<EOL><DEDENT>Tp = toeplitz(x[m:N], x[m::-<NUM_LIT:1>])<EOL>if method in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>Up = toeplitz([<NUM_LIT:0>]*(m+<NUM_LIT:1>), numpy.insert(x[N:N-m-<NUM_LIT:1>:-<NUM_LIT:1>],<NUM_LIT:0>,<NUM_LIT:0>))<EOL><DEDENT>if method == '<STR_LIT>':<EOL><INDENT>if complex_type == True:<EOL><INDENT>C = numpy.zeros((N+m, m+<NUM_LIT:1>), dtype=complex)<EOL><DEDENT>else:<EOL><INDENT>C = numpy.zeros((N+m, m+<NUM_LIT:1>))<EOL><DEDENT>for i in range(<NUM_LIT:0>, m):<EOL><INDENT>C[i] = Lp[i]<EOL><DEDENT>for i in range(m, N):<EOL><INDENT>C[i] = Tp[i-m]<EOL><DEDENT>for i in range(N, N+m):<EOL><INDENT>C[i] = Up[i-N]<EOL><DEDENT><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>if complex_type == True:<EOL><INDENT>C = numpy.zeros((N, m+<NUM_LIT:1>), dtype=complex)<EOL><DEDENT>else:<EOL><INDENT>C = numpy.zeros((N, m+<NUM_LIT:1>))<EOL><DEDENT>for i in range(<NUM_LIT:0>, m):<EOL><INDENT>C[i] = Lp[i]<EOL><DEDENT>for i in range(m, N):<EOL><INDENT>C[i] = Tp[i-m]<EOL><DEDENT><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>if complex_type == True:<EOL><INDENT>C = numpy.zeros((N, m+<NUM_LIT:1>), dtype=complex)<EOL><DEDENT>else:<EOL><INDENT>C = numpy.zeros((N, m+<NUM_LIT:1>))<EOL><DEDENT>for i in range(<NUM_LIT:0>, N-m):<EOL><INDENT>C[i] = Tp[i]<EOL><DEDENT>for i in range(N-m, N):<EOL><INDENT>C[i] = Up[i-N+m]<EOL><DEDENT><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>return Tp<EOL><DEDENT>elif method == '<STR_LIT>':<EOL><INDENT>if complex_type == True:<EOL><INDENT>C = numpy.zeros((<NUM_LIT:2>*(N-m), m+<NUM_LIT:1>), dtype=complex)<EOL><DEDENT>else:<EOL><INDENT>C = numpy.zeros((<NUM_LIT:2>*(N-m), m+<NUM_LIT:1>))<EOL><DEDENT>for i in range(<NUM_LIT:0>, N-m):<EOL><INDENT>C[i] = Tp[i]<EOL><DEDENT>Tp = numpy.fliplr(Tp.conj())<EOL>for i in range(N-m, <NUM_LIT:2>*(N-m)):<EOL><INDENT>C[i] = Tp[i-N+m]<EOL><DEDENT><DEDENT>return C<EOL>
r"""Correlation matrix

    This function is used by PSD estimator functions. It generates
    the correlation matrix from a correlation data set and a maximum lag.

    :param array x: autocorrelation samples (1D)
    :param int m: the maximum lag

    Depending on the choice of the method, the correlation matrix has different
    sizes, but the number of rows is always m+1.

    Method can be :

    * 'autocorrelation': (default) X is the (n+m)-by-(m+1) rectangular Toeplitz
      matrix derived using prewindowed and postwindowed data.
    * 'prewindowed': X is the n-by-(m+1) rectangular Toeplitz matrix derived
      using prewindowed data only.
    * 'postwindowed': X is the n-by-(m+1) rectangular Toeplitz matrix that
      derived using postwindowed data only.
    * 'covariance': X is the (n-m)-by-(m+1) rectangular Toeplitz matrix
      derived using nonwindowed data.
    * 'modified': X is the 2(n-m)-by-(m+1) modified rectangular Toeplitz
      matrix that generates an autocorrelation estimate for the length n data
      vector x, derived using forward and backward prediction error estimates.


    :return:
        * the autocorrelation matrix
        * R, the (m+1)-by-(m+1) autocorrelation matrix estimate ``R= X'*X``.

    .. rubric:: Algorithm details:

    The **autocorrelation** matrix is a :math:`(N+p) \times (p+1)` rectangular Toeplilz
    data matrix:

    .. math:: X_p = \begin{pmatrix}L_p\\T_p\\Up\end{pmatrix}

    where the lower triangular :math:`p \times (p+1)` matrix :math:`L_p` is

    .. math:: L_p =
        \begin{pmatrix}
        x[1]     &  \cdots     & 0     & 0        \\
        \vdots    &  \ddots     & \vdots & \vdots    \\
        x[p]     &  \cdots     & x[1]  & 0
        \end{pmatrix}

    where the rectangular :math:`(N-p) \times (p+1)` matrix :math:`T_p` is

    .. math:: T_p =
        \begin{pmatrix}
        x[p+1]     &  \cdots    & x[1]        \\
        \vdots    &  \ddots     & \vdots    \\
        x[N-p]     &  \cdots    & x[p+1]        \\
        \vdots    &  \ddots     & \vdots    \\
        x[N]     &  \cdots      & x[N-p]
        \end{pmatrix}

    and where the upper triangular :math:`p \times (p+1)` matrix :math:`U_p` is

    .. math:: U_p =
        \begin{pmatrix}
        0         &  x[N]      & \cdots     & x[N-p+1]        \\
        \vdots    &  \vdots    & \ddots & \vdots    \\
        0         &  0         & \cdots  & x[N]
        \end{pmatrix}

    From this definition, the prewindowed matrix is

    .. math:: X_p = \begin{pmatrix}L_p\\T_p\end{pmatrix}

    the postwindowed matrix is

    .. math:: X_p = \begin{pmatrix}T_p\\U_p\end{pmatrix}

    the covariance matrix is:

    .. math:: X_p = \begin{pmatrix}T_p\end{pmatrix}

    and the modified covariance matrix is:

    .. math:: X_p = \begin{pmatrix}T_p\\T_p^*\end{pmatrix}