import pandas as pd
import numpy as np
import math
import matplotlib.pyplot as plt
df = pd.read_csv('Data1.txt') # read in the data taken previously
T = df.Time
VD = df.Vo
VO = df.Vd
plt.plot(T, VO * 2.0 / 16383, label='Vd')
plt.plot(T, VD * 2.0 / 16383, label='Vo')
plt.legend()
plt.xlabel('time (s)')
plt.ylabel('voltage (V)')
R = 130
Vd = df.Vd[140:195] * 2.0 / 16383
Vo = df.Vo[140:195] * 2.0 / 16383
V = Vd - Vo
I = V / R
A, B = np.polyfit(np.log(I), Vd, 1)
Vth = A*np.log(I) + B
Bconst = 1.380649 * 10**-23
Echarge = 1.602176634 * 10**-19
Tabs = 294.27 # or 70 degrees farenheit
N = (A*Echarge) / (Tabs * Bconst)
Io = 2.71828**(-B/A)
print("N: "+ str(N) + " Io: " + str(Io))
plt.plot( np.log(I), Vd, 'b.')
plt.plot(np.log(I), Vth, 'r-')
plt.xlabel("Natural Log of Current")
plt.ylabel("Voltage Drop")
N: 5.012052797910366 Io: 2.4623155994260655e-10
mu = 25
std = 6
N = 10000
xs = np.random.normal(loc=mu, scale=std, size=N)
res = plt.hist(xs,bins = 20)
xs = np.array(sorted(xs))
zs = np.array(sorted(np.random.normal(loc=0, scale=1.0, size=N)))
plt.plot(zs,xs,'b.')
plt.plot(zs, zs*std + mu,'r-')
print("x > 35 =", len(xs[xs>35])/N)
x > 35 = 0.045