-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABCDmatrixcalc.py
More file actions
78 lines (48 loc) · 2.21 KB
/
ABCDmatrixcalc.py
File metadata and controls
78 lines (48 loc) · 2.21 KB
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
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 14 21:30:26 2020
@author: Adam
"""
import numpy as np
def ABCDmatrixcalc(array): # calculates the ABCD matrix for a given array of circuit data
matrix1=np.zeros((2,2), dtype=complex)
matrix2=np.zeros((2,2), dtype=complex) # predefine temp storage matrices to do the ABCD calculation
tempmatrix=np.zeros((2,2), dtype=complex)
flag=1
if array[1] == 0: # define the first ABCD matrix if it's a shunt impedance
matrix1[0,0] = 1
matrix1[0,1] = 0
matrix1[1,0] = 1/(array[2])
matrix1[1,1] = 1
else: # else it's a series impedance, define first ABCD matrix using series impedance formula
matrix1[0,0] = 1
matrix1[0,1] = array[2]
matrix1[1,0] = 0
matrix1[1,1] = 1
for i in range (5,len(array),3):
if flag == 1: # flag=1 means it's the first iteration of the loop, calculate stuff a little differently
flag = 0
if array[4] == 0: # checks if it's a shunt
tempmatrix[0,0] = 1
tempmatrix[0,1] = 0
tempmatrix[1,0] = 1/(array[5])
tempmatrix[1,1] = 1
else: # else it's a series impedance
tempmatrix[0,0] = 1
tempmatrix[0,1] = array[5]
tempmatrix[1,0] = 0
tempmatrix[1,1] = 1
matrix2 = matrix1 @ tempmatrix
else:
if array[i-1] == 0: # it's a shunt
tempmatrix[0,0] = 1
tempmatrix[0,1] = 0
tempmatrix[1,0] = 1/(array[i])
tempmatrix[1,1] = 1
else: # else it's a series impedance
tempmatrix[0,0] = 1
tempmatrix[0,1] = array[i]
tempmatrix[1,0] = 0
tempmatrix[1,1] = 1
matrix2 = matrix2 @ tempmatrix
return matrix2