-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelaxation_oscillator_data_gen.py
103 lines (77 loc) · 1.87 KB
/
relaxation_oscillator_data_gen.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import numpy as np
from numpy import sin, cos, exp, pi
mu=1e-6
C=200*mu
V=90
R=10000
tau=R*C
V_b=80
V_e=40
t_e=-tau*np.log((V-V_e)/V)
T=R*C*np.log((V-V_e)/(V-V_b))
nt=1000
data_dict={}
data_dict["capacitor"]=C
data_dict["batter voltage"]=V
data_dict["resistor"]=R
data_dict["time constant"]=tau
data_dict["breakdown voltage"]=V_b
data_dict["extinction voltage"]=V_e
data_dict["period"]=T
data_dict["extinction time"]=t_e
nt=1000
t=np.linspace(0,5*T,nt)
dt=t[1]-t[0]
Vn=np.zeros(t.size)
def voltage(t):
return V*(1-exp(-t/tau))
t_eval=0
for i in range(nt):
v=voltage(t_eval)
if v >=V_b:
#print(t_eval,t[i])
t_eval=t_e
v=voltage(t_eval)
Vn[i]=v
t_eval+=dt
data_dict={}
data_dict["capacitor"]=C
data_dict["batter voltage"]=V
data_dict["resistor"]=R
data_dict["time constant"]=tau
data_dict["breakdown voltage"]=V_b
data_dict["extinction voltage"]=V_e
data_dict["period"]=T
data_dict["extinction time"]=t_e
data_dict["voltage data"]={"voltage":Vn, "time":t}
t=np.linspace(0,T,1000)
# make periodic data
v=V*(1-exp(-(t+t_e)/tau))
t=np.r_[t, t+T, t+2*T, t + 3*T]
v=np.r_[v,v,v,v]
data_dict["periodic voltage data"]={"voltage":v, "time":t}
# make Fourier data
nmax=500
n=np.arange(1,nmax+1)
an=np.zeros(nmax)
bn=np.zeros(nmax)
wn=np.zeros(nmax)
hn=np.zeros((nmax,t.size))
pf=-2*V/T*exp(-t_e/tau)
for i in range(nmax):
wn[i]=2*pi*(i+1)/T
val=(1/tau)**2 + wn[i]**2
den=1/val
an[i]=pf*den*1/tau*(1-exp(-T/tau))
bn[i]=pf*wn[i]*den*(1-exp(-T/tau))
hn[i,:]=an[i]*cos(wn[i]*t) + bn[i]*sin(wn[i]*t)
a0=V/T*(T + tau*exp(-t_e/tau)*exp(-T/tau)-tau*exp(-t_e/tau))
Fourier_dict={}
Fourier_dict["a_0"]=a0
Fourier_dict["a_n"]=an
Fourier_dict["b_n"]=bn
Fourier_dict["harmonics"]=hn
Fourier_dict["omega_n"]=wn
Fourier_dict["n"]=n
Fourier_dict["time"]=t
data_dict["Fourier data"]=Fourier_dict