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

Gaussian Fit — Control Systems/Curve Fitting

Control_Systems/Curve_Fitting/Gaussian_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.

Gaussian Fit

Control Systems / Curve Fitting

Fits a sum of N Gaussians to the last W samples and emits its amplitudes:

ŷ(x) = Σi=1..n ai·exp( −((x − bi) ÷ ci)² )

This is MATLAB's gauss<n> model, and the output carries its amplitudes in that model's own order – a₁, a₂, …, an. The newest sample sits at x = 0 and the sample i steps back at x = −i·h, the same abscissa Polynomial Fit and Fourier Fit use. It is the useful half of peak fitting: known peaks, unknown strengths.

Ports

  • u – the sampled signal being fitted. Scalar: one channel and its own window – see Notes.
  • a – the amplitude column, [n, 1], in the order above. Its height follows Number of Terms alone.

Parameters

  • Window Length – W, how many samples the fit sees. A whole number from 3 to 101, and it must be at least n: n amplitudes cannot be determined by fewer than n points. Bounded above because the dot products are unrolled at export.
  • Number of Terms – n, a whole number from 1 to 8, matching MATLAB's gauss1…gauss8. Each term adds one Gaussian and one output row.
  • Centres – [b₁ … bn], an n element vector giving where each bump sits on the fitted axis, in the same units as Abscissa Step. The window covers −(W−1)·h to 0, so a centre far outside that range contributes a nearly flat column and conditions the fit badly.
  • Widths – [c₁ … cn], an n element vector of strictly positive numbers. MATLAB's c is the 1/e half width, not a standard deviation: c = σ·√2.
  • Abscissa Step – h, the spacing between consecutive samples on the fitted axis. A single positive number. Set it to the sampling period and give the centres and widths in seconds, or leave it at 1 and give them in samples.
  • 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 n×W coefficient bank is structural and is inlined into the arithmetic at export time rather than exposed as a tunable parameter: it follows from all five settings, and changing any of them changes how many multiplies and how many outputs the core contains. Re-export after changing them. No exponential is evaluated in any generated core – every one of them was evaluated once, at export time, to build the bank.

The three HDL targets are genuine synthesizable Q16.16: a shift register and one fixed multiply-accumulate per amplitude, with the products accumulated at full width and shifted back once per row.

Simulink bridge

None (Support::None). Fitting a sum of Gaussians to a running window is a Curve Fitting Toolbox function (fit with a gauss<n> 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 centres and widths are parameters here and MATLAB solves for them. That is the one real departure from fit(x, y, 'gauss2'), and it is what makes the block possible: with b and c unknown the fit is nonlinear and needs an iterative solver every sample; with both given it is an ordinary linear least squares whose design matrix is fixed by the configuration. If the peak positions are what you are looking for, this is the wrong block – find them first and set them here.
  • ⚠ 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 amplitudes against a basis of exponentials. Wiring this block into any of the three produces a number rather than an error, so the mistake is silent.
  • One solve, then arithmetic. The small normal-equation system is solved once when the configuration loads; every sample afterwards is n fixed dot products.
  • ⚠ Not every setting is a fit, and the block refuses rather than guessing. Two terms given the same centre and width are the same column, and the fit has no unique answer; two bumps that overlap almost that far have one, but the window can barely tell them apart and the normal matrix is ill conditioned long before it is singular. The singular case is detected when the configuration loads and reported with a reason – rather than emitting the arbitrary answer a pseudo-inverse would have produced. Keep the centres at least a width apart and neither case arises.
  • Verified against MATLAB. At W = 13, n = 2, h = 0.4, centres [−1.1 −3.3] and widths [0.9 1.7], R2026a's own least-squares solve of the same design matrix answers a = [0.3030382460638365, 0.21965420016626469] on a fixed 13-sample window; this block reproduces both entries to 1.0e−15 relative, with cond(A'A) = 2.23. Solving the normal equations squares the condition number where a QR solve does not, which is the price of collapsing the whole fit into one inlined bank of numbers instead of putting a factorization in ten generated cores; it costs nothing at a conditioning like that one.
  • MATLAB's width is not a standard deviation. exp(-((x-b)/c)^2) has no factor of two in the exponent, so c = σ·√2 and the bump's full width at half maximum is 2·c·√(ln 2).
  • The window is zero-prefilled, and the zeros count. The first W−1 amplitude vectors of a run are a startup transient, matching Moving Median, Detrend, Savitzky-Golay Filter, Polynomial Fit and Fourier Fit.
  • Scalar only. One channel and its own history; wire one block per channel.
  • No state space. Linear in the input, but through a fixed filter bank over W past samples rather than an A/B/C/D pair, so model reduction correctly declines to merge it.

