-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasic.py
75 lines (63 loc) · 1.25 KB
/
basic.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
'''
Colection of very basic electronics calcs.
'''
def sum(*x):
'''
Sum of values.
'''
from numpy.core.fromnumeric import sum as _sum
return _sum(x)
def sum_inv(*x):
'''
Sum of inverses.
1/(1/x+1/y+1/z...)
'''
return 1.0/sum([1.0/i for i in x])
def res_parallel(*r):
'''
Caluclate the resistance of a parallel
combination of resistors.
*r = any number of resistors.
'''
return sum_inv(*r)
def cap_series(*c):
'''
Caluclate the capacitance of a series
combination of capacitors.
*c = any number of capacitors.
'''
return sum_inv(*c)
def pot_div_ratio(r1, r2):
'''
vin--[r1]--vout--[r2]--gnd
'''
return float(r2)/(r1+r2)
def pot_div(v1, r1, r2, v2=0):
'''
v1--[r1]--return--[r2]--v2
'''
return (v1-v2)*pot_div_ratio(r1,r2)+v2;
def x_cap(c, f):
'''
Calulate reactance of a capacitor.
'''
from math import pi
return -1.0/(2.0*pi*f*c)
def x_cap_i(x, f):
'''
Calulate capacitor for a reactance.
'''
from math import pi
return -1.0/(2.0*pi*f*x)
def x_ind(l, f):
'''
Calculate reactance of an inductor.
'''
from math import pi
return 2.0*pi*f*l
def x_ind_i(x, f):
'''
Calculate infuctor for a reactance.
'''
from math import pi
return x/(2.0*pi*f)