Exemplo n.º 1
0
def test_arma():
    """arma, check that rho is correct (appendix 10.A )and reproduce figure 10.2"""
    a, b, rho = arma_estimate(marple_data, 20, 20, 40)
    psd = arma2psd(A=a, B=b, rho=rho, NFFT=None)
    psd = arma2psd(A=a, B=b, rho=rho)
    try:
        psd = arma2psd(A=None, B=None, rho=rho)
        assert False
    except:
        assert True
    return psd
Exemplo n.º 2
0
def test_arma():
    """arma, check that rho is correct (appendix 10.A )and reproduce figure 10.2"""
    a,b, rho = arma_estimate(marple_data, 20, 20, 40)
    psd = arma2psd(A=a,B=b, rho=rho, NFFT=None)
    psd = arma2psd(A=a,B=b, rho=rho)
    try:
        psd = arma2psd(A=None, B=None, rho=rho)
        assert False
    except:
        assert True
    return psd
Exemplo n.º 3
0
def test_arma2psd():
    psd = arma2psd([0.5], NFFT=16, norm=True) * 4
    assert_array_almost_equal(
        psd,
        numpy.array([
            0.44444444, 0.46000709, 0.51095832, 0.61248861, 0.8, 1.15298155,
            1.84198285, 3.06635155, 4., 3.06635155, 1.84198285, 1.15298155,
            0.8, 0.61248861, 0.51095832, 0.46000709
        ]))
Exemplo n.º 4
0
def test_ma():
    """ma PSD. check that rho is correct (appendix 10.A )and reproduce figure 10.2"""
    b, rho = ma(marple_data, 15, 30)
    assert_almost_equal(rho, 0.21432, decimal=4)

    assert_almost_equal(b[0], -0.25150803 + 0.67246418j, decimal=6)
    assert_almost_equal(b[1], -0.68612023 + 0.14571702j, decimal=6)
    """-0.25150803+0.67246418j, -0.68612023+0.14571702j,
        0.02061484-0.52246411j,  0.11444091-0.19157961j,
        0.36592370+0.09885689j,  0.00556917+0.4330789j ,
       -0.40634639+0.04854752j, -0.10092740-0.42813962j,
        0.26013726-0.16101382j,  0.25119793+0.16711825j,
       -0.13448885+0.21202256j, -0.16125290+0.10804393j,
       -0.03402254-0.18015694j,  0.08780647-0.1146388j ,
        0.02294750+0.08411391j
    """
    psd = arma2psd(B=b, rho=rho)
    return psd
Exemplo n.º 5
0
def test_ma():
    """ma PSD. check that rho is correct (appendix 10.A )and reproduce figure 10.2"""
    b, rho = ma(marple_data, 15, 30)
    assert_almost_equal(rho, 0.21432, decimal=4)

    assert_almost_equal(b[0], -0.25150803+0.67246418j, decimal=6)
    assert_almost_equal(b[1], -0.68612023+0.14571702j, decimal=6)

    """-0.25150803+0.67246418j, -0.68612023+0.14571702j,
        0.02061484-0.52246411j,  0.11444091-0.19157961j,
        0.36592370+0.09885689j,  0.00556917+0.4330789j ,
       -0.40634639+0.04854752j, -0.10092740-0.42813962j,
        0.26013726-0.16101382j,  0.25119793+0.16711825j,
       -0.13448885+0.21202256j, -0.16125290+0.10804393j,
       -0.03402254-0.18015694j,  0.08780647-0.1146388j ,
        0.02294750+0.08411391j
    """
    psd = arma2psd(B=b, rho=rho)
    return psd
Exemplo n.º 6
0
def test_arburg_functional():
    ar, P, k = arburg(marple_data, order=15)
    PSD = arma2psd(ar)
    newpsd = cshift(PSD, len(PSD)//2) # switch positive and negative freq
    return newpsd
Exemplo n.º 7
0
def test_arma2psd():
    psd = arma2psd([0.5], NFFT=16, norm=True)*4
    assert_array_almost_equal(psd, numpy.array([ 0.44444444,  0.46000709,  0.51095832,  0.61248861,  0.8       ,
            1.15298155,  1.84198285,  3.06635155,  4.        ,  3.06635155,
            1.84198285,  1.15298155,  0.8       ,  0.61248861,  0.51095832,
            0.46000709]))
Exemplo n.º 8
0
def test_arma():
    """arma, check that rho is correct (appendix 10.A )and reproduce figure 10.2"""
    a,b, rho = arma_estimate(marple_data, 20,20,40)
    psd = arma2psd(A=a,B=b, rho=rho)
    return psd
plt.ylabel('Power Spectral Density')

#Part 2.3(B)
btWin = signal.hamming(len(y_coordinates_3))
db20 = lambda x: np.log10(np.abs(x)) * 20
phi, f = blackmanTukey(y_coordinates_3, btWin, len(y_coordinates_3))
plt.figure()
plt.plot(x_coordinates_3, db20(phi))
plt.title('Blackman-Tukey')
plt.xlabel('Frequencies')
plt.ylabel('Spectral Estimate')

#Part 2.3(C)
plt.figure()
ar, ma, rho = arma_estimate(y_coordinates_3, 15, 15, 30)
psd = arma2psd(ar, ma, rho=rho, NFFT=4096)
plt.plot(10 * np.log10(psd / max(psd)))
plt.axis([0, 4096, -80, 0])
plt.title('AutoRegressive')
plt.xlabel('Frequencies')
plt.ylabel('Spectral Estimate')

plt.figure()
plt.subplot(2, 1, 1)
# Part 2.5
frequencies = 1000.0  # Sampling frequency
time_stamps_2 = np.arange(1000) / frequencies
signal_1 = np.sin(2 * np.pi * 100 * time_stamps_2)  # with frequency of 100
plt.plot(time_stamps_2, signal_1, color='r', label='Signal_1')

signal_2 = np.sin(2 * np.pi * 20 * time_stamps_2)  # frequency 20
Exemplo n.º 10
0
def test_arburg_functional():
    ar, P, k = arburg(marple_data, order=15)
    PSD = arma2psd(ar)
    newpsd = cshift(PSD, len(PSD) // 2)  # switch positive and negative freq
    return newpsd
Exemplo n.º 11
0
def test_arma():
    """arma, check that rho is correct (appendix 10.A )and reproduce figure 10.2"""
    a,b, rho = arma_estimate(marple_data, 20,20,40)
    psd = arma2psd(A=a,B=b, rho=rho)
    return psd