def test_psd_matlab():

    """ Test the results of mlab csd/psd against saved results from Matlab"""

    from matplotlib import mlab

    test_dir_path = os.path.join(nitime.__path__[0], 'tests')

    ts = np.loadtxt(os.path.join(test_dir_path, 'tseries12.txt'))

    #Complex signal!
    ts0 = ts[1] + ts[0] * np.complex(0, 1)

    NFFT = 256
    Fs = 1.0
    noverlap = NFFT / 2

    fxx, f = mlab.psd(ts0, NFFT=NFFT, Fs=Fs, noverlap=noverlap,
                      scale_by_freq=True)

    fxx_mlab = fftpack.fftshift(fxx).squeeze()

    fxx_matlab = np.loadtxt(os.path.join(test_dir_path, 'fxx_matlab.txt'))

    npt.assert_almost_equal(fxx_mlab, fxx_matlab, decimal=5)
dataset/ETHPy150Open nipy/nitime/nitime/tests/test_algorithms.py/test_psd_matlab/original