Generated reference › Exponential Fit — Control Systems/Curve Fitting
kind: generated#block#control-systems-curve-fitting

Exponential Fit — Control Systems/Curve Fitting

Control_Systems/Curve_Fitting/Exponential_Fit · 1 input / 1 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Description#

The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.

Exponential Fit

Control Systems / Curve Fitting

Fits a single exponential to the last W samples and emits its two parameters:

ŷ(x) = a·exp(b·x)

This is MATLAB's exp1 library model, and the output carries a then b – coeffnames(fittype('exp1'))'s own order. The newest sample sits at x = 0 and the sample i steps back at x = −i·h, the same abscissa Polynomial Fit, Fourier Fit and Gaussian Fit use, so a is the fitted value now and b is the growth rate per unit of that axis – positive for growth, negative for decay.

Ports

  • u – the sampled signal being fitted. Scalar: one channel and its own window – see Notes.
  • ab – the parameter column, [2, 1]: row 1 is a, row 2 is b. Its height is fixed and does not follow any setting.

Parameters

  • Window Length – W, how many samples the fit sees. A whole number from 3 to 101. Two parameters need at least two points, and a third is the first that makes it a fit rather than an interpolation. Bounded above because the dot products are unrolled at export.
  • Abscissa Step – h, the spacing between consecutive samples on the fitted axis. A single positive number. Set it to the sampling period and b comes out per second; leave it at 1 and b comes out per sample.
  • Ordinate Floor – the smallest ordinate the fit will consider. A single strictly positive number. A sample at or below it is treated as being at it, because an exponential is strictly positive and a sampled signal is not: the logarithm has no answer at zero or below. Set it just under the smallest value the signal legitimately reaches; a floor far below that lets a single dropout dominate the fit, because in the log domain the distance from 0.001 to 1 is the same as the distance from 1 to 1000.
  • Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.

Code export

All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text.

The 2×W coefficient bank is structural and is inlined into the arithmetic at export time rather than exposed as a tunable parameter: it follows from the window length and the abscissa step together, and changing either changes how many multiplies the core contains. Re-export after changing them. The floor is inlined as a constant beside its own logarithm.

A generated core carries exactly two transcendental calls per step – one ln of the incoming sample and one exp of the fitted intercept. Both are the model itself and neither can be folded away; the basis, by contrast, never reaches a core at all, having been evaluated once at export time to build the bank.

The three HDL targets are simulation-only real arithmetic, quantizing only at the port boundary: a logarithm and an exponential have no Q16.16 form. They additionally clamp the amplitude to the [0, 32767] that format can carry, which the seven software targets and this block's own simulation do not.

Simulink bridge

None (Support::None). Fitting an exponential to a running window is a Curve Fitting Toolbox function (fit with the exp1 model), and that toolbox ships no Simulink library at all, so there is no path a diagram could name. The bridge reports this block rather than dropping it silently, and it therefore has no parity testbench; code export verification still covers it across all ten languages.

Notes

  • Stateful, and discrete by nature (setDiscreteOnlyBlock(true)): the window advances once per sample.
  • ⚠ The fit is done in the log domain and MATLAB's is not. Taking logarithms turns ln y = ln a + b·x into an ordinary straight-line least squares whose design matrix is fixed by the configuration – which is what lets the whole solve happen once and every sample afterwards be two dot products. fit(x, y, 'exp1') instead minimises the residual in y by iteration, weighting large ordinates more heavily, and no closed form produces its answer. The two agree only on data that lies exactly on an exponential. Measured on the thirteen-sample window in this block's source banner, the log-domain answer is a = 0.4164, b = −0.1662 and R2026a's exp1 answers a = 0.5021, b = −0.1844 – 17 % and 11 % apart. If the y-residual objective is what you need, fit offline; this block is the one that runs in a generated core.
  • ⚠ Only the single-term model is offered. MATLAB's exp2, a·ebx + c·edx, does not survive the logarithm – a sum of exponentials has no linear form – so it would need an iterative solve every sample in ten backends. With the two rates given rather than fitted it becomes linear again, and that is exactly the shape Gaussian Fit and Sum of Sines Fit already have.
  • ⚠ The ordinate is floored, and the floor is part of the answer. Every sample at or below Ordinate Floor enters the fit as that floor, in all ten targets and in this block's own simulation alike. Flooring is not a convenience: VHDL's LOG asserts on a non-positive argument, which aborts a simulation rather than returning a bad number, so it has to exist somewhere and it exists in one place.
  • One solve, then arithmetic. The 2×2 normal-equation system is solved once when the configuration loads; every sample afterwards is two fixed dot products over the window, plus the one logarithm and the one exponential.
  • The window holds logarithms, and is prefilled at y = 1. The register stores ln y rather than y, so the logarithm is taken once per sample rather than W times; every backend zero-initializes its state, and zero in that register means ln y = 0. The first W−1 outputs of a run are therefore a startup transient, as they are on Detrend, Savitzky-Golay Filter, Polynomial Fit, Fourier Fit and Gaussian Fit.
  • ⚠ Its output is NOT a polynomial, and Evaluate Fit cannot read it. Evaluate Fit, Fit Derivative and Fit Integral all speak coefficients in descending powers; these are the two parameters of an exponential. Wiring this block into any of the three produces a number rather than an error, so the mistake is silent. To evaluate the fitted curve at some x, compute a·exp(b·x) with a Math Function and a Gain.
  • For a power law, use Power Fit. y = a·xb is the same straight line against ln x instead of x, and Power Fit is that block.
  • Scalar only. One channel and its own history; wire one block per channel.
  • No state space. Linear in ln y and not in y, so there is no A/B/C/D pair to seed and model reduction correctly declines to merge it.

