em = -np.cumsum(2 * np.pi * KDCO1 * np.diff(x) * (1 / float(FS)))
em_pn = make_signal(em, fs=FS)
em_pn = debias_pn(em_pn, 0.5 * SIM_SPAN)
plot_td(em_pn, tmax=PLOT_SPAN, title="Emergent PN", dots=True)

plt.subplot(3, 3, 9)
pn = copy(pn_sig.td[int(np.ceil(GEAR_SW_T * FCLK)):])
em = copy(em_pn.td[int(np.ceil(GEAR_SW_T * FCLK)):])
pn[np.abs(pn) > 3 * rms] = np.nan
em[np.abs(em) > 3 * rms] = np.nan
plt.hist(pn, alpha=0.5, bins=50, density=True)
plt.hist(em, alpha=0.5, bins=50, density=True)

plt.figure(2)
plot_pn_ssb2(pn_sig,
             dfmax=PN_FMAX,
             line_fit=False,
             tmin=GEAR_SW_T * PN_CALC_SAFETY_FACTOR)
plot_pn_ar_model(pn_sig, p=200, tmin=GEAR_SW_T * PN_CALC_SAFETY_FACTOR)
# rpm = noise_power_ar_model(pn_sig, fmax=FCLK/2, p=200, tmin=GEAR_SW_T)
# print("int rpm = ", np.sqrt(rpm))

plot_pn_ar_model(em_pn, p=200, tmin=GEAR_SW_T * PN_CALC_SAFETY_FACTOR)
plot_pi_pll_bbpd_pn(**lfs["bbpd"])
plot_pi_pll_osc_pn(DCO_PN, DCO_PN_DF, **lfs["bbpd"])
# plot_osc_pn_ideal(DCO_PN, DCO_PN_DF)
plt.show()

# plt.scatter(em_pn.td[int(np.ceil(GEAR_SW_T*FCLK)):],pn_sig.td[int(np.ceil(GEAR_SW_T*FCLK)):])
# plt.show()
Exemple #2
0
tdc_sig = make_signal(td=tdc_out[PLOT_SLICE], fs=FS)
bbpd_sig = make_signal(td=bbpd_out[PLOT_SLICE], fs=FS)
error_sig = make_signal(td=error[PLOT_SLICE], fs=FS)

# plt.subplot(2,3,1)
# plot_td(clk_sig, title="CLK")
# razavify()
plt.subplot(2, 3, 1)
plot_td(osc_freq, title="Inst. DCO Frequency")
# razavify()
plt.subplot(2, 3, 2)
plot_td(pn_sig, title="Phase error (noise)")
# razavify()
plt.subplot(2, 3, 3)
plot_td(tdc_sig, title="TDC/PD Output", label="TDC")
plot_td(bbpd_sig, title="BBPD Output", label="BBPD")
plot_td(error_sig, title="Error Output", label="Combined Error")
plt.legend()
# razavify()
plt.subplot(2, 3, 4)
plot_td(lf_sig, title="Loop Filter Output")
# razavify()
plt.subplot(2, 3, 5)
plot_pn_ssb2(pn_sig_full, dfmax=PN_FMAX, line_fit=False)
plot_lf_ideal_pn(RO_POWER, TEMP, **lf_params)
plt.grid()
# plot_fd(osc_sig_full)
# razavify()
adjust_subplot_space(2, 2, 0.1, 0.1)
plt.show()
Exemple #3
0
fs = 16e6
dt = 1 / fs

steps = 100000

pn = 10**(-80 / 10)
df = 1e6

krw = rw_gain(pn, df, steps, dt, m=1)
print("krw=", krw)
dco = DCO(kdco, f0, dt, krw=krw)

osc_sig = np.zeros(steps)
for n in range(steps):
    osc_sig[n] = dco.update(fctrl=0)

osc_sig = make_signal(td=osc_sig, fs=fs)

plot_pn_ssb2(osc_sig, line_fit=True)
#plot_pn_ar_model(osc_sig)
plt.legend()
plt.title(
    "DCO SSB Phase Noise [dBc/Hz],\n $\mathtt{krw}$ fitted to $L(\Delta f=10^6)$ = -80 dBc/Hz"
)
razavify(loc="lower left", bbox_to_anchor=[0, 0])
plt.xticks([1e2, 1e3, 1e4, 1e5, 1e6, 1e7],
           ["$10^2$", "$10^3$", "$10^4$", "$10^5$", "$10^6$", "$10^7$"])

plt.tight_layout()
plt.savefig("dco_rw_pn.pdf")
Exemple #4
0
em_pn = make_signal(em, fs=FS)
em_pn = debias_pn(em_pn, 0.5 * SIM_SPAN)
plot_td(em_pn, tmax=PLOT_SPAN, title="Emergent PN", dots=False)

plt.subplot(3, 3, 9)
pn = copy(pn_sig.td[int(np.ceil(GEAR_SW_T * FCLK)):])
em = copy(em_pn.td[int(np.ceil(GEAR_SW_T * FCLK)):])
pn[np.abs(pn) > 3 * rms] = np.nan
em[np.abs(em) > 3 * rms] = np.nan
plt.hist(pn, alpha=0.5, bins=50, density=True)
plt.hist(em, alpha=0.5, bins=50, density=True)

plt.figure(2)
plot_pn_ssb2(pn_sig,
             dfmax=PN_FMAX,
             line_fit=False,
             tmin=GEAR_SW_T * PN_CALC_SAFETY_FACTOR,
             label="$\\phi_n$")
