mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-11-13 01:53:31 +01:00
ZH: test script for true_phase/calculated phase at tx
This commit is contained in:
parent
2e227d1765
commit
a4fa874b54
2 changed files with 73 additions and 1 deletions
|
@ -23,19 +23,28 @@ rng = np.random.default_rng(seed)
|
||||||
phase_res = np.zeros(int(N))
|
phase_res = np.zeros(int(N))
|
||||||
|
|
||||||
# Vary both the base time and the phase
|
# Vary both the base time and the phase
|
||||||
|
t_extra = 0
|
||||||
for i in range(int(N)):
|
for i in range(int(N)):
|
||||||
|
|
||||||
|
# Change timebase
|
||||||
|
t -= t_extra
|
||||||
t_extra = (2*rng.uniform(size=1) - 1) *1e3
|
t_extra = (2*rng.uniform(size=1) - 1) *1e3
|
||||||
t += t_extra
|
t += t_extra
|
||||||
|
|
||||||
|
# Randomly phased beacon
|
||||||
phase = lib.phase_mod(np.pi*(2*rng.uniform(size=1) -1)) # rad
|
phase = lib.phase_mod(np.pi*(2*rng.uniform(size=1) -1)) # rad
|
||||||
beacon = lib.sine_beacon(frequency, t, t0=0, phase=phase)
|
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)
|
measured = lib.find_beacon_in_traces([beacon], t, frequency, frequency_fit=False)
|
||||||
|
|
||||||
t -= t_extra
|
|
||||||
phase_res[i] = lib.phase_mod(measured[1][0] - phase)
|
phase_res[i] = lib.phase_mod(measured[1][0] - phase)
|
||||||
|
|
||||||
fig, ax = plt.subplots()
|
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_xlabel("$\\varphi_{meas} - \\varphi_{true}$ [rad]")
|
||||||
ax.set_ylabel("#")
|
ax.set_ylabel("#")
|
||||||
ax.hist(phase_res, bins='sqrt')
|
ax.hist(phase_res, bins='sqrt')
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Test the functions in lib concerning
|
||||||
|
beacon generation and removing the geometrical phase
|
||||||
|
work correctly together.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
from earsim import Antenna
|
||||||
|
import lib
|
||||||
|
|
||||||
|
seed = 12345
|
||||||
|
dt = 1 # ns
|
||||||
|
frequency = 45e-3 # GHz
|
||||||
|
N = 5e2
|
||||||
|
c_light = 3e8*1e-9
|
||||||
|
|
||||||
|
t = np.arange(0, 10*int(1e3), dt, dtype=float)
|
||||||
|
rng = np.random.default_rng(seed)
|
||||||
|
phase_in = lib.phase_mod(np.pi*(2*rng.uniform(size=1) -1)) # rad
|
||||||
|
|
||||||
|
tx = Antenna(x=0,y=0,z=0,name='tx')
|
||||||
|
rx = Antenna(x=30,y=40,z=120,name='rx')
|
||||||
|
|
||||||
|
# Vary both the base time and the phase
|
||||||
|
t_extra = 0
|
||||||
|
phase_res = np.zeros(int(N))
|
||||||
|
for i in range(int(N)):
|
||||||
|
# Change timebase
|
||||||
|
t -= t_extra
|
||||||
|
t_extra = (2*rng.uniform(size=1) - 1) *1e3
|
||||||
|
t += t_extra
|
||||||
|
|
||||||
|
# Randomise Antenna Location
|
||||||
|
if True:
|
||||||
|
rx.x, rx.y, rx.z = (2*rng.uniform(size=3) -1) * 1e4
|
||||||
|
|
||||||
|
# Randomly phased beacon
|
||||||
|
# at Antenna
|
||||||
|
phase = lib.phase_mod(np.pi*(2*rng.uniform(size=1) -1)) # rad
|
||||||
|
beacon = lib.beacon_from(tx, rx, frequency, t, radiate_rsq=False, phase=phase, c_light=c_light)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
calculated_phase = lib.remove_antenna_geometry_phase(tx, rx, frequency, measured[1][0], c_light=c_light)
|
||||||
|
|
||||||
|
phase_res[i] = lib.phase_mod(calculated_phase - phase)
|
||||||
|
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
ax.set_title("Measured phase at Antenna - geometrical phase")
|
||||||
|
ax.set_xlabel("$\\varphi_{meas} - \\varphi_{true}$ [rad]")
|
||||||
|
ax.set_ylabel("#")
|
||||||
|
ax.hist(phase_res, bins='sqrt')
|
||||||
|
plt.show()
|
||||||
|
|
Loading…
Reference in a new issue