Ejemplo n.º 1
0
def test_classical_synthesizer():
    Ts = 1.0 / 200e6

    vco = Vco("fc + Kv*x", "fc,Kv,Ts", 1.84e9, 30e6, Ts)
    ref_clk = SigGen("square", 20e6, Ts)
    reg1 = Reg()
    reg2 = Reg()
    and1 = And()

    rc_filter = Filter("1.0", "1+1/(2*pi*fp)*s", "fp,Ts", 127.2e3, Ts)
    int_filter = Filter("2*pi*fp/10", "s", "fp,Ts", 127.2e3, Ts)

    v1 = []
    v2 = []

    N = 90
    for i in xrange(200000):
        if i == 160000:
            N += 1
        ref_clk.inp(0.0)  # set jitter to zero

        #PFD
        reg1.inp(1.0, vco.out, -1.0, and1.out)
        reg2.inp(1.0, ref_clk.out, -1.0, and1.out)
        and1.inp(reg1.out, reg2.out)

        # charge pump
        chp_out = (reg2.out - reg1.out) * 0.1989 * np.pi

        #loop filter
        rc_filter.inp(chp_out)
        int_filter.inp(chp_out)
        vco_in = rc_filter.out + int_filter.out

        #VCO
        vco.inp(vco_in, N)

        #
        v1.append(N)
        v2.append(vco_in)

    ax1 = plt.subplot(211)
    plt.plot(v1)
    plt.subplot(212, sharex=ax1)
    plt.plot(v2)

    #plt.ylim([-0.5,2.5])
    plt.show()
Ejemplo n.º 2
0
def test_case1():
    Ts = 1e-9
    vco = Vco("fc + Kv*x","fc,Kv,Ts",10e6,1e6,Ts)
    vout = []
    phase_out = []

    vco2 = Vco("fc + Kv*x","fc,Kv,Ts",10e6,1e6,Ts)
    vout2 = []

    for i in range(10000):
        vin = 1e-4*i
        vout.append(vco.inp(vin))
        vout2.append(vco2.inp(vin,3))

        phase_out.append(np.sin(vco.phase))
    #print vout 

    ax1 = plt.subplot(311)
    plt.plot(vout)
    plt.ylabel("square")

    plt.subplot(312,sharex=ax1,sharey=ax1)
    plt.plot(phase_out)
    plt.ylabel("sine")

    plt.subplot(313,sharex=ax1,sharey=ax1)
    plt.plot(vout2)
    plt.ylabel("square3")
    plt.ylim([-1.5,1.5])
    plt.show()
Ejemplo n.º 3
0
def test_case1():
    Ts = 1e-9
    vco = Vco("fc + Kv*x", "fc,Kv,Ts", 10e6, 1e6, Ts)
    v1 = []
    v2 = []
    v3 = []

    rand1 = Rand("gauss")

    for i in range(10000):

        if i == 5000:
            rand1.reset()
        elif i == 7000:
            rand1.set_seed(2)

        vin = 1e-4 * i

        noise1 = 0.01 * rand1.inp() + 0.2

        vco.inp(vin + noise1)

        v1.append(vin + noise1)
        v2.append(noise1)
        v3.append(vco.out)

    ax1 = plt.subplot(311)
    plt.plot(v1)
    plt.ylabel("in")

    plt.subplot(312, sharex=ax1)
    plt.plot(v2)
    plt.ylabel("noise")

    plt.subplot(313, sharex=ax1)
    plt.plot(v3)
    plt.ylabel("vco")
    #plt.ylim([-1.5,1.5])
    plt.show()
Ejemplo n.º 4
0
import numpy as np
import matplotlib.pyplot as plt
import os

os.sys.path.append("../.")
from pysim import Divider, Vco, Reg

if __name__ == "__main__":
    Ts = 1e-9
    vco = Vco("fc + Kv*x", "fc,Kv,Ts", 10e6, 1e6, Ts)
    divider = Divider()

    vout_vco = []
    vout_div = []
    vreg1_out = []
    vreg2_out = []
    lat1_out = []
    lat2_out = []

    reg1 = Reg()
    reg2 = Reg()

    for i in range(10000):

        vin = 1e-4 * i
        vco.inp(vin)  #frequency will gradually increase since in is a ramp
        divider.inp(vco.out, 10)  # divide down VCO frequency by a factor of 10

        reg1.inp(divider.out, vco.out)
        reg2.inp(divider.out, vco.out, -1.0, reg1.out)
