S-parameter Utilities

S-parameter manipulation utilities for PyBERT.

Original author: David Banas <capn.freako@gmail.com>

Original date: June 16, 2024

Copyright (c) 2024 David Banas; all rights reserved World wide.

A partial extraction of the old pybert/utility.py, as part of a refactoring.

pybert.utility.sparam.H_2_s2p(H: numpy.typing.NDArray.~Comp, Zc: numpy.typing.NDArray.~Comp, fs: numpy.typing.NDArray.~Real, Zref: float = 50) skrf.Network[source]

Convert transfer function to 2-port network.

Parameters:
  • H – Transfer function of medium alone.

  • Zc – Complex impedance of medium.

  • fs – Frequencies at which H and Zc were sampled (Hz).

Keyword Arguments:

Zref – Reference (i.e. - port) impedance to be used in constructing the network (Ohms). Default: 50

Returns:

2-port network representing the channel to which H and Zc pertain.

pybert.utility.sparam.cap_mag(zs: numpy.typing.NDArray.~Comp, maxMag: float = 1.0) numpy.typing.NDArray.~Comp[source]

Cap the magnitude of a list of complex values, leaving the phase unchanged.

Parameters:

zs – The complex values to be capped.

Keyword Arguments:

maxMag – The maximum allowed magnitude. Default: 1

Notes

  1. Any pre-existing shape of the input will be preserved.

pybert.utility.sparam.import_channel(filename: str, sample_per: float, fs: numpy.typing.NDArray.~Real, zref: float = 100, renumber: bool = False) skrf.Network[source]

Read in a channel description file.

Parameters:
  • filename – Name of file from which to import channel description.

  • sample_per – Sample period of system signal vector (s).

  • fs – (Positive only) frequency values being used by caller (Hz).

Keyword Arguments:
  • zref – Reference impedance for time domain files (Ohms). Default: 100

  • renumber – Automatically fix “1=>3/2=>4” port numbering when True. Default: False

Returns:

2-port network description of channel.

Notes

1. When a time domain (i.e. - impulse or step response) file is being imported, we have little choice but to use the given reference impedance as the channel characteristic impedance, for all frequencies. This implies two things:

1. Importing time domain descriptions of channels into PyBERT yields necessarily lower fidelity results than importing Touchstone descriptions; probably not a surprise to those skilled in the art.

2. The user should take care to ensure that the reference impedance value in the GUI is equal to the nominal characteristic impedance of the channel being imported when using time domain channel description files.

pybert.utility.sparam.import_freq(filename: str, renumber: bool = False) skrf.Network[source]

Read in a 1, 2, or 4-port Touchstone file, and return an equivalent 2-port network.

Parameters:

filename – Name of Touchstone file to read in.

Keyword Arguments:

renumber – Automatically detect/fix “1=>3/2=>4” port numbering, when True. Default = False

Returns:

2-port differential network.

Raises:

ValueError – If Touchstone file is not 1, 2, or 4-port.

Notes

1. A 4-port Touchstone file is assumed single-ended, and the “DD” quadrant of its mixed-mode equivalent gets returned.

pybert.utility.sparam.interp_s2p(ntwk: skrf.Network, f: numpy.typing.NDArray.~Real) skrf.Network[source]

Safely interpolate a 2-port network, by applying certain constraints to any necessary extrapolation.

Parameters:
  • ntwk – The 2-port network to be interpolated.

  • f – The list of new frequency sampling points (Hz).

Returns:

The interpolated/extrapolated 2-port network.

Raises:

ValueError – If ntwk is _not_ a 2-port network.

pybert.utility.sparam.mon_mag(zs: numpy.typing.NDArray.~Comp) numpy.typing.NDArray.~Comp[source]

Enforce monotonically decreasing magnitude in list of complex values, leaving the phase unchanged.

Parameters:

zs – The complex values to be adjusted.

Notes

  1. Any pre-existing shape of the input will be preserved.

pybert.utility.sparam.sdd_21(ntwk: skrf.Network, renumber: bool = False) skrf.Network[source]

Given a 4-port single-ended network, return its differential 2-port network.

Parameters:

ntwk – 4-port single ended network.

Keyword Arguments:

renumber – Automatically fix “1=>3/2=>4” port numbering when True. Default: False

Returns:

2-port differential network.

pybert.utility.sparam.se2mm(ntwk: skrf.Network, scale: float = 0.5, renumber: bool = False) skrf.Network[source]

Given a 4-port single-ended network, return its mixed mode equivalent.

Parameters:

ntwk – 4-port single ended network.

Keyword Arguments:
  • scale – Normalization factor. Default: 0.5

  • renumber – Automatically fix “1=>3/2=>4” port numbering when True. Default: False

Returns:

Mixed mode equivalent network, in the following format

\[\begin{split}\begin{matrix} Sdd11 & Sdd12 & Sdc11 & Sdc12\\ Sdd21 & Sdd22 & Sdc21 & Sdc22\\ Scd11 & Scd12 & Scc11 & Scc12\\ Scd21 & Scd22 & Scc21 & Scc22 \end{matrix}\end{split}\]