#!/usr/bin/env python3 """ Test the functions in lib concerning beacon generation and phase measuring work correctly together. """ import matplotlib.pyplot as plt import numpy as np import lib seed = 12345 dt = 1 # ns frequency = 45e-3 # GHz N = 5e2 t = np.arange(0, 10*int(1e3), dt, dtype=float) rng = np.random.default_rng(seed) phase_res = np.zeros(int(N)) # Vary both the base time and the phase t_extra = 0 for i in range(int(N)): # Change timebase t -= t_extra t_extra = (2*rng.uniform(size=1) - 1) *1e3 t += t_extra # Randomly phased beacon phase = lib.phase_mod(np.pi*(2*rng.uniform(size=1) -1)) # rad beacon = lib.sine_beacon(frequency, t, t0=0, phase=phase) if True: # blank part of the beacon blank_low, blank_high = 2*int(1e3), 4*int(1e3) beacon[blank_low:blank_high] = 0 measured = lib.find_beacon_in_traces([beacon], t, frequency, frequency_fit=False) phase_res[i] = lib.phase_mod(measured[1][0] - phase) fig, ax = plt.subplots() ax.set_title("Sine beacon phase determination\nwith random time shifts") ax.set_xlabel("$\\varphi_{meas} - \\varphi_{true}$ [rad]") ax.set_ylabel("#") ax.hist(phase_res, bins='sqrt') plt.show()