nport — n-ports and 2n-ports

Signal Representations

Depending on the n-port representation (see n-port Representations below), the signals on the terminals of an n-port are represented as either voltages and currents or traveling waves [1]. The conventions for voltages, currents and voltage waves used in nport are shown in figures A two-port network descibed by voltages and currents and A two-port network descibed by traveling waves.

_images/2port_VI.png

A two-port network descibed by voltages and currents

_images/2port_WA.png

A two-port network descibed by traveling waves

In the voltage-current representation, the currents are flowing into the ports. In the traveling-wave representation, a_i and b_i represent voltage waves flowing into and out of port i respectively. The relation between voltages and currents and traveling waves is given by

\begin{split}\begin{align} v_i &= a_i + b_i\\ i_i &= \frac{a_i - b_i}{Z_0} \end{align}\end{split}

n-port Representations

Impedance (Z) parameters

Pass Z or IMPEDANCE as type on object instantiation.

\begin{split}\begin{bmatrix} v_{1} \cr v_{2} \end{bmatrix} = \begin{bmatrix} Z_{11} & Z_{12} \cr Z_{21} & Z_{22} \end{bmatrix} \begin{bmatrix} i_{1} \cr i_{2} \end{bmatrix}\end{split}

Admittance (Y) parameters

Pass Y or ADMITTANCE as type on object instantiation.

\begin{split}\begin{bmatrix} i_{1} \cr i_{2} \end{bmatrix} = \begin{bmatrix} Y_{11} & Y_{12} \cr Y_{21} & Y_{22} \end{bmatrix} \begin{bmatrix} v_{1} \cr v_{2} \end{bmatrix}\end{split}

Scattering (S) parameters

Pass S or SCATTERING as type on object instantiation.

\begin{split}\begin{bmatrix} b_{1} \cr b_{2} \end{bmatrix} = \begin{bmatrix} S_{11} & S_{12} \cr S_{21} & S_{22} \end{bmatrix} \begin{bmatrix} a_{1} \cr a_{2} \end{bmatrix}\end{split}

2n-port Representations

In addition to the n-port Representations, 2n-ports have two extra representations.

Transmission (ABCD) parameters

Pass ABCD or TRANSMISSION as type on object instantiation.

\begin{split}\begin{bmatrix} v_{1} \cr i_{1} \end{bmatrix} = \begin{bmatrix} A & B \cr C & D \end{bmatrix} \begin{bmatrix} v_{2} \cr - i_{2} \end{bmatrix}\end{split}

Scattering Transfer (T) parameters

Pass T or SCATTERING_TRANSFER as type on object instantiation.

\begin{split}\begin{bmatrix} a_{1} \cr b_{1} \end{bmatrix} = \begin{bmatrix} T_{11} & T_{12} \cr T_{21} & T_{22} \end{bmatrix} \begin{bmatrix} b_{2} \cr a_{2} \end{bmatrix}\end{split}

2-port Representations

Supported types for 2-port parameters include all of the above and, additionally:

Hybrid (H) parameters

Pass H or HYBRID as type on object instantiation.

\begin{split}\begin{bmatrix} v_{1} \cr i_{2} \end{bmatrix} = \begin{bmatrix} H_{11} & H_{12} \cr H_{21} & H_{22} \end{bmatrix} \begin{bmatrix} i_{1} \cr v_{2} \end{bmatrix}\end{split}

Inverse Hybrid (G) parameters

Pass G or INVERSE_HYBRID as type on object instantiation.

\begin{split}\begin{bmatrix} i_{1} \cr v_{2} \end{bmatrix} = \begin{bmatrix} G_{11} & G_{12} \cr G_{21} & G_{22} \end{bmatrix} \begin{bmatrix} v_{1} \cr i_{2} \end{bmatrix}\end{split}

Frequency-independent n-ports

A Single n-port Matrix

class nport.NPortMatrix

Bases: nport.base.NPortMatrixBase

Class representing an n-port matrix (Z, Y or S; for 2-ports also T, G, H or ABCD)

Parameters:
  • matrix (n by n array) – matrix elements
  • type (Z, Y, S, T, G, H or ABCD) – matrix type
  • z0 (float) – normalizing impedance (only S and T)
convert(type, z0=None)

Convert to another n-port matrix representation

Parameters:
  • type (Z, Y or S) – new matrix type
  • z0 (float) – normalizing impedance (only S and T)
Return type:

NPortMatrix

is_passive()

Check whether this n-port matrix is passive

Return type:bool
is_reciprocal()

Check whether this n-port matrix is reciprocal

Return type:bool
is_symmetrical()

