-
Notifications
You must be signed in to change notification settings - Fork 0
/
FinePhasingRandomTest.py
63 lines (50 loc) · 1.81 KB
/
FinePhasingRandomTest.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
63
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 20 06:40:24 2021
@author: bob
"""
import math
import numpy as np
import matplotlib.pyplot as plt
Energy=1500 #Energy=[250,750,1500]
Dispersion = 0.47 #Dispersion = [0.275,0.443,0.47]
reSolution = 30e-6 #reSolution=[25e-6,25e-6,30e-6]
def truncate(number, decimals=0):
"""
Returns a value truncated to a specific number of decimal places.
"""
if not isinstance(decimals, int):
raise TypeError("decimal places must be an integer.")
elif decimals < 0:
raise ValueError("decimal places has to be 0 or more.")
elif decimals == 0:
return math.trunc(number)
factor = 10.0 ** decimals
return math.trunc(number * factor) / factor
def fitOut(offSet):
degRees = []
outPut=[]
for i in range(-5,6,1):
#point=-16*math.cos(math.radians(offSet-90+i))+16*math.cos(math.radians(offSet+90+i))
plusNinety=(16*math.cos(math.radians(offSet+90+i))*Dispersion)/Energy + (np.random.rand()-0.5)*reSolution
minusNinety=(-16*math.cos(math.radians(offSet-90+i))*Dispersion)/Energy + (np.random.rand()-0.5)*reSolution
point = truncate(minusNinety,5) + truncate(plusNinety,5)
degRees.append(i)
outPut.append(point)
y=np.array(degRees)
x=np.array(outPut)
A = np.vstack([x, np.ones(len(x))]).T
m, c = np.linalg.lstsq(A, y, rcond=None)[0]
return c
#plt.plot(degRees,outPut)
#plt.xlabel('zero crossing at '+str(-c))
#plt.show()
if __name__ == "__main__":
deltaDeg=[]
zeroCross=[]
for i in range(0,10000):
tempPhase=(i-5000)/10000
deltaDeg.append(tempPhase)
zeroCross.append(fitOut(tempPhase))
plt.plot(deltaDeg,zeroCross)
plt.show()