def arma2psd(A=None, B=None, rho=<NUM_LIT:1.>, T=<NUM_LIT:1.>, NFFT=<NUM_LIT>, sides='<STR_LIT:default>',<EOL>norm=False):
if NFFT is None:<EOL><INDENT>NFFT = <NUM_LIT><EOL><DEDENT>if A is None and B is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>psd = np.zeros(NFFT, dtype=complex)<EOL>if A is not None:<EOL><INDENT>ip = len(A)<EOL>den = np.zeros(NFFT, dtype=complex)<EOL>den[<NUM_LIT:0>] = <NUM_LIT:1.>+<NUM_LIT><EOL>for k in range(<NUM_LIT:0>, ip):<EOL><INDENT>den[k+<NUM_LIT:1>] = A[k]<EOL><DEDENT>denf = fft(den, NFFT)<EOL><DEDENT>if B is not None:<EOL><INDENT>iq = len(B)<EOL>num = np.zeros(NFFT, dtype=complex)<EOL>num[<NUM_LIT:0>] = <NUM_LIT:1.>+<NUM_LIT><EOL>for k in range(<NUM_LIT:0>, iq):<EOL><INDENT>num[k+<NUM_LIT:1>] = B[k]<EOL><DEDENT>numf = fft(num, NFFT)<EOL><DEDENT>if A is not None and B is not None:<EOL><INDENT>psd = rho / T * abs(numf)**<NUM_LIT> / abs(denf)**<NUM_LIT><EOL><DEDENT>elif A is not None:<EOL><INDENT>psd = rho / T / abs(denf)**<NUM_LIT><EOL><DEDENT>elif B is not None:<EOL><INDENT>psd = rho / T * abs(numf)**<NUM_LIT><EOL><DEDENT>psd = np.real(psd)<EOL>if sides != '<STR_LIT:default>':<EOL><INDENT>from . import tools<EOL>assert sides in ['<STR_LIT>']<EOL>if sides == '<STR_LIT>':<EOL><INDENT>psd = tools.twosided_2_centerdc(psd)<EOL><DEDENT><DEDENT>if norm == True:<EOL><INDENT>psd /= max(psd)<EOL><DEDENT>return psd<EOL>
r"""Computes power spectral density given ARMA values.

    This function computes the power spectral density values
    given the ARMA parameters of an ARMA model. It assumes that
    the driving sequence is a white noise process of zero mean and
    variance :math:`\rho_w`. The sampling frequency and noise variance are
    used to scale the PSD output, which length is set by the user with the
    `NFFT` parameter.

    :param array A:   Array of AR parameters (complex or real)
    :param array B:   Array of MA parameters (complex or real)
    :param float rho: White noise variance to scale the returned PSD
    :param float T:   Sample interval in seconds to scale the returned PSD
    :param int NFFT:  Final size of the PSD
    :param str sides: Default PSD is two-sided, but sides can be set to centerdc.

    .. warning:: By convention, the AR or MA arrays does not contain the
        A0=1 value.

    If :attr:`B` is None, the model is a pure AR model. If :attr:`A` is None,
    the model is a pure MA model.

    :return: two-sided PSD

    .. rubric:: Details:

    AR case: the power spectral density is:

    .. math:: P_{ARMA}(f) = T \rho_w \left|\frac{B(f)}{A(f)}\right|^2

    where:

    .. math:: A(f) = 1 + \sum_{k=1}^q b(k) e^{-j2\pi fkT}
    .. math:: B(f) = 1 + \sum_{k=1}^p a(k) e^{-j2\pi fkT}

    .. rubric:: **Example:**

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

        import spectrum.arma
        from pylab import plot, log10, legend
        plot(10*log10(spectrum.arma.arma2psd([1,0.5],[0.5,0.5])), label='ARMA(2,2)')
        plot(10*log10(spectrum.arma.arma2psd([1,0.5],None)), label='AR(2)')
        plot(10*log10(spectrum.arma.arma2psd(None,[0.5,0.5])), label='MA(2)')
        legend()

    :References: [Marple]_