19
19
def ab_to_s (
20
20
a_matrix : TerminalPortDataArray , b_matrix : TerminalPortDataArray
21
21
) -> TerminalPortDataArray :
22
- """Get the scattering matrix given the power wave matrices."""
22
+ """Get the scattering matrix given the power wave matrices.
23
+
24
+ The scattering matrix S is computed from the incident (a) and reflected (b)
25
+ power wave amplitude matrices using the formula :math:`S = b * a^-1`.
26
+
27
+ Args:
28
+ a_matrix: Matrix of incident power wave amplitudes.
29
+ b_matrix: Matrix of reflected power wave amplitudes.
30
+
31
+ Returns:
32
+ The computed scattering (S) matrix.
33
+ """
23
34
# Ensure dimensions are ordered properly
24
35
a_matrix = a_matrix .transpose (* TerminalPortDataArray ._dims )
25
36
b_matrix = b_matrix .transpose (* TerminalPortDataArray ._dims )
@@ -35,7 +46,19 @@ def ab_to_s(
35
46
36
47
37
48
def check_port_impedance_sign (Z_numpy : np .ndarray ):
38
- """Sanity check for consistent sign of real part of Z for each port across all frequencies."""
49
+ """Sanity check for consistent sign of real part of Z for each port.
50
+
51
+ This check iterates through each port and ensures that the sign of the real
52
+ part of its impedance does not change across all frequencies. A sign change
53
+ can indicate an unphysical result or numerical instability.
54
+
55
+ Args:
56
+ Z_numpy: NumPy array of impedance values with shape (num_freqs, num_ports).
57
+
58
+ Raises:
59
+ Tidy3dError: If an inconsistent sign of the real part of the impedance
60
+ is detected for any port.
61
+ """
39
62
for port_idx in range (Z_numpy .shape [1 ]):
40
63
port_Z = Z_numpy [:, port_idx ]
41
64
signs = np .sign (np .real (port_Z ))
@@ -48,8 +71,18 @@ def check_port_impedance_sign(Z_numpy: np.ndarray):
48
71
49
72
50
73
def compute_F (Z_numpy : np .array ):
51
- """Helper to convert port impedance matrix to F, which is used for
52
- computing generalized scattering parameters."""
74
+ r"""Helper to convert port impedance matrix to F for generalized S-parameters.
75
+
76
+ The matrix F is used when converting between S and Z parameters for circuits
77
+ with differing port impedances. Its diagonal elements are defined as
78
+ :math:`F_{kk} = 1 / (2 * \sqrt{Re(Z_k)})`.
79
+
80
+ Args:
81
+ Z_numpy: NumPy array of complex port impedances.
82
+
83
+ Returns:
84
+ NumPy array containing the computed F values.
85
+ """
53
86
return 1.0 / (2.0 * np .sqrt (np .real (Z_numpy )))
54
87
55
88
@@ -78,8 +111,12 @@ def compute_port_VI(
78
111
def compute_power_wave_amplitudes (
79
112
port : Union [LumpedPort , CoaxialLumpedPort ], sim_data : SimulationData
80
113
) -> tuple [FreqDataArray , FreqDataArray ]:
81
- """Compute the incident and reflected power wave amplitudes at a lumped port.
82
- The computed amplitudes have not been normalized.
114
+ """Calculates the unnormalized power wave amplitudes from port voltage (V),
115
+ current (I), and impedance (Z0) using:
116
+
117
+ .. math::
118
+ a = (V + Z0*I) / (2 * sqrt(Re(Z0)))
119
+ b = (V - Z0*I) / (2 * sqrt(Re(Z0)))
83
120
84
121
Parameters
85
122
----------
@@ -105,6 +142,9 @@ def compute_power_delivered_by_port(
105
142
) -> FreqDataArray :
106
143
"""Compute the power delivered to the network by a lumped port.
107
144
145
+ The power is calculated as the incident power minus the reflected power:
146
+ P = 0.5 * (|a|^2 - |b|^2).
147
+
108
148
Parameters
109
149
----------
110
150
port : Union[:class:`.LumpedPort`, :class:`.CoaxialLumpedPort`]
@@ -123,7 +163,19 @@ def compute_power_delivered_by_port(
123
163
124
164
125
165
def s_to_z (s_matrix : TerminalPortDataArray , reference : Union [complex , PortDataArray ]) -> DataArray :
126
- """Get the impedance matrix given the scattering matrix and a reference impedance."""
166
+ """Get the impedance matrix given the scattering matrix and a reference impedance.
167
+
168
+ This function converts an S-matrix to a Z-matrix. It handles both a single
169
+ uniform reference impedance and generalized per-port reference impedances.
170
+
171
+ Args:
172
+ s_matrix: The scattering (S) matrix to convert.
173
+ reference: The reference impedance. Can be a single complex value for all
174
+ ports or a PortDataArray for per-port impedances.
175
+
176
+ Returns:
177
+ The computed impedance (Z) matrix as a DataArray.
178
+ """
127
179
128
180
# Ensure dimensions are ordered properly
129
181
z_matrix = s_matrix .transpose (* TerminalPortDataArray ._dims ).copy (deep = True )
0 commit comments