58 lines
1.2 KiB
Python
58 lines
1.2 KiB
Python
|
#!/usr/bin/env python3
|
||
|
# coding: utf-8
|
||
|
|
||
|
import pylab as p
|
||
|
|
||
|
data = [
|
||
|
# SolarLader, Multimeter
|
||
|
[0, 0],
|
||
|
[0.412, 0.388],
|
||
|
[0.421, 0.392],
|
||
|
[0.64, 0.591],
|
||
|
[0.72, 0.655],
|
||
|
[0.78, 0.705],
|
||
|
[1, 0.903],
|
||
|
[1.05, 0.928],
|
||
|
[1.2, 1.04],
|
||
|
[1.36, 1.17],
|
||
|
[1.4, 1.205],
|
||
|
[1.706, 1.470],
|
||
|
[1.93, 1.58],
|
||
|
[2, 1.661],
|
||
|
[2.01, 1.683],
|
||
|
[2.08, 1.69],
|
||
|
[2.22, 1.78],
|
||
|
[2.27, 1.815],
|
||
|
]
|
||
|
|
||
|
data_array = p.transpose(p.array(data))
|
||
|
|
||
|
Ichg = data_array[0]
|
||
|
Imulti = data_array[1]
|
||
|
|
||
|
adc = Ichg * 4096/8.6 + 89
|
||
|
|
||
|
fit = p.polyfit(adc, Imulti, 1)
|
||
|
|
||
|
poly = p.poly1d(fit)
|
||
|
|
||
|
#Ifit = adc**2 * fit[0] + adc * fit[1] + fit[2]
|
||
|
Ifit = poly(adc)
|
||
|
Ierror = Ifit - Imulti
|
||
|
|
||
|
adc_expanded = p.arange(0, 4095, 1)
|
||
|
Ifit_expanded = poly(adc_expanded)
|
||
|
|
||
|
#print("adc² • {:.3f} + adc • {:.3f} + {:.3f}".format(fit[0], fit[1], fit[2]))
|
||
|
print("adc • {:.3g} + {:.3g}".format(fit[0], fit[1]))
|
||
|
|
||
|
p.figure()
|
||
|
p.plot(adc, Imulti, 'rx')
|
||
|
p.plot(adc, Ifit, 'r-')
|
||
|
p.figure()
|
||
|
p.plot(adc, Imulti, 'rx')
|
||
|
p.plot(adc_expanded, Ifit_expanded, 'b-')
|
||
|
p.figure()
|
||
|
p.plot(adc, Ierror)
|
||
|
p.show()
|