forked from Ledger-Donjon/silicon-toaster
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot-calibration.py
More file actions
executable file
·49 lines (38 loc) · 880 Bytes
/
plot-calibration.py
File metadata and controls
executable file
·49 lines (38 loc) · 880 Bytes
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
#!/usr/bin/python3
import matplotlib.pyplot as plt
import quicklog
import numpy as np
x = []
y = []
plt.figure()
for record in quicklog.read_log("calibration-800.log"):
x.append(float(record["value"]))
y.append(float(record["voltage"]))
plt.plot(x, y)
coefs = np.polyfit(x, y, 4)
poly = np.poly1d(coefs)
print("Raw->Volt", coefs)
coefs_inv = np.polyfit(y, x, 4)
poly_inv = np.poly1d(coefs_inv)
print("Volt->Raw", coefs_inv)
plt.figure()
x = np.linspace(0, max(x), 100)
y = []
for xx in x:
v = 0
for i, c in enumerate(coefs):
v += c * xx ** (len(coefs) - i - 1)
y.append(v)
plt.plot(x, y)
# plt.plot(x, poly(x))
y = np.linspace(0, max(y), 100)
x = []
for yy in y:
v = 0
for i, c in enumerate(coefs_inv):
v += c * yy ** (len(coefs_inv) - i - 1)
x.append(v)
plt.figure()
plt.plot(x, y)
# plt.plot(x, poly_inv(x))
plt.show()