Code facts#

FactValue
registered typeControl_Systems/Curve_Fitting/Exponential_Fit
familyControl_Systems/Curve_Fitting
solver environment classICoreBlock_0_Control_Systems_1_Curve_Fitting_2_Exponential_Fit
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Curve_Fitting/Exponential_Fit/ICoreBlock_0_Control_Systems_1_Curve_Fitting_2_Exponential_Fit.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Curve_Fitting/Exponential_Fit/ICoreBlock_0_Control_Systems_1_Curve_Fitting_2_Exponential_Fit.h
default size on canvas130 × 72 px
ports at insert1 in, 1 out
code generators implementedPython, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text

Ports#

#DirectionSignal typeDescription label
1inICoreDoubleu
2outICoreDoubleab

Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.

Configuration variables#

Config variableDefaultSimulink parameter
Window Length12—
Abscissa Step1—
Ordinate Floor1e-6—

Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.

supportSupport::None
Simulink path—
port-count rulePortsParam::None
SampleTime parameteryes

Caveat (shown to the user): fitting an exponential to a running window is a Curve Fitting Toolbox function (fit with the exp1 model), not a Simulink library block -- that toolbox ships no Simulink library at all -- so there is no path a diagram could name; the block is reported rather than dropped when a model crosses

Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h

Description vs code#

The lists agree. check_block_descriptions.py finds no disagreement between the description's Ports, Parameters, Code export and Simulink bridge lists and the code's.

The verdict above is tools/docs/check_block_descriptions.py (P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.

File banner (developer view)#

The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).

Exponential Fit -- MATLAB's exp1 library model over the last W samples, as the pair (a, b) y(x) = a * exp(b * x)

coeffnames(fittype('exp1')) in R2026a reports {a b}, and the output column carries them in that order. The abscissa is the family's: the newest sample at x = 0, the sample i steps back at x = -i*h.

THE FIT IS DONE IN THE LOG DOMAIN. ln y = ln a + b*x is a straight-line least squares whose design matrix is settled by the configuration, so the normal-equation system is solved ONCE per configuration load and every sample afterwards is two fixed dot products over one shift register. fit(x, y, 'exp1') minimises the residual in y instead, by iteration; the two objectives agree only on data lying exactly on an exponential.

MEASURED AGAINST R2026a rather than asserted. Over the thirteen-sample window

y = [1.2 0.7 2.5 0.3 0.12 0.8 1.1 -0.22 0.45 1.7 0.35 0.62 0.09] (oldest first)

at W = 13, h = 0.4 and an ordinate floor of 0.28, MATLAB's own straight-line solve of the same points, polyfit(x, log(max(y, 0.28)), 1), answers

b = -0.16620991902881643 ln a = -0.87617328483395829 a = 0.41637320860634985

and cond(A'A) there is 34.13. This block reproduces both to 1e-15 relative. On the SAME data MATLAB's nonlinear fit(x, y, 'exp1') answers a = 0.50205895512231191, b = -0.18436721774974324 -- 17 % and 11 % away, which is the size of the objective difference on data that is not exponential, and is quoted in the description rather than hidden.

⚠ NO LOGARITHM OF A CONFIGURED VALUE SURVIVES INTO A GENERATED CORE: the bank is numbers. The two transcendental calls a core does carry are one ln() of the incoming SAMPLE and one exp() of the fitted intercept, both unavoidable -- they are the model.

Sample results#

Exponential Fit — Step: 0 -> 1 at t = 1 sExponential Fit — Step: 0 -> 1 at t = 1 s02040012345t (s)in ICoreDouble-Out-0out ICoreDouble-Out-0 [2x1] entry 0

The same rig also ran:

StimulusWhat it isOutput range
impulseImpulse: one sample of 1 at k = 5, 0 elsewhere (Repeating Sequence Stair)1.701e-7 … 0.01701
rampRamp: slope 1 from t = 00.01468 … 6.49
sineSine Wave: amplitude 1, 2 rad/s, no phase, no bias2.458e-8 … 35.39
tableRepeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sample2.031e-6 … 0.01701

Plotted: step — Step: 0 -> 1 at t = 1 s

Category dynamic · sample time 0.1 · 60 steps · commit 94aea539e1b63d0ffbcf829426bcd09d1d2a53e5 · produced by docsSample --out <folder> --blocks Exponential_Fit Power_Fit --steps 60 · data docs/generated/samples/Control_Systems__Curve_Fitting__Exponential_Fit.json · the SVG is generated from those numbers by tools/docs/plot_svg.py, so it is a run and not a drawing (R-D10).