1
0

scan_analysis.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. evaluate the offset for the various gains
  3. """
  4. from struct import*
  5. import ctypes
  6. import array
  7. import numpy as np
  8. import matplotlib.pyplot as plt
  9. import time
  10. from scipy import stats
  11. ADC = np.load("tmp.npy")
  12. V = np.linspace(0,990,1000)
  13. slope = np.zeros(7)
  14. for g in range(1,8):
  15. k=0
  16. while ADC[g-1,k]<10:
  17. k+=1
  18. start = k
  19. while (k<1000 and ADC[g-1,k]<4000):
  20. k+=1
  21. stop = k
  22. slope[g-1], intercept,t_value,p_value,std_err = stats.linregress(V[start:stop],ADC[g-1,start:stop])
  23. plt.plot(V[start:stop],ADC[g-1,start:stop])
  24. plt.plot(V,slope[g-1]*V+intercept,':',color='black')
  25. print(slope[g-1])
  26. print(intercept)
  27. plt.ylim(-10,4100)
  28. plt.xlim(-1,810)
  29. plt.xlabel("Voffset")
  30. plt.ylabel("ADC")
  31. plt.title("Gain from 2 to 128")
  32. plt.grid()
  33. plt.show()
  34. G = [1.63/0.62,3.044/1.63,4.66/3.044,6.15/4.66,7.24/6.15,7.926/7.24]
  35. Gth = [3,7.0/3,15.0/7,31.0/15,63/31,127/63]
  36. B=slope
  37. for g in range(2,8):
  38. G[g-2] = slope[g-1]/slope[g-2]
  39. for g in range(1,8):
  40. B[g-1]=slope[g-1]/(2**g-1)
  41. plt.plot(G)
  42. plt.plot(Gth)
  43. plt.show()
  44. plt.plot(B)
  45. plt.xlabel("Gain G from 2 to 128")
  46. plt.ylabel("B")
  47. #plt.title("Gain from 2 to 128")
  48. plt.grid()
  49. plt.show()