Generated reference › Covariance Method — Control Systems/Spectral Measurements
kind: generated#block#control-systems-spectral-measurements

Covariance Method — Control Systems/Spectral Measurements

C

Control_Systems/Spectral_Measurements/Covariance_Method · 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.

Covariance Method

Control Systems / Spectral Measurements

Estimates the power spectral density of a signal frame parametrically: it fits an order-p autoregressive model by the covariance method – exactly as the Covariance AR Estimator block does – and evaluates the spectrum that model implies,

Pxx[k] = G·Ts / |A(ej2πk/nfft)|², k = 0 … nfft−1,

where A is the prediction-error filter, G the model's error variance and Ts the time between samples of the series. This is MATLAB's pcov with 'twosided' and a sampling frequency of 1/Ts.

It fits the forward predictor x[n] ≈ −Σaix[n−i] by least squares over the N−p rows that fit wholly inside the frame (no windowing), and the error variance is the mean squared residual over those rows.

Ports

  • u – the signal frame x, an [N,1] column; N must be at least 2p – MATLAB's arcov rule; below it there are fewer prediction rows than unknowns and the normal equations are singular.
  • Pxx – the power spectral density, [nfft,1]: all nfft bins, two-sided, bin k at frequency k/(nfft·Ts). Units of power per hertz when Ts is in seconds.

Parameters

  • Estimation Order – p, a whole number of 1 or more. Defaults to 6, as Simulink's does.
  • FFT Length – nfft, the number of frequency bins, a whole number of 1 or more. Defaults to 256. It need not be a power of two. An nfft smaller than p+1 samples the spectrum of A wrapped modulo nfft rather than truncated – measured against the Simulink block, which does the same.
  • Series Sample Time (s) – Ts, the time between samples of the series the frame was cut from, a positive scalar. Defaults to 1. It only scales the answer: halving Ts halves every bin.
  • 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 frame length and the order are baked into the core at export time, and so are the FFT length, Ts and the nfft-point cosine and sine tables.

The three HDL targets are simulation-only: they carry the arithmetic in real and quantize only at the port boundary. The solve divides by elimination pivots that are not bounded away from zero, and the spectrum divides by |A|², which a Q16.16 datapath does not survive. The cores simulate correctly and are not offered as synthesizable.

Simulink bridge

Import and export, mapped to dspspect3/Covariance Method – the DSP System Toolbox block. "Estimation Order" to ord, "FFT Length" to fftsize and "Series Sample Time (s)" to Ts.

inheritFFT = off and inheritTs = off are always emitted. With inheritFFT on the Simulink block picks its own length, and with inheritTs on it takes Ts from the frame period divided by N – measured: a 16-sample frame arriving every second scales every bin by exactly 1/16. This block runs one frame per step and has no frame period to divide, so Ts is always the dialog's value. Importing a model whose block inherits its Ts keeps the block's dialog Ts, so its spectrum can come out scaled differently from Simulink's, by exactly that ratio.

"Sampling Time (s)" does not cross. dspspect3/Covariance Method defines no SampleTime parameter at all – verified against the R2026a block dialog – and set_param on a parameter a block does not define is a hard error that aborts the whole generated script.

Notes

  • Stateless and algebraic: the whole solve runs on this sample's frame. Nothing is carried between steps.
  • An all-zero frame gives NaN, as the Simulink block does – measured on the estimator: A = [1 NaN …], G = NaN, so every bin of the spectrum is NaN. There is no guard to switch on; feed it a frame with energy in it.
  • The frame rule is stricter than the Simulink block's. That block accepted p = 7 on a 12-sample frame, where only 5 prediction rows exist for 7 unknowns; this one refuses anything MATLAB's arcov refuses, because below that rule the answer is a number rather than an estimate.
  • The normal equations are solved by Gaussian elimination with partial pivoting. The Simulink block uses a Cholesky factorization and arcov a QR; on any frame this block accepts, the three agree to rounding.
  • Two-sided, every bin. Bins 1 … nfft−1 mirror about nfft/2 for a real frame; nothing is folded or doubled. For the one-sided density pcov gives by default, double bins 1 to nfft/2−1.
  • The three HDL targets' output port is Q16.16, whose largest value is 32767. The spectrum is G·Ts/|A|² and nothing keeps A's zeros off the unit circle (the covariance methods least of all) – a sharp enough peak overflows that port on those three targets while the other seven carry it. Scale Ts down to keep every bin in range; it only scales the answer.
  • Reach for the Covariance AR Estimator block for the model itself rather than its spectrum.