Ejemplo n.º 5
0
def test_BBCDR():
    Ts = 1.0/15e9

    vco = Vco("fc + Kv*x","fc,Kv,Ts",2.5e9,50e6,Ts)
    prbs_data = SigGen("prbs",2.502e9,Ts)
    reg1 = Reg()
    latch1 = Latch()

    xor1 = Xor()
    xor2 = Xor()

    int_filt = Filter("1","C*s","C,Ts",2e-9,Ts)
    rc_filt =Filter("R","1+1/(2*pi*fp)*s","R,fp,Ts",1.07e3,40e6,Ts)

    vco_period = EdgeMeasure()
    in_period = EdgeMeasure()

    randg = Rand("gauss")

    # VCO noise
    N_dBc = -100.0 # -90dBc/Hz at 1MHz offset
    f_off = 1e6
    Kv = 30e6

    noise_var = np.power(10,N_dBc/10.0)*np.power(f_off/Kv,2)
    

    v1 = []
    v2 = []
    v3 = []
    v4 = []
    v5 = []


    for i in xrange(500000):
        in_ = prbs_data.inp(0.0) # set jitter to zero
        
        # Hogge PD
        reg1.inp(in_,vco.out)
        latch1.inp(reg1.out,vco.out)
        xor1.inp(in_,reg1.out)
        xor2.inp(reg1.out,latch1.out)

        pd_out = xor1.out-xor2.out

        # charge pump

        chp_out = 150e-6*pd_out

        #loop filter
        vco_in = int_filt.inp(chp_out) + rc_filt.inp(chp_out)
        vco_in += np.sqrt(noise_var/Ts)*randg.inp() # add VCO noise

        #VCO
        vco.inp(vco_in)

        #
        v1.append(vco_period.inp(vco.out))
        v2.append(in_period.inp(prbs_data.square))
        v3.append(vco_in)
        v4.append(int_filt.out)
        v5.append(pd_out)

    ax1 = plt.subplot(511)
    plt.plot(v1)
    plt.subplot(512,sharex=ax1)
    plt.plot(v2)

    plt.subplot(513,sharex=ax1)
    plt.plot(v3)
    plt.subplot(514,sharex=ax1)
    plt.plot(v4)
    plt.subplot(515,sharex=ax1)
    plt.plot(v5)
    #plt.ylim([-0.5,2.5])
    plt.show()
    np.save("vco_period",v1)
    np.save("in_period",v2)
Ejemplo n.º 6
0
def test_case5():
    Ts = 1e-9
    vco = Vco("fc + Kv*x","fc,Kv,Ts",10e6,1e6,Ts) 
    vco.set_phase(2)
Ejemplo n.º 7
0
def test_case4():
    Ts = 1e-9
    vco = Vco("fc + Kv*x","fc,Kv,Ts",10e6,1e6,Ts) 
    vco.set("fc + Kv*x","fc,Kv,Ts",10e6,1e6,1e-10)
    print vco._sample_period
Ejemplo n.º 8
0
def test_case3():
    vco = Vco("fc + Kv*x","fc,Kv",10e6,1e6)
Ejemplo n.º 9
0
def test_case2():
    Ts = 1e-40
    vco = Vco("fc + Kv*x","fc,Kv,Ts",10e6,1e6,Ts)
Ejemplo n.º 10
0
def test_BBCDR():
    Ts = 1.0 / 15e9

    vco = Vco("fc + Kv*x", "fc,Kv,Ts", 2.5e9, 50e6, Ts)
    prbs_data = SigGen("prbs", 2.502e9, Ts)
    reg1 = Reg()
    reg2 = Reg()
    reg3 = Reg()
    latch1 = Latch()

    xor1 = Xor()
    xor2 = Xor()

    int_filter = Filter("2*pi*40e9", "s", "Ts", Ts)

    vco_period = EdgeMeasure()
    in_period = EdgeMeasure()

    randg = Rand("gauss")

    # VCO noise
    N_dBc = -90.0  # -90dBc/Hz at 1MHz offset
    f_off = 1e6
    Kv = 50e6

    noise_var = np.power(10, N_dBc / 10.0) * np.power(f_off / Kv, 2)

    v1 = []
    v2 = []
    v3 = []
    v4 = []
    v5 = []

    for i in range(300000):
        in_ = prbs_data.inp(0.0)  # set jitter to zero

        # Bang-bang PD
        reg1.inp(in_, vco.out)
        reg2.inp(reg1.out, vco.out)
        reg3.inp(in_, -vco.out)
        latch1.inp(reg3.out, -vco.out)
        xor1.inp(reg1.out, latch1.out)
        xor2.inp(reg2.out, latch1.out)

        pd_out = xor1.out - xor2.out

        # charge pump

        chp_out = 1e-6 * pd_out

        #loop filter
        vco_in = int_filter.inp(chp_out) + chp_out * 125e3
        vco_in += np.sqrt(noise_var / Ts) * randg.inp()  # add VCO noise

        #VCO
        vco.inp(vco_in)

        #
        v1.append(vco_period.inp(vco.out))
        v2.append(in_period.inp(prbs_data.square))
        v3.append(int_filter.out)
        v4.append(pd_out)
        v5.append(prbs_data.out)

    ax1 = plt.subplot(411)
    plt.plot(v1)
    plt.subplot(412, sharex=ax1)
    plt.plot(v2)

    plt.subplot(413, sharex=ax1)
    plt.plot(v3)
    plt.subplot(414, sharex=ax1)
    plt.plot(v4)

    #plt.ylim([-0.5,2.5])
    plt.show()