This commit is contained in:
Jan Petykiewicz 2024-03-14 22:38:17 -07:00
parent 2c5c40c1e7
commit 0ad78271ca

View File

@ -225,11 +225,19 @@ def connect_s(
) -> NDArray[numpy.complex128]: ) -> NDArray[numpy.complex128]:
""" """
TODO TODO
connect two n-port networks' s-matrices together. freq x ... x n x n
specifically, connect port `k` on network `A` to port `l` on network
Based on skrf implementation
Connect two n-port networks' s-matrices together.
Specifically, connect port `k` on network `A` to port `l` on network
`B`. The resultant network has nports = (A.rank + B.rank-2); first `B`. The resultant network has nports = (A.rank + B.rank-2); first
(A.rank - 1) ports are from `A`, remainder are from B. (A.rank - 1) ports are from `A`, remainder are from B.
Assumes same reference impedance for both `k` and `l`; may need to
connect an "impedance mismatch" thru element first!
Args: Args:
A: S-parameter matrix of `A`, shape is fxnxn A: S-parameter matrix of `A`, shape is fxnxn
k: port index on `A` (port indices start from 0) k: port index on `A` (port indices start from 0)
@ -237,7 +245,7 @@ def connect_s(
l: port index on `B` l: port index on `B`
Returns: Returns:
C: new S-parameter matrix new S-parameter matrix
""" """
if k > A.shape[-1] - 1 or l > B.shape[-1] - 1: if k > A.shape[-1] - 1 or l > B.shape[-1] - 1:
raise ValueError("port indices are out of range") raise ValueError("port indices are out of range")
@ -253,11 +261,18 @@ def innerconnect_s(
) -> NDArray[numpy.complex128]: ) -> NDArray[numpy.complex128]:
""" """
TODO TODO
n x n x freq freq x ... x n x n
connect two ports of a single n-port network's s-matrix.
Based on skrf implementation
Connect two ports of a single n-port network's s-matrix.
Specifically, connect port `k` to port `l` on `S`. This results in Specifically, connect port `k` to port `l` on `S`. This results in
a (n-2)-port network. a (n-2)-port network.
Assumes same reference impedance for both `k` and `l`; may need to
connect an "impedance mismatch" thru element first!
Args: Args:
S: S-parameter matrix of `S`, shape is fxnxn S: S-parameter matrix of `S`, shape is fxnxn
k: port index on `S` (port indices start from 0) k: port index on `S` (port indices start from 0)
@ -276,18 +291,18 @@ def innerconnect_s(
if k > S.shape[-1] - 1 or l > S.shape[-1] - 1: if k > S.shape[-1] - 1 or l > S.shape[-1] - 1:
raise ValueError("port indices are out of range") raise ValueError("port indices are out of range")
l = [l] ll = slice(l, l + 1)
k = [k] kk = slice(k, k + 1)
mkl = 1 - S[k, l] mkl = 1 - S[..., kk, ll]
mlk = 1 - S[l, k] mlk = 1 - S[..., ll, kk]
C = S + ( C = S + (
S[k, :] * S[:, l] * mlk S[..., kk, :] * S[..., :, l] * mlk
+ S[l, :] * S[:, k] * mkl + S[..., ll, :] * S[..., :, k] * mkl
+ S[k, :] * S[l, l] * S[:, k] + S[..., kk, :] * S[..., l, l] * S[..., :, kk]
+ S[l, :] * S[k, k] * S[:, l] + S[..., ll, :] * S[..., k, k] * S[..., :, ll]
) / ( ) / (
mlk * mkl - S[k, k] * S[l, l] mlk * mkl - S[..., kk, kk] * S[..., ll, ll]
) )
# remove connected ports # remove connected ports