def test_case7(): # a RC filter Ts = 1.0 / 4e3 r = 10e3 c = 100e-6 RC_filter = Filter("1", "1+r*c*s", "r,c,Ts", r, c, Ts) vin = 0.0 v1 = [] v2 = [] for i in range(-4000, 20000): if i > 0: vin = 10.0 RC_filter.inp(vin) v1.append(vin) v2.append(RC_filter.out) #t = np.arange t = np.arange(-4000, 20000) * Ts plt.plot(t, v1, label="Va") plt.plot(t, v2, label="Vb") plt.grid() plt.ylim([-1, 11]) plt.legend(loc="best") plt.show()
def test_case2(): int_filt = Filter("3+4*s+5*s^2", "6+7*s+8*s^2", "Ts", 1e-9) print int_filt.inp(0.2) print int_filt.inp(0.3) int_filt.reset(0) print int_filt.inp(0.4)
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()
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)
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()
def test_case6(): sample_per = 1e-6 double_integ = Filter("K", "s^2", "K,Ts", 1e5, sample_per) diff = Filter("s", "1", "Ts", sample_per)
def test_case1(): list1 = [1.0, -2.0, 1.0] #double_accum = Filter("1",list1) Filter("3+4*z^-1+5*z^-2", "6+7*z^-1+8*z^-2", "Ts", 1e-9)
def test_case5(): sample_per = 1e-6 double_integ = Filter("K", "s^2", "K,Ts", 1e5, sample_per) diff = Filter("s", "1", "Ts", sample_per) v1 = [] v2 = [] v3 = [] in_ = 1.0 for i in range(1000): if i == 200: in_ = -1.0 elif i == 400: in_ = 2.0 elif i == 700: double_integ.reset(0.0) diff.reset(0.0) # cascade double_integ.inp(in_) diff.inp(double_integ.out) v1.append(in_) v2.append(double_integ.out) v3.append(diff.out) ax1 = plt.subplot(311) plt.plot(v1) plt.subplot(312, sharex=ax1) plt.plot(v2) plt.subplot(313, sharex=ax1) plt.plot(v3) plt.show()
def test_case4(): list1 = [1.0, -2.0, 1.0] double_accum = Filter("1", list1) first_diff = Filter("1-z^-1", "1") v1 = [] v2 = [] v3 = [] in_ = 1.0 for i in range(1000): if i == 200: in_ = -1.0 elif i == 400: in_ = 2.0 elif i == 700: double_accum.reset(0.0) first_diff.reset(0.0) # cascade double_accum.inp(in_) first_diff.inp(double_accum.out) v1.append(in_) v2.append(double_accum.out) v3.append(first_diff.out) ax1 = plt.subplot(311) plt.plot(v1) plt.subplot(312, sharex=ax1) plt.plot(v2) plt.subplot(313, sharex=ax1) plt.plot(v3) plt.show()
def test_case3(): int_filt = Filter("3 + 8.1*s^3 - 5.2*s^5", "6.3+2.4*s^2+3.5*s^3", "Ts", 1e-9)