Code facts#

FactValue
registered typeControl_Systems/Spectral_Measurements/Covariance_Method
familyControl_Systems/Spectral_Measurements
solver environment classICoreBlock_0_Control_Systems_1_Spectral_Measurements_2_Covariance_Method
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Spectral_Measurements/Covariance_Method/ICoreBlock_0_Control_Systems_1_Spectral_Measurements_2_Covariance_Method.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Spectral_Measurements/Covariance_Method/ICoreBlock_0_Control_Systems_1_Spectral_Measurements_2_Covariance_Method.h
default size on canvas120 × 70 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
2outICoreDoublePxx

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
Estimation Order6ord
FFT Length256fftsize
Series Sample Time (s)1Ts

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::Both
Simulink pathdspspect3/Covariance Method
port-count rulePortsParam::None
SampleTime parameterno — the counterpart defines none; the rate stays on the ICore side
always setinheritFFT = off, inheritTs = off
ICore configSimulink parameterValue translation
Estimation Orderordpasses through
FFT Lengthfftsizepasses through
Series Sample Time (s)Tspasses through

Caveat (shown to the user): dspspect3/Covariance Method has NO SampleTime parameter (verified against the R2026a block dialog), so "Sampling Time (s)" does not cross. 'inheritFFT' and 'inheritTs' are pinned off: this block runs one frame per step and has no frame period to infer Ts from, so a model whose block inherits Ts imports with the dialog's Ts and a spectrum scaled by the ratio of the two

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

Description vs code#

The checker has a blind spot here — it could not resolve something (a grouped port bullet, a computed config name), which is reported and never counted as a pass. A reader has to settle it:

  • B0 every stimulus in the sample errored — cross-checks skipped

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).

Covariance Method block — the power spectral density of a signal frame through an AR model fitted by the covariance method MATLAB's pcov (two-sided, fs = 1/Ts) and the DSP System Toolbox block dspspect3/Covariance Method, both measured on R2026a first. Pxx[k] = G*Ts / |A(e^{j 2 pi k / nfft})|^2 over ALL nfft bins.

⚠ Ts IS THE TIME BETWEEN SAMPLES OF THE SERIES, and Simulink's default infers it as the FRAME PERIOD / N (measured: a flat ratio of exactly 1/16 on a 16-sample frame every 1 s, 1/24 on 24, exactly 0.25 with inheritTs off and Ts = 0.25). A step here carries one frame and no frame period, so inheritTs is pinned off and Ts is always the dialog's value.

The spectrum is a direct DFT of all p+1 coefficients with nfft-point cosine/sine tables, so an nfft below p+1 samples A wrapped modulo nfft -- which is what the Simulink block does too, measured at nfft = 4, p = 6.

The solve, the spectrum and all ten emitted bodies live in ICoreArEstimationSupport, beside the measurements that justify them; this file is the block's ports, parameters and bridge.

Code export: all ten targets. The three HDL ones are SIMULATION-ONLY real arithmetic -- the solve divides by quantities a Q16.16 datapath cannot carry.

Sample results#

No stimulus produced a sampled output in this rig — Invalid input size at Covariance Method block: ICore Blocks/Home/Covariance Method. That is a fact about the single-block rig, not a verdict on the block: an offline batch fit, a block whose output only appears at onSolverFinish, or one that needs a driven environment cannot be exercised alone.

Category unsampled · sample time 0.1 · 60 steps · commit 358d2d933 · produced by docsSample --out <folder> --blocks Burg_AR_Estimator Yule_Walker_AR_Estimator Covariance_AR_Estimator Modified_Covariance_AR_Estimator Burg_Method Yule_Walker_Method Covariance_Method Modified_Covariance_Method --steps 60

Sample data: docs/generated/samples/Control_Systems__Spectral_Measurements__Covariance_Method.json