kicad2ems.core.macromodel¶
A passive rational macromodel of S-parameters, and its response in time.
m = fit(f, S, z0=50.0) # vector fitting, common poles (Model)
m.S(f) # the model on any frequencies, DC too
m.passive() # (passive, the largest singular value)
m.enforce() # residues perturbed until passive
tr = Transient(m, dt) # the model stepped in time
V, I = simulate(m, terms, t) # every port's voltage with terminations
The fit is relaxed vector fitting (Gustavsen and Semlyen 1999, the relaxed
form of Gustavsen 2006): every entry of S on the same poles, so the model is a
state-space system of a few hundred states; the poles stable by construction
(an unstable one flipped), so the response is causal. The samples carry a DC
point where they reach low enough: Re S is even in w and Im S odd, so S(0) is
the constant of Re S fitted as a + b w^2 on the lowest samples (a time-domain
response settles to the model's S(0), which no sample in the band fixes).
Passivity (the model's largest singular value at most 1 at every frequency,
not only the samples': a transient of a non-passive model can grow without
bound) is checked on a dense grid from DC to PASS_TOP x fmax and at each
pole's frequency; where it is not, the residues are perturbed (each entry's
least change over the band that takes every violation's largest singular value
down to 1 - PASS_MARGIN along its singular vectors), until passive.
In time: S's ports are waves at each port's z0, a = (V + z0 I) / 2 sqrt(z0)
incident, b = (V - z0 I) / 2 sqrt(z0) reflected, I into the port. Each pole's
state is stepped exactly for an input linear over the step (recursive
convolution), so b[n] = G a[n] + h[n] (h from the past alone); each port's
termination is a current I(V) into the port at the step (a source behind its
resistance, a load, an IBIS buffer: core.ibis), and the step's waves solve
(Newton where a termination is not linear).
- class kicad2ems.core.macromodel.Load(r=None, c=0.0, vtt=0.0)[source]¶
A resistance r (ohm; None: none) to vtt (V) beside a capacitance c (F) to ground: the current into the port is -(V - vtt) / r - c dV/dt.
- class kicad2ems.core.macromodel.Model(poles, R, D, z0, fmax, info=None)[source]¶
S(s) = D + sum_k R_k / (s - p_k) (s in rad/s): poles p (np,), complex ones in conjugate pairs (p, p*) side by side; residues R (np, n, n), a conjugate pole's the conjugate; D (n, n) real; z0 (n,) each port's reference (ohm). fmax (Hz): the band the model was fitted on (passivity is checked to PASS_TOP times it). info: the fit's record.
- enforce(max_iter=20, scale_max=0.02)[source]¶
Make the model passive (the module's text): its samples on the dense grid projected onto passivity (each singular value above 1 - PASS_MARGIN taken down to it) and its residues and D fitted to them again on the same poles, until passive; a violation of at most scale_max left after max_iter rounds, the whole model scaled down to the margin (a gain of at most -0.17 dB). Returns the rounds (0: passive already). Raises ValueError where it does not get there. (Residues perturbed at the violations alone, as equalities, had overshot: a lossless line's 1.0000 to 1.01.)
- class kicad2ems.core.macromodel.Thevenin(e, rs, c=0.0)[source]¶
A source e(t) (V; a function of time) behind rs (ohm) and, beside the port, a capacitance c (F): the current into the port is (e - V) / rs - c dV/dt.
- class kicad2ems.core.macromodel.Transient(model, dt)[source]¶
The model stepped at dt (s): each pole's state exact for an input linear over the step. b[n] = G a[n] + history(a[n - 1]); advance(a[n]) after a step's waves are solved.
- kicad2ems.core.macromodel.dc_point(f, S, low=0.05, points=6)[source]¶
S(0) from the lowest samples (Re S even in w: a + b w^2; Im S odd, 0 at DC), or None where the samples start above `low` x fmax (a DC from there would be a guess).
- kicad2ems.core.macromodel.fit(f, S, z0=50.0, poles=None, tol=0.002, dc=True, passive=True, max_poles=400, log=None)[source]¶
The macromodel of S (nf, n, n) on f (Hz, rising, above 0): `poles` poles, or (None) the fewest of 8, 12, 16 ... up to max_poles that fit within tol (RMS of |S - model| over the samples, of the largest |S|); a DC point added (dc_point) where the samples reach low enough; made passive (Model.enforce) where it is not. Raises ValueError where no fit is within tol.
- kicad2ems.core.macromodel.simulate(model, terms, t, log=None, newton=30, tol=1e-09)[source]¶
Every port's voltage and current (into the port) (len(t), n) for the terminations `terms` (one a port: Thevenin, Load, an IBIS buffer: each iv(V, t, dt) -> (I into the port, dI/dV) and accept(V, t, dt)), on the uniform times t (s) from 0, every port at rest before.