/** * measureTrace — teaching-grade time-domain estimator. * * WHY this approach (no FFT/windowing): * This is an interactive oscilloscope for circuit learners, not an * instrument-grade analyser. We want numbers that are immediately * comprehensible and match what a student would compute by hand from the * waveform. Threshold-crossing edge detection gives that, and a DFT/FFT would * add windowing artefacts the user would have to understand — not the right * trade-off here. * * The engine does NOT only produce clean sines: capacitor ringing, PWM * ripple, and switching glitches are normal. A bare midpoint crossing is * fragile against these (a lone spike suppresses detection; ripple near the * threshold inflates the edge count and the reported frequency by 2-5x), so * the estimator is hardened three ways below. * * Edge-detection rules: * - Threshold = midpoint of the 2nd/98th percentiles (not raw min/max), so a * single outlier spike cannot move it outside the real signal. * - Rising crossing with Schmitt hysteresis: after an edge, re-arm only once * the signal falls a band (10% of span) below mid, collapsing ripple/noise * crossings to one edge per cycle. * - Single-sample spikes are rejected (a real edge stays above mid on the * next sample; a glitch falls straight back). * - At least 2 rising edges are required to compute frequency/period; if the * inter-edge intervals are too irregular (no stable period) frequency is * left undefined rather than reporting a confident wrong value. * - Duty cycle: fraction of samples above the midpoint between the first * and last rising-edge timestamps. Using sample fractions (not time- * weighted) is simpler and correct for the uniformly-sampled output the * recorder provides. * * No React/DOM/Worker imports — importable from any context including tests. */ export interface TraceMeasurements { /** Minimum sample value. */ min: number; /** Maximum sample value. */ max: number; /** Arithmetic mean. */ mean: number; /** Root mean square. */ rms: number; /** Estimated fundamental frequency in Hz; undefined when not detectable. */ frequency?: number; /** Estimated period in seconds; undefined when not detectable. */ period?: number; /** * Fraction of samples above the midpoint (0–1); undefined when not * detectable (e.g. dc or fewer than 2 rising edges). */ dutyCycle?: number; } /** * Compute time-domain statistics for a single trace window. * * @param t Monotonically increasing time values (seconds). Non-finite entries * delimit acquisition gaps. * @param v Corresponding voltage samples, same length as t. Non-finite entries * delimit acquisition gaps rather than being joined across. */ export declare function measureTrace(t: number[], v: number[]): TraceMeasurements;