/** * True linearized small-signal AC analysis (Wave A5) — the SPICE-style * counterpart of the large-signal "ac-sweep" runner in * analysis/run-ac-sweep.ts. That runner drives the real nonlinear circuit * with a sine and DFTs the response, so its results include distortion and * drive-amplitude effects; THIS module linearizes every device about a * committed DC operating point and solves the complex admittance system * exactly, so its results are the ideal small-signal transfer function. Both * modes stay available on purpose: they answer different questions. * * Flow per analysis: * 1. engine.dcOperatingPoint() — the Wave A3 ladder — must converge; the * committed point (node voltages, regimes, latches, trip states) is the * linearization bias and stays held for the whole sweep. * 2. One AcSystem (bordered 2n real system, see ac-system.ts) is built for * the loaded matrix layout and reused across every frequency point: * clear() keeps the sparse backend's discovered pattern, so the sweep * pays the symbolic analysis once and each point is a value-only * restamp + factorization. * 3. Per frequency, every registered device with an acStamp hook stamps * its linearized contribution at the committed OP; devices without the * hook are documented high-Z (no small-signal contribution), except * committed digital output stages, which get the generic * Thevenin-to-rail default below. The designated input source injects * a unit 1 + j0 drive; every other independent source is AC-zeroed * (voltage branches become AC shorts, current sources become opens). * * MCU boards are rejected outright: firmware has no small-signal model, and * silently treating a running core's outputs as bias-frozen would present a * confident wrong answer. Circuits without MCUs cover every registered kind * via acStamp hooks or the defaults here. */ import { type DcOperatingPointResult, type SimEngine } from "./sim-engine.js"; export interface SmallSignalAcOptions { /** Component id of the independent source carrying the unit AC drive. */ inputId: string; /** Deterministic net ids to report (e.g. "n3"; "gnd" reads as 0). */ outputNetIds: readonly string[]; /** Analysis frequencies in hertz; every entry must be finite, > 0 (the * operating point itself is the DC answer), and inside the documented * [1e-9, 1e15] Hz sanity window. */ frequenciesHz: readonly number[]; } export interface SmallSignalAcNetOutput { netId: string; /** 20*log10(|V|) per point — gain in dB relative to the 1 V unit drive. * Exactly-zero responses (e.g. probing "gnd") read -Infinity. */ magnitudeDb: number[]; /** Phase in degrees, atan2(im, re), in (-180, 180]. */ phaseDeg: number[]; /** Raw complex response per point (volts per volt of drive). */ re: number[]; im: number[]; } export interface SmallSignalAcResult { frequenciesHz: number[]; outputs: SmallSignalAcNetOutput[]; /** Description of the injected reference drive. */ reference: { inputId: string; kind: string; injection: string; }; /** Which dcOperatingPoint stage produced the linearization bias. */ opMethod: DcOperatingPointResult["method"]; /** * Frequencies whose bordered solve reported an ill-conditioned (but not * singular) factorization. Results at these points are returned — the * regularized system is solvable by construction, e.g. an ideal lossless * LC probed exactly at resonance answers through the disclosed 1e-12 node * shunt — but the backend's health flag is surfaced instead of silently * discarded so callers can see which points sit on a near-singularity. */ illConditionedFrequenciesHz: number[]; } /** * Run a linearized small-signal AC analysis over a loaded engine. * * The engine must have a circuit loaded; its DC operating point is computed * (and committed) here, so the engine's public readouts afterwards describe * the bias point the analysis linearized about. Throws with a descriptive * message on every unusable configuration instead of returning NaNs: a * missing/invalid input, an MCU-bearing circuit, a non-converged OP, or a * singular AC system. */ export declare function runSmallSignalAc(engine: SimEngine, options: SmallSignalAcOptions): SmallSignalAcResult;