Exemple #1
0
def test_add_points():
    obj = Pnoise([1e3, 1e6, 1e9], [-100, -120, -140])
    obj.add_points([1e2, 1e3, 1e10], [-80, -70, -160])
    assert np.all(obj.fm == [1e2, 1e3, 1e6, 1e9, 1e10])
    assert np.all(obj.ldbc == [-80, -70, -120, -140, -160])
    # Check deep the interpolation
    obj.fm = [1e2, 1e6, 1.1e5, 7e7]
    obj.fm = [1e3, 1e6, 1.1e5,7e7, 1e10]
Exemple #2
0
def test__init__():
    # Test __init__
    fm = np.logspace(3, 9, 100)
    lorentzian = Pnoise(fm, 10 * np.log10(1 / (fm * fm)), label='Lorentzian')
    white = Pnoise(fm, -120 * np.ones(fm.shape), label='white')
    added = white + lorentzian
    added.label = "addition"
    assert_almost_equal(added.ldbc[0], -60, 4)
    assert_almost_equal(added.ldbc[-1], -120, 4)
    ix, = np.where(fm > 1e6)
    assert_almost_equal(added.ldbc[ix[0]], -117.2822, 4)
Exemple #3
0
def test_integration():
    fm = np.logspace(4, 8, 1000)
    lorentzian = Pnoise(fm, 10 * np.log10(1 / (fm * fm)), label='Lorentzian')
    white = Pnoise(fm, -120 * np.ones(fm.shape), label='white')
    added = lorentzian + white
    iadded_gardner = added.integrate()
    iadded_trapz = added.integrate(method='trapz')
    f_int = lambda fm: 2.0e-12 * fm - 2.0 / fm
    i_f_int = np.sqrt(f_int(fm[-1]) - f_int(fm[0]))
    assert_almost_equal(iadded_trapz, i_f_int, 5)
    assert_almost_equal(iadded_trapz, i_f_int, 5)
Exemple #4
0
def test_add_noise_sources():
    from numpy.testing import assert_almost_equal
    import matplotlib.pyplot as plt
    myAnalogPLL = AnalogPLL(4, 521.8e+06, Navg=10, prescaler=2, plltype=2)
    myAnalogPLL.loopcalc(1e6, 60.0, -130.0, 1e6, 0.1, 300)
    myAnalogPLL.lti()
    pinput = [
        Pnoise([1e3, 1e6, 1e9], [-140, -140, -140], label='input', fc=48e6)
    ]
    poutput = [
        Pnoise([1e3, 1e6, 1e9], [-70, -120, -180], label='VCO', fc=480e6)
    ]

    fm = np.logspace(4, 8, 100)
    pn_total, pn_in_colored, pn_out_colored = \
        myAnalogPLL.add_noise_sources(fm, pn_inputs=pinput, pn_outputs=poutput)
    assert_almost_equal(pn_total.interp1d(1e8), -160, 2)
    assert_almost_equal(pn_total.interp1d(1e4), -120, 2)
Exemple #5
0
def test_with_points_slopes():
    from copy import copy
    # test the new
    fi = np.array([1e4, 1e9])
    ldbc_fi = np.array([-40, -150])
    slopes = np.array([-30, -20])
    pnoise_model = Pnoise.with_points_slopes(fi, ldbc_fi, slopes)
    fm = np.logspace(3, 9, 20)
    pnoise_extrapolated = copy(pnoise_model)
    pnoise_extrapolated.fm = fm
Exemple #6
0
def test_with_points_slopes():
    from copy import copy
    # test the new
    fi = np.array([1e4, 1e9])
    ldbc_fi = np.array([-40, -150])
    slopes = np.array([-30, -20])
    pnoise_model = Pnoise.with_points_slopes(fi, ldbc_fi, slopes)
    fm = np.logspace(3, 9, 20)
    pnoise_extrapolated = copy(pnoise_model)
    pnoise_extrapolated.fm = fm
Exemple #7
0
def test_generate_samples():
    pnobj = Pnoise.with_points_slopes([1e5, 1e6, 1e9], [-80, -100, -120],
                                      [-30, -20, 0])
    npoints = 2**16
    fs = 500e6
    phi_t = pnobj.generate_samples(npoints, fs)
    f, pxx = sig.welch(phi_t, fs, window='blackman', nperseg=2**8)
    ldbc_noise = 10 * np.log10(pxx / 2)
    pnobj.fm = f[1:]
    error = np.max(np.abs((pnobj.ldbc - ldbc_noise[1:]) / pnobj.ldbc * 100))
    assert error < 2.5
Exemple #8
0
def test_private_functions():
    # test the new
    fi = np.array([1e4, 1e9])
    ldbc_fi = np.array([-40, -150])
    slopes = np.array([-30, -20])
    fm = np.logspace(3, 9, 20)
    ldbc_model = Pnoise._pnoise_point_slopes(fi, ldbc_fi, slopes, fm)
    func = intp.interp1d(log10(fm), ldbc_model, kind='linear')
    ldbc_0 = func(log10(fi[0]))
    ldbc_1 = func(log10(fi[1]))
    assert_almost_equal(ldbc_0, ldbc_fi[0], 0)
    assert_almost_equal(ldbc_1, ldbc_fi[1], 0)
