-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexamine_log_from_debug_program.py
62 lines (52 loc) · 1.38 KB
/
examine_log_from_debug_program.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Dennis van Gils
27-07-2021
"""
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(0, 0)
fig.show()
fig.canvas.draw()
fn = "log.txt"
with open(fn, "r") as file:
filedata = file.read()
filedata = filedata.replace("draw", "")
filedata = filedata.replace("samples received: 2500", "")
with open(fn, "w") as file:
file.write(filedata)
# fmt: off
a = np.loadtxt(fn)
time = np.array(a[:, 0])
ref_X = np.array(a[:, 1])
ref_Y = np.array(a[:, 2])
sig_I = np.array(a[:, 3])
# fmt: on
# time = time - time[0]
time_diff = np.diff(time)
print("time_diff:")
print(" median = %i usec" % np.median(time_diff))
print(" mean = %i usec" % np.mean(time_diff))
print(" min = %i usec" % np.min(time_diff))
print(" max = %i usec" % np.max(time_diff))
time_ = time[:-1]
time_gaps = time_[abs(time_diff) > 500]
time_gap_durations = time_diff[abs(time_diff) > 500]
print("\nnumber of gaps > 500 usec: %i" % len(time_gaps))
for i in range(len(time_gaps)):
print(
" gap %i @ t = %.3f msec for %.3f msec"
% (i + 1, time_gaps[i] / 1e3, time_gap_durations[i] / 1e3)
)
plt.plot(time / 1e3, ref_X, ".-k")
plt.plot(time / 1e3, ref_Y, ".-y")
plt.plot(time / 1e3, sig_I, ".-r")
plt.grid()
plt.xlabel("time (ms)")
plt.ylabel("voltage (V)")
plt.title(fn)
fig.canvas.draw()
plt.show(block=True)