Browse documentation
Docs/Language

Native discrete control models

Grid's grid.discrete-siso.v1 profile composes and simulates dimensionless, linear, time-invariant models with one input and one output. Definitions and reports are ordinary reusable values…

Discrete control models

Grid's grid.discrete-siso.v1 profile composes and simulates dimensionless, linear, time-invariant models with one input and one output. Definitions and reports are ordinary reusable values in the existing native LIR workflow. They do not schedule a device or create a running DSP process.

Start with the controller comparison example. It builds a plant from transfer coefficients, composes a gain controller, closes negative feedback, and compares step and impulse responses. Editing the gain or sample period recomputes the same source-owned definitions; source and saved LIR reopen retain the same behavior.

Model contracts

Call Meaning
CS_LTI(a, b, c, d, sample_period) State-space definition. A is a dense square matrix or row-major flat vector; B and C are state-length row/column vectors; D is a scalar.
CS_TRANSFER(numerator, denominator, sample_period) Proper transfer function with coefficient vectors in descending powers of z, converted to controllable canonical state space.
CS_SERIES(left, right) Left output feeds right input.
CS_PARALLEL(left, right) Both receive the same input; outputs are added.
CS_FEEDBACK(forward, return_path) Negative feedback: forward/(1 + forward*return_path).
CS_RESPONSE(model, initial_state, inputs) Pure finite response, with explicit initial state and one scalar input per sample.

A model record retains profile, time_domain, sample_period, a, b, c, and d. Coefficients are normalized realization data, not the original transfer spelling. The owning source retains that spelling. Records can be inspected and saved; consuming calls revalidate their profile and dimensions. Unrecognized fields or time domains refuse.

Models use x[k+1] = A*x[k] + B*u[k] and y[k] = C*x[k] + D*u[k], with sample time k*sample_period starting at zero. This follows conventional discrete state-space equations. The period is positive finite seconds; signal/state coefficients are untyped dimensionless numbers. Composition requires exactly equal periods: there is no inferred clock, tolerance-based clock merge or implicit resampling.

State order after composition is left/forward states followed by right/return states. Initial states use that order. Static gains have zero states and use [] for initial state. The transfer constructor admits at most numerator length equal to denominator length, with a nonzero leading denominator. For example, [0.2] / [1, -0.8] means 0.2/(z-0.8), not a polynomial in ascending powers of z or an implicit continuous-time model. There is no pole-zero cancellation, minimal-realization conversion or hidden-state removal.

Feedback solves the scalar direct-feedthrough loop at composition time. It refuses when abs(1 + Df*Dh) <= 1e-12*(1 + abs(Df*Dh)) or the divisor is non-finite. This prevents singular and near-singular admitted loops; it does not certify general numerical conditioning.

Response and diagnostics

Use [1, 1, ...] for a unit step and [1, 0, ...] for a unit-sample impulse. The impulse is not divided by sample period. Arbitrary finite row/column input vectors and nonzero initial states are supported. Each call starts from its explicit initial state, with no implicit warm state across recalculations.

The complete report retains the model, method, initial state, inputs, times, next_states, and outputs. At time k, outputs[k] is y[k] and next_states[k] is x[k+1]. Array indexing in Grid remains one-based. The report also includes sorted numerical poles as real/imaginary pairs, spectral_radius, stability, and stability_tolerance.

Diagnostics use the existing native general real-matrix eigenvalue algorithm. All realization modes count, including hidden or cancelling modes. Radius below 1 - 1e-9 reports stable; above 1 + 1e-9 reports unstable; the boundary band reports boundary-or-uncertain. These are floating-point internal asymptotic-stability diagnostics, not proofs, BIBO/minimal-model classification, or a claim that a unit-circle pole is safely marginal. An unstable model can still produce a finite report. Numerical nonconvergence or non-finite evolution returns an error, never a successful partial report.

Bounds and compatibility

The profile admits at most 16 states, including the combined state count, and 1 through 16,384 samples. Coefficient magnitudes must not exceed 1e100. Initial state, inputs and resulting values must be finite; timestamps must remain finite. Allocation and transition budgets are checked before the trajectory allocation. No workers, clocks, network access or durable mutable state are created.

The historical CS_STATE_SPACE_SIM retains its existing MIMO shapes, budgets, and post-update output convention C*x[k+1] + D*u[k]. It shares the same native recurrence through a compile-time output-timing choice. Its results are not silently reinterpreted as the new model profile. Existing Signal/DSP, ODE integration, and general eigenvalue functions remain independently usable.

Continuous-time discretization, MIMO composition, transfer export, unit-aware signals, mixed-rate coupling, delay/block-language elaboration, controller synthesis, frequency-domain margins and physical actuation are outside this profile. They remain tracked in the S12 completion ledger.