Exemple #9
0
def test_generate_samples():
    pnobj = Pnoise.with_points_slopes([1e5, 1e6, 1e9],
                                      [-80,-100,-120],
                                      [-30,-20,0])
    npoints = 2 ** 16
    fs = 500e6
    phi_t = pnobj.generate_samples(npoints, fs)
    f, pxx = sig.welch(phi_t, fs, window='blackman', nperseg=2**8)
    ldbc_noise = 10 * np.log10(pxx / 2)
    pnobj.fm = f[1:]
    error = np.max(np.abs((pnobj.ldbc - ldbc_noise[1:]) / pnobj.ldbc * 100))
    assert error < 2.5
Exemple #10
0
def test_private_functions():
    # test the new
    fi = np.array([1e4, 1e9])
    ldbc_fi = np.array([-40, -150])
    slopes = np.array([-30, -20])
    fm = np.logspace(3, 9, 20)
    ldbc_model = Pnoise._pnoise_point_slopes(fi, ldbc_fi, slopes, fm)
    func = intp.interp1d(log10(fm), ldbc_model, kind='linear')
    ldbc_0 = func(log10(fi[0]))
    ldbc_1 = func(log10(fi[1]))
    assert_almost_equal(ldbc_0, ldbc_fi[0], 0)
    assert_almost_equal(ldbc_1, ldbc_fi[1], 0)
Exemple #11
0
def test_add_points():
    obj = Pnoise([1e3, 1e6, 1e9], [-100, -120, -140])
    obj.add_points([1e2, 1e3, 1e10], [-80, -70, -160])
    assert np.all(obj.fm == [1e2, 1e3, 1e6, 1e9, 1e10])
    assert np.all(obj.ldbc == [-80, -70, -120, -140, -160])
    # Check deep the interpolation
    obj.fm = [1e2, 1e6, 1.1e5, 7e7]
    obj.fm = [1e3, 1e6, 1.1e5, 7e7, 1e10]
Exemple #12
0
def test_interp1d_class():
    fm = np.array([1e3, 1e5, 1e7])
    lorentzian = Pnoise(fm, 10 * np.log10(1 / (fm * fm)),
                        label='Lorentzian')
    val = lorentzian.interp1d(1e6)
    assert_almost_equal(val, -120, 4)
Exemple #13
0
def test_fc_settler():
    fm = np.array([1e3, 1e5, 1e7])
    ldbc = 10 * np.log10(1 / (fm * fm))
    lorentzian = Pnoise(fm, ldbc, fc=1e9, label='Lorentzian')
    lorentzian.fc = 10e9
    assert_almost_equal(lorentzian.ldbc, ldbc + 20*log10(10e9/1e9))
Exemple #14
0
def test_fm_fc_scaling():
    pnobj = Pnoise([1e4, 1e6, 1e8],[-80,-100,-120], fc=2e9)
    pnobj.fc = 20e9
    assert np.all(pnobj.ldbc == [-60,-80,-100])
    pnobj.fm = [1e5, 1e6, 1e7]
    assert np.all(pnobj.ldbc == [-70,-80,-90])
Exemple #15
0
def test_at_fc():
    pnobj = Pnoise([1e4, 1e6, 1e8],[-80,-100,-120], fc=2e9)
    pnob2 = pnobj.at_fc(20e9)
    assert np.all(pnob2.ldbc == [-60,-80,-100])
Exemple #16
0
def test_fm_fc_scaling():
    pnobj = Pnoise([1e4, 1e6, 1e8], [-80, -100, -120], fc=2e9)
    pnobj.fc = 20e9
    assert np.all(pnobj.ldbc == [-60, -80, -100])
    pnobj.fm = [1e5, 1e6, 1e7]
    assert np.all(pnobj.ldbc == [-70, -80, -90])
Exemple #17
0
def test_at_fc():
    pnobj = Pnoise([1e4, 1e6, 1e8], [-80, -100, -120], fc=2e9)
    pnob2 = pnobj.at_fc(20e9)
    assert np.all(pnob2.ldbc == [-60, -80, -100])
Exemple #18
0
def test_fc_settler():
    fm = np.array([1e3, 1e5, 1e7])
    ldbc = 10 * np.log10(1 / (fm * fm))
    lorentzian = Pnoise(fm, ldbc, fc=1e9, label='Lorentzian')
    lorentzian.fc = 10e9
    assert_almost_equal(lorentzian.ldbc, ldbc + 20 * log10(10e9 / 1e9))
Exemple #19
0
def test_interp1d_class():
    fm = np.array([1e3, 1e5, 1e7])
    lorentzian = Pnoise(fm, 10 * np.log10(1 / (fm * fm)), label='Lorentzian')
    val = lorentzian.interp1d(1e6)
    assert_almost_equal(val, -120, 4)