Check whether this n-port matrix is symmetrical

Return type:bool
parallel(other, portmap=None)

Connect other in parallel with this NPortMatrix.

Parameters:
  • portmap (iterable of ints) – specifies to which ports of other should be connected to the ports of this NPortMatrix. A zero in the n-th position indicates that nothing should be placed in parallel with the port n. A positive integer in position m indicates the port number of other that should be connected to port m.
Return type:

NPortMatrix (type Y)

ports

The number of ports of this NPortMatrix

Return type:int
power(n)

Return this NPortMatrix raised to the nth power

Return type:NPortMatrix
recombine(portsets)

Recombine ports, reducing the number of ports of this NPortMatrix.

Parameters:
  • portsets (iterable of ints and tuples) – an int specifies the number of a port that needs to be kept as-is. If the int is negative, the port’s polarity will be reversed. A tuple specifies a pair of ports that are to be recombined into a single port. The second element of this tuple acts as the ground reference to the first element.
Return type:

NPortMatrix (type Z)

>>> recombine([(1,3), (2,4), 5, -6]

will generate a four-port where:

  • port 1 is original port 1 referenced to port 3
  • port 2 is original port 2 referenced to port 4
  • port 3 is original port 5
  • port 4 is original port 6, but with reversed polarity
renormalize(z0)

Renormalize the n-port parameters to z0

Parameters:
  • z0 (float) – new normalizing impedance
Return type:

NPortMatrix

reverse()

Return an NPortMatrix with the ports reversed. This simply flips the matrix horizontally and vertically.

Return type:NPortMatrix
shunt(portsets)

Connect ports together, reducing the number of ports of this NPortMatrix.

Parameters:
  • portsets (iterable of ints and tuples) – an int specifies the number of a port that needs to be kept as-is. A tuple specifies a set of ports that are to be connected together.
Return type:

NPortMatrix (type Y)

>>> shunt([1, (2, 3), (4, 5, 6)]

will generate a three-port where:

  • port 1 is original port 1
  • port 2 is original port 2 and 3 connected together
  • port 3 is original ports 4, 5 and 6 connected together
submatrix(ports)

Keep only the parameters corresponding to the given ports, discarding the others. For a Z-matrix and a Y-matrix this corresponds to terminating the discarded ports in an open or short circuit respectively.

Parameters:
  • ports (iterable) – list of ports to keep
Return type:

NPortMatrix

twonportmatrix(inports=None, outports=None)

Return the 2n-port matrix represented by this n-port matrix

Parameters:
  • inports (class:tuple or list) – the list of ports that make up the inputs of the 2n-port
  • outports (tuple or list) – the list of ports that make up the outputs
Return type:

TwoNPortMatrix

A Single 2n-port Matrix

class nport.TwoNPortMatrix

Bases: nport.base.NPortMatrixBase

Class representing a 2n-port matrix (Z, Y, S, T or ABCD)

Parameters:
  • freqs (list) – list of frequency samples
  • matrix (2 by 2 array where each element is an n by n array) – matrix elements
  • type (Z, Y, S, T or ABCD) – matrix type
  • z0 (float) – normalizing impedance (only S and T)
convert(type, z0=None)

Convert from one 2n-port matrix representation to another

Parameters:
  • type (Z, Y, S, T or ABCD) – new matrix type
  • z0 (float) – normalizing impedance (only S and T)
nportmatrix()

Convert this TwoNPortMatrix to an NPortMatrix

Return type:NPortMatrix
ports

The number of ports of this TwoNPortMatrix

Return type:int
renormalize(z0)

Renormalize the 2n-port parameters to z0

Parameters:
  • z0 (float) – new normalizing impedance

Frequency-dependent n-ports

n-ports

class nport.NPort

Bases: nport.base.NPortBase

Class representing an n-port across a list of frequencies

Parameters:
  • freqs (list) – list of frequency samples
  • matrix (list of n by n arrays) – list of matrix elements
  • type (Z, Y, S, T, G, H or ABCD) – matrix type
  • z0 (float) – normalizing impedance (only S and T)
add(freq, matrix)

Return an NPort with the specified frequency sample added.

Parameters:
  • freq (float) – frequency at which to insert matrix
  • matrix (NPortMatrix or a complex array) – matrix to insert at freq
Return type:

NPort

If matrix is an NPortMatrix, its elements will be converted to this NPort‘s type and characteristic impedance. If matrix is a complex array, it is assumed the elements are in the format of this NPort.

convert(type, z0=None)

Convert to another n-port matrix representation

Parameters:
  • type (Z, Y, S, T, G, H or ABCD) – n-port representation type to convert to
  • z0 (float) – normalizing impedance (only S and T)
group_delay(port1, port2)

Return the group delay of the parameter as specified by the indices port1 and port2

Parameters:
  • port1 (int) – index of input port
  • port2 (int) – index of output port
Returns:

group delay of parameter at indices port1 and port2

Return type:

ndarray

invert()

Return an NPort described by the inverse of this NPort‘s matrices

Return type:NPort
is_passive()

Check whether this NPort is passive

Return type:bool
matrix_cls

alias of NPortMatrix

parallel(other, portmap=None)

Connect other in parallel with this NPort.

Parameters:
  • portmap (iterable of ints) – specifies to which ports of other should be connected to the ports of this NPort. A zero in the n-th position indicates that nothing should be placed in parallel with the port n. A positive integer in position m indicates the port number of other that should be connected to port m.
Return type:

NPort

ports

The number of ports of this NPort

Return type:int
power(n)

Return this NPort‘s matrices raised to the nth power

Return type:NPort
recombine(portsets)

Recombine ports, reducing the number of ports of this NPort.

Parameters:
  • portsets (iterable of ints and tuples) – an int specifies the number of a port that needs to be kept as-is. If the int is negative, the port’s polarity will be reversed. A tuple specifies a pair of ports that are to be recombined into a single port. The second element of this tuple acts as the ground reference to the first element.
Return type:

NPort

>>> recombine([(1,3), (2,4), 5, -6]

will generate a four-port where:

  • port 1 is original port 1 referenced to port 3
  • port 2 is original port 2 referenced to port 4
  • port 3 is original port 5
  • port 4 is original port 6, but with reversed polarity
renormalize(z0)

Renormalize the n-port parameters to z0

Parameters:
  • z0 (float) – new normalizing impedance
Return type:

NPort

reverse()

Return an NPort with the ports reversed. This simply flips the matrices horizontally and vertically.

Return type:NPort
shunt(portsets)

Connect ports together, reducing the number of ports of this NPort.

Parameters:
  • portsets (iterable of ints and tuples) – an int specifies the number of a port that needs to be kept as-is. A tuple specifies a set of ports that are to be connected together.
Return type:

NPort

>>> shunt([1, (2, 3), (4, 5, 6)]

will generate a three-port where:

  • port 1 is original port 1
  • port 2 is original port 2 and 3 connected together
  • port 3 is original ports 4, 5 and 6 connected together
submatrix(ports)

Keep only the parameters corresponding to the given ports, discarding the others. For a Z-matrix and a Y-matrix this corresponds to terminating the discarded ports in an open or short circuit respectively.

Parameters:
  • ports (iterable) – list of ports to keep
twonport(inports=None, outports=None)

Convert this NPort to a TwoNPort using inports as the input ports and outports as the output ports.

Parameters:
  • inports (tuple or list) – the list of ports that make up the inputs of the 2n-port
  • outports (tuple or list) – the list of ports that make up the outputs
Return type:

TwoNPort

2n-ports

class nport.TwoNPort

Bases: nport.base.NPortBase

Class representing a 2n-port across a list of frequencies

Parameters:
  • matrices – list of matrix elements
  • type (Z, Y, S, T or ABCD) – matrix type
  • z0 (float) – normalizing impedance (only S and T)
add(freq, matrix)

Return a TwoNPort with the specified frequency sample added.

If matrix is a TwoNPortMatrix, its elements will be converted to this TwoNPort‘s type and characteristic impedance. If matrix is a complex array, it is assumed the elements are in the format of this TwoNPort.

Parameters:
  • freq (float) – frequency at which to insert matrix
  • matrix (TwoNPortMatrix or a complex array) – matrix to insert at freq
Return type:

TwoNPort

convert(type, z0=None)

Convert to another 2n-port matrix representation

Parameters:
  • type (Z, Y, S, T or ABCD) – new matrix type
  • z0 (float) – normalizing impedance (only S and T)
matrix_cls

alias of TwoNPortMatrix

nport()

Convert this TwoNPort to an NPort

Return type:NPort
ports

The number of ports of this TwoNPort

Return type:int
renormalize(z0)

Renormalize the 2n-port parameters to z0

Parameters:
  • z0 (float) – new normalizing impedance
Return type:

TwoNPort

[KUR65]“Power Waves and the Scattering Matrix” by K. Kurokawa in IEEE Transactions on Microwave Theory and Techniques, vol. 13, no. 2, pp. 194–202, 1965

Footnotes

[1]Power wave representations, as introduced by Kurokawa [KUR65], are currently not supported by nport.