optimize_s11#

simpleEMS.sim_tools.optimize_s11(freqs: ndarray[tuple[Any, ...], dtype[_ScalarT]], s11: ndarray[tuple[Any, ...], dtype[_ScalarT]], target_freq: float | None = None, freq_band: tuple[float, float] | None = None, mode: str = 'worst', threshold: float = -15) → floating#

Objective function for S11 (reflection) optimization. Lower is better.

Intended as a scalar cost function for optimize_s_params: converts S11 to dB and reduces it to a single number, either at one frequency or over a band. If target_freq is given it takes precedence over freq_band (and mode/threshold are ignored).

Parameters:
  • freqs (NDArray) – Array of frequencies in Hz, matching s11.

  • s11 (NDArray) – Complex S11 parameter array across the frequency range.

  • target_freq (float, optional) – If given, evaluate S11 (in dB) at the frequency in freqs closest to this value, ignoring freq_band/mode/ threshold.

  • freq_band (tuple of (float, float), optional) – Frequency band (f_min, f_max) in Hz over which to evaluate S11 when target_freq is not given.

  • mode (str, optional) –

    Evaluation mode within the frequency band:

    • "worst" : the maximum S11 in dB (worst-case reflection).

    • "mean" : the mean S11 in dB across the band.

    • "threshold" : sum, over the band, of the amount (in dB) each point exceeds threshold (0 if none exceed it).

    Default is "worst".

  • threshold (float, optional) – S11 threshold in dB, used only when mode="threshold". Default is -15.

Returns:

Scalar cost value (S11 in dB); lower means better matched.

Return type:

float

Raises:

ValueError – If mode is not one of "mean", "worst", or "threshold", or if neither target_freq nor freq_band is provided.