Code facts#

FactValue
registered typeControl_Systems/Curve_Fitting/Gaussian_Fit
familyControl_Systems/Curve_Fitting
solver environment classICoreBlock_0_Control_Systems_1_Curve_Fitting_2_Gaussian_Fit
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Curve_Fitting/Gaussian_Fit/ICoreBlock_0_Control_Systems_1_Curve_Fitting_2_Gaussian_Fit.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Curve_Fitting/Gaussian_Fit/ICoreBlock_0_Control_Systems_1_Curve_Fitting_2_Gaussian_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
2outICoreDoublea

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—
Number of Terms2—
Centres[-2 -6]—
Widths[1.5 2.5]—
Abscissa Step1—

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 a sum of Gaussians to a running window is a Curve Fitting Toolbox function (fit with a gauss<n> 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).

Gaussian Fit -- the least-squares sum of N Gaussians through the last W samples MATLAB's gauss<n> fittype with the centres and widths GIVEN rather than identified:

y(x) = SUM(i = 1..n) a_i * exp( -((x - b_i) / c_i)^2 )

Output order is a1 .. an -- coeffnames(fittype('gauss2')) in R2026a reports {a1 b1 c1 a2 b2 c2}, and b and c are this block's parameters rather than part of its answer.

With b and c given the fit is LINEAR, so the whole normal-equation system is solved once per configuration load and what every target carries is n fixed dot products over one shift register. The solve itself is ICoreCurveFitBankSupport's, shared with Sum_Of_Sines_Fit. See the header for why the centres and widths had to move from the answer to the question.

TRANSCRIBED FROM R2026a and checked against a run of it rather than inferred. At W = 13, n = 2, h = 0.4, centres [-1.1 -3.3] and widths [0.9 1.7], over the window

y = [1.2 -0.7 2.5 0.3 -1.9 0.8 1.1 -2.2 0.45 1.7 -0.35 0.62 -1.4] (oldest first)

MATLAB's own least-squares solve of the same design matrix (A\y, a QR solve) answers a = [0.3030382460638365, 0.21965420016626469]. This block reproduces both entries to 1.0e-15 relative, and cond(A'A) there is 2.23.

⚠ NO EXPONENTIAL SURVIVES INTO A GENERATED CORE. Every exp() is evaluated once, here, to build the bank; the ten targets carry the resulting numbers and nothing else. That is what makes the three HDL targets genuine synthesizable Q16.16 rather than simulation-only.

Sample results#

Gaussian Fit — Step: 0 -> 1 at t = 1 sGaussian Fit — Step: 0 -> 1 at t = 1 s00.51012345t (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)-0.05971 … 0.5385
rampRamp: slope 1 from t = 00 … 6.64
sineSine Wave: amplitude 1, 2 rad/s, no phase, no bias-1.24 … 1.239
tableRepeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sample-1.47 … 2.444

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

Category dynamic · sample time 0.1 · 60 steps · commit 5ec6520e9ab09131166ee577848f504dc1883d0f · produced by docsSample --out <folder> --blocks Gaussian_Fit Sum_Of_Sines_Fit --steps 60 · data docs/generated/samples/Control_Systems__Curve_Fitting__Gaussian_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).