diff --git a/ycx_complex_numbers/H.py b/ycx_complex_numbers/H.py index 62c09d1..f24847c 100644 --- a/ycx_complex_numbers/H.py +++ b/ycx_complex_numbers/H.py @@ -12,6 +12,7 @@ def __init__(self, c=None): class NetH(Net): + """H - (hybrid) 2-port-node parameters.""" def __init__(self, h11=None, h12=None, h21=None, h22=None): super().__init__(c11=H(h11), c12=H(h12), c21=H(h21), c22=H(h22)) @@ -40,6 +41,7 @@ def is_symmetrical(self): return self.determinant == 1 def to_a(self): + """Convert to ABCD parameters""" return cn.Neta( a11=-self.determinant / self.h21, a12=-self.h11 / self.h21, @@ -48,6 +50,7 @@ def to_a(self): ) def to_b(self): + """Convert to ABCD' parameters""" return cn.Netb( b11=1 / self.h12, b12=self.h11 / self.h12, @@ -59,6 +62,7 @@ def to_ABCD(self): return self.to_a() def to_Y(self): + """Convert to Y parameters""" return cn.NetY( y11=1 / self.h11, y12=-self.h12 / self.h11, @@ -67,6 +71,7 @@ def to_Y(self): ) def to_Z(self): + """Convert to Z parameters""" return cn.NetZ( z11=self.determinant / self.h22, z12=self.h12 / self.h22, @@ -75,6 +80,7 @@ def to_Z(self): ) def to_S(self, Z0=50 + 0j): + """Convert to S parameters""" hi = self.h11 / Z0 hr = self.h12 hf = self.h21 diff --git a/ycx_complex_numbers/S.py b/ycx_complex_numbers/S.py index 267b41b..629d902 100644 --- a/ycx_complex_numbers/S.py +++ b/ycx_complex_numbers/S.py @@ -13,6 +13,7 @@ def __init__(self, c=None): class NetS(Net): + """S - Scatter 2-port-node parameters.""" def __init__(self, s11=None, s12=None, s21=None, s22=None): super().__init__(c11=S(s11), c12=S(s12), c21=S(s21), c22=S(s22)) @@ -33,6 +34,7 @@ def s22(self): return self._c22 def to_Y(self, Z0=50 + 0j): + """Convert to Y parameters""" return NetY( y11=((1 + self.s22) * (1 - self.s11) + self.s12 * self.s21) / ((1 + self.s11) * (1 + self.s22) + self.s12 * self.s21) @@ -49,6 +51,7 @@ def to_Y(self, Z0=50 + 0j): ) def to_Z(self, Z0=50+0j): + """Convert to Z parameters""" d = (1 - self.s11) * (1 - self.s22) - self.s12 * self.s21 return cn.NetZ( z11=((1 + self.s11) * (1 - self.s22) + self.s12 * self.s21) / d * Z0, @@ -58,6 +61,7 @@ def to_Z(self, Z0=50+0j): ) def to_a(self): + """Convert to ABCD parameters""" d = 2 * self.s21 return cn.Neta( a11=((1 + self.s11) * (1 - self.s22) + self.s12 * self.s21) / d, @@ -67,6 +71,7 @@ def to_a(self): ) def to_H(self, Z0=50 + 0j): + """Convert to H parameters""" d = (1 - self.s11) * (1 + self.s22) + self.s12 * self.s21 return cn.NetH( h11=((1 + self.s11) * (1 + self.s22) - self.s12 * self.s21) / d * Z0, diff --git a/ycx_complex_numbers/Y.py b/ycx_complex_numbers/Y.py index 477f087..5a77050 100644 --- a/ycx_complex_numbers/Y.py +++ b/ycx_complex_numbers/Y.py @@ -19,6 +19,7 @@ def B(self): return self._c.imag class NetY(Net): + """Y - Admittance 2-port-node parameters.""" def __init__(self, y11=None, y12=None, y21=None, y22=None): super().__init__(c11=Y(y11), c12=Y(y12), c21=Y(y21), c22=Y(y22)) @@ -47,6 +48,7 @@ def is_symmetrical(self): return self.y11 == self.y22 def to_a(self): + """Convert to ABCD parameters""" return cn.Neta( a11=-self.y22 / self.y21, a12=-1 / self.y21, @@ -55,6 +57,7 @@ def to_a(self): ) def to_b(self): + """Convert to ABCD' parameters""" return cn.Netb( b11=-self.y11 / self.y12, b12=-1 / self.y12, @@ -66,6 +69,7 @@ def to_ABCD(self): return self.to_a() def to_H(self): + """Convert to H parameters""" return cn.NetH( h11=1 / self.y11, h12=-self.y12 / self.y11, @@ -74,6 +78,7 @@ def to_H(self): ) def to_Z(self): + """Convert to Z parameters""" return cn.NetZ( z11=self.y22 / self.determinant, z12=-(self.y12 / self.determinant), @@ -82,6 +87,7 @@ def to_Z(self): ) def to_S(self, Z0=50 + 0j): + """Convert to S parameters""" yi = self.y11 * Z0 yr = self.y12 * Z0 yf = self.y21 * Z0 diff --git a/ycx_complex_numbers/Z.py b/ycx_complex_numbers/Z.py index 8e2ebfb..5e5065c 100644 --- a/ycx_complex_numbers/Z.py +++ b/ycx_complex_numbers/Z.py @@ -19,6 +19,7 @@ def X(self): return self._c.imag class NetZ(Net): + """Z - Impedance 2-port-node parameters.""" def __init__(self, z11=None, z12=None, z21=None, z22=None): super().__init__(c11=Z(z11), c12=Z(z12), c21=Z(z21), c22=Z(z22)) @@ -47,6 +48,7 @@ def is_symmetrical(self): return self.z11 == self.z22 def to_a(self): + """Convert to ABCD parameters""" return cn.Neta( a11=self.z11 / self.z21, a12=self.determinant / self.z21, @@ -55,6 +57,7 @@ def to_a(self): ) def to_b(self): + """Convert to ABCD' parameters""" return cn.Netb( b11=self.z22 / self.z12, b12=self.determinant / self.z12, @@ -66,6 +69,7 @@ def to_ABCD(self): return self.to_a() def to_H(self): + """Convert to H parameters""" return cn.NetH( h11=self.determinant / self.z22, h12=self.z12 / self.z22, @@ -74,6 +78,7 @@ def to_H(self): ) def to_Y(self): + """Convert to Y parameters""" return cn.NetY( y11=self.z22 / self.determinant, y12=-self.z12 / self.determinant, @@ -82,6 +87,7 @@ def to_Y(self): ) def to_S(self, Z0=50 + 0j): + """Convert to S parameters""" zi = self.z11 / Z0 zr = self.z12 / Z0 zf = self.z21 / Z0 diff --git a/ycx_complex_numbers/a.py b/ycx_complex_numbers/a.py index 0eefee2..bfa26cd 100644 --- a/ycx_complex_numbers/a.py +++ b/ycx_complex_numbers/a.py @@ -3,7 +3,7 @@ class a(Complex): - """ABCD - A ABCD (fwd Chain/Cascade/Transmission) parameters.""" + """ABCD - A ABCD (fwd Chain/Cascade/Transmission) parameter.""" _symbol = "a" @@ -12,6 +12,7 @@ def __init__(self, c=None): class Neta(Net): + """ABCD - An ABCD (fwd Chain/Cascade/Transmission) 2-port-node parameters.""" def __init__(self, a11=None, a12=None, a21=None, a22=None): super().__init__(c11=a(a11), c12=a(a12), c21=a(a21), c22=a(a22)) @@ -56,6 +57,7 @@ def is_symmetrical(self): return self.A == self.D def to_b(self): + """Convert to ABCD' parameters""" return cn.Netb( b11=self.D / self.determinant, b12=self.B / self.determinant, @@ -64,6 +66,7 @@ def to_b(self): ) def to_H(self): + """Convert to H parameters""" return cn.NetH( h11=self.B / self.D, h12=self.determinant / self.D, @@ -72,6 +75,7 @@ def to_H(self): ) def to_Y(self): + """Convert to Y parameters""" return cn.NetY( y11=self.D / self.B, y12=-self.determinant / self.B, @@ -80,6 +84,7 @@ def to_Y(self): ) def to_Z(self): + """Convert to Z parameters""" return cn.NetZ( z11=self.A / self.C, z12=self.determinant / self.C, @@ -88,6 +93,7 @@ def to_Z(self): ) def to_S(self): + """Convert to S parameters""" d = self.A + self.B + self.C + self.D return cn.NetS( s11=(self.A + self.B - self.C - self.D) / d, diff --git a/ycx_complex_numbers/b.py b/ycx_complex_numbers/b.py index 3160551..4f50eba 100644 --- a/ycx_complex_numbers/b.py +++ b/ycx_complex_numbers/b.py @@ -3,7 +3,7 @@ class b(Complex): - """ABCD' - A ABCD' (rev Chain/Cascade/Transmission) parameters.""" + """ABCD' - A ABCD' (rev Chain/Cascade/Transmission) parameter.""" _symbol = "b" @@ -12,6 +12,7 @@ def __init__(self, c=None): class Netb(Net): + """ABCD' - An ABCD' (rev Chain/Cascade/Transmission) 2-port-node parameters.""" def __init__(self, b11=None, b12=None, b21=None, b22=None): super().__init__(c11=b(b11), c12=b(b12), c21=b(b21), c22=b(b22)) @@ -56,6 +57,7 @@ def is_symmetrical(self): return self.A == self.D def to_a(self): + """Convert to ABCD parameters""" return cn.Neta( a11=self.D / self.determinant, a12=self.B / self.determinant, @@ -64,6 +66,7 @@ def to_a(self): ) def to_H(self): + """Convert to H parameters""" return cn.NetH( h11=self.B / self.A, h12=1 / self.A, @@ -72,6 +75,7 @@ def to_H(self): ) def to_Y(self): + """Convert to Y parameters""" return cn.NetY( y11=self.A / self.B, y12=-1 / self.B, @@ -80,6 +84,7 @@ def to_Y(self): ) def to_Z(self): + """Convert to Z parameters""" return cn.NetZ( z11=self.D / self.C, z12=1 / self.C, diff --git a/ycx_complex_numbers/complex.py b/ycx_complex_numbers/complex.py index 6edfbcb..f13d19a 100644 --- a/ycx_complex_numbers/complex.py +++ b/ycx_complex_numbers/complex.py @@ -21,6 +21,7 @@ def __init__(self, c=None): self._c = c + 0j def from_polar(self, mag, angle): + """Create a Complex instance from a polar coordinate using magnitude and phase angle""" x = mag * np.cos(np.deg2rad(angle)) y = mag * np.sin(np.deg2rad(angle)) self._c = complex(x, y) @@ -62,14 +63,19 @@ def __abs__(self): return abs(self._c) def as_complex(self): + """Return Complex as a pure python complex number""" return self._c def as_polar(self): + """Return as polar magnitude and phase angle""" mag = abs(self._c) angle = math.degrees(math.atan2(self._c.imag, self._c.real)) return {"mag": mag, "angle": angle} def as_conjugate(self): + """Return the complex conjugate + + see also conjugate() property""" return self.__class__((self._c.real - 1j * self._c.imag)) @property @@ -223,7 +229,7 @@ def c22(self): @property def m(self): - """as numpy array matrix""" + """as a numpy square 2x2 array matrix""" return np.array([[self.c11, self.c12], [self.c21, self.c22]]) def __add__(self, other): @@ -295,4 +301,5 @@ def __rmul__(self, other): @property def determinant(self): + """Return the determinant of the complex square matrix""" return self._c11 * self._c22 - self._c12 * self._c21