forked from lasseufpa/ptp-dal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kalman_demo.py
executable file
·66 lines (51 loc) · 1.84 KB
/
kalman_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
"""Experiment with Kalman Filter
Compare Kalman to LS
Suggested experiments:
- Set pdv_distr to "Gaussian" in order to experiment with Gaussian-distributed
time offset noise.
- Change the freq_rw = 1e-18 to control how fast the frequency offset changes
over time.
- Change the LS window length as it substantially affects the LS result.
- Change the transition and observation covariance matrices within the Kalman
implementation.
- Change the delta of the frequency estimator to see how it affects Kalman
performance.
"""
import ptp.simulation
import ptp.ls
import ptp.kalman
import ptp.metrics
import ptp.frequency
# Run PTP simulation
n_iter = 1e3
simulation = ptp.simulation.Simulation(n_iter = n_iter, pdv_distr="Gamma",
freq_rw = 1e-18)
simulation.run()
# Least-squares estimator
N = 128
ls = ptp.ls.Ls(N, simulation.data)
ls.process()
# Raw frequency estimations (differentiation of raw time offset measurements)
freq_estimator = ptp.frequency.Estimator(simulation.data, delta=1)
freq_estimator.process()
# Kalman
kalman = ptp.kalman.Kalman(simulation.data, simulation.sync_period)
kalman.process()
# PTP analyser
analyser = ptp.metrics.Analyser(simulation.data)
analyser.plot_toffset_vs_time(show_ls=True,
show_kf=True,
save=True)
analyser.plot_toffset_err_vs_time(show_ls=True,
show_kf=True,
show_raw=False,
save=True)
analyser.plot_foffset_vs_time(show_ls=True,
show_kf=True,
show_raw=False,
save=True)
analyser.plot_mtie(show_ls=True,
show_kf=True,
show_raw=False,
save=True)