def ma(X, Q, M):
if Q <= <NUM_LIT:0> or Q >= M:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>a, rho, _c = yulewalker.aryule(X, M, '<STR_LIT>')   <EOL>a = np.insert(a, <NUM_LIT:0>, <NUM_LIT:1>)<EOL>ma_params, _p, _c = yulewalker.aryule(a, Q, '<STR_LIT>')    <EOL>return ma_params, rho<EOL>
Moving average estimator.

    This program provides an estimate of the moving average parameters
    and driving noise variance for a data sequence based on a
    long AR model and a least squares fit.

    :param array X: The input data array
    :param int Q: Desired MA model order (must be >0 and <M)
    :param int M: Order of "long" AR model (suggest at least 2*Q )

    :return:
        * MA    - Array of Q complex MA parameter estimates
        * RHO   - Real scalar of white noise variance estimate

    .. plot::
        :width: 80%
        :include-source:

        from spectrum import arma2psd, ma, marple_data
        import pylab

        # Estimate 15 Ma parameters
        b, rho = ma(marple_data, 15, 30)
        # Create the PSD from those MA parameters
        psd = arma2psd(B=b, rho=rho, sides='centerdc')
        # and finally plot the PSD
        pylab.plot(pylab.linspace(-0.5, 0.5, 4096), 10 * pylab.log10(psd/max(psd)))
        pylab.axis([-0.5, 0.5, -30, 0])

    :reference: [Marple]_