plot_pn_ar_model(pn_sig,
                 p=200,
                 fmin=FBIN,
                 tmin=GEAR_SW_T * PN_CALC_SAFETY_FACTOR,
                 label="$\\phi_n$")
# rpm = noise_power_ar_model(pn_sig, fmax=FCLK/2, p=200, tmin=GEAR_SW_T)
# print("int rpm = ", np.sqrt(rpm))

plot_pn_ar_model(em_pn,
                 p=200,
                 fmin=FBIN,
                 tmin=GEAR_SW_T * PN_CALC_SAFETY_FACTOR,
                 label="$\\phi_{em}$")
Exemple #5
0
        label="BBPD",
        tmax=PLOT_SPAN)
plot_td(main_pn_data["error"],
        title="Error Output",
        label="Combined Error",
        tmax=PLOT_SPAN)
plt.legend()
# razavify()
plt.subplot(2, 3, 4)
# plot_td(lf_sig, title="Loop Filter Output", tmax=PLOT_SPAN)
plot_td(main_pn_data["lf"], title="Loop Filter Output", tmax=PLOT_SPAN)
# razavify()
plt.subplot(2, 3, 5)
# plot_pn_ssb2(spur_sig_full, dfmin=1e6, dfmax=PN_FMAX, line_fit=False, tmin=TSETTLE_EST)
# plot_pn_ssb2(pn_sig_full, dfmax=1e6, line_fit=False, tmin=TSETTLE_EST)
plot_pn_ssb2(pn_sig, dfmax=PN_FMAX, line_fit=False, tmin=MAX_TSETTLE)
# plot_pn_ssb2(spur_pn_sig, dfmin=1e6, dfmax=PN_FMAX, line_fit=False)
plot_lf_ideal_pn(DCO_POWER, TEMP, fmax=PN_FMAX, **lf_params)
plt.grid()
if RUN_SPURSIM:
    plt.subplot(2, 3, 6)
    plt.plot(spur_pn_data["lf"].td)
plt.xlabel("n")
plt.ylabel("OTW[n]")
plt.title("Steady state oscillator tuning word")
plt.grid()
# plt.subplot(2,3,6)
# plt.plot(spur_pn_data["lf"])

# plot_fd(osc_sig_full)
# razavify()
Exemple #6
0
# krw = 4*np.pi*np.sqrt(FS*s0)/np.sqrt((2*FS)**2 + (2*np.pi*PN_DF)**2)
# krw = 2*np.pi*np.sqrt(s0/FS)
krw = rw_gain_fom(fom_db=DCO_FOM, fosc=FOSC, power=DCO_POWER, fs=FS)
print("krw =", krw)
error = np.zeros(SIM_STEPS)
dco1 = DCOPhase(kdco1=0, kdco2=0, f0=FL_DCO, dt=1/float(FS), krw=krw,
               init_phase=0, quantize=False)
dco2 = DCOPhase(kdco1=0, kdco2=0, f0=FL_DCO, dt=1/float(FS), krw=0,
               init_phase=0, quantize=False)
for n in range(SIM_STEPS):
    error[n] = dco1.update(0,0)-dco2.update(0,0)
# print(error)
# plt.plot(error)


E = np.fft.fft(error)/np.sqrt(FS*SIM_STEPS)
plt.semilogx(f, 20*np.log10(np.abs(E[1:int(0.5*SIM_STEPS)])))
# plt.show()
K = np.average(np.abs(E[1:int(0.5*SIM_STEPS)])**2*f**2)
print("Fitted pn @ 1MHz = ", 10*np.log10(K/1e6**2))
print("rms_error =", np.std(error))
print("predicted rms error =", np.sqrt(2*K*(1/FBIN - 1/(0.5*FS))))
# plt.plot(K)
# plt.show()

pn_sig = make_signal(error, fs=FS)
plot_pn_ssb2(pn_sig, dfmax=PN_FMAX, line_fit=False, tmin=0)
plot_pn_ar_model(pn_sig, p=200, tmin=0)
plt.show()

Exemple #7
0
        main_pn_data = pllsim_int_n(verbose=False, **main_sim_params)
        pn_sig = pn_signal(main_pn_data, DIV_N)

        # pow_pn = np.mean(pn_sig.td**2)
        # print(pow_pn)
        pow_pn = 20 * np.mean((pn_sig.td)**2)
        print(KBBPD, pow_pn)
        # error.append(np.abs(pow_pn - est_pow_pn))
        return pow_pn

    return cost


cost = kbbpd_cost(est_pow_pn)

print(gss(cost, arg="KBBPD", params={}, _min=0, _max=0.3, max_iter=15))

for x, y in zip(np.geomspace(0.01, 0.1, 11), error):
    print(x, y)

plt.subplot(2, 1, 1)
plot_td(pn_sig)
plt.subplot(2, 1, 2)
plt.plot(main_pn_data["osc"].td - DIV_N * main_pn_data["clk"].td)
plt.show()
plot_pn_ssb2(pn_sig, dfmax=8e8, line_fit=False)
plot_pn_ar_model(pn_sig, p=200, tmin=0)
plot_lf_ideal_pn(DCO_PN, DCO_PN_DF, **lf_params)
print(noise_power_ar_model(pn_sig, fmax=FCLK / 2, p=100))
plt.show()