Generated reference › Spectrogram — Control Systems/Time Frequency
kind: generated#block#control-systems-time-frequency

Spectrogram — Control Systems/Time Frequency

Control_Systems/Time_Frequency/Spectrogram · 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.

Spectrogram

Control Systems / Time Frequency

The short-time Fourier transform of a stream: a windowed, one-sided transform of the last L samples, taken every hop samples – MATLAB's spectrogram, one column at a time:

Xj[m] = Σn w[n]·x[j·hop + n]·e−i2πmn/L,   m = 0 … L/2

published as the magnitude |Xj|, or as |Xj|² scaled to a power spectral density or a power spectrum.

Ports

  • u – the sampled signal. Scalar: one channel and its own window.
  • S – the current frame, [L/2+1, 1], one-sided with DC first and Nyquist last. It changes only on a frame sample and holds in between (see Frames and timing).

Parameters

  • Window Length – L, the frame and transform length: an even whole number from 4 to 32. Even because a one-sided spectrum needs a Nyquist bin; bounded above because the transform is unrolled at export and its cost grows as L².
  • Hop Size – the samples from one frame to the next, 1 to L. MATLAB's noverlap is L − hop.
  • Window – Hamming (MATLAB's default), Hann or Rectangular: the symmetric windows MATLAB's hamming() and hann() return, so hamming(8) starts at 0.08.
  • Spectrum Type – what each bin carries:
    • Magnitude – |X[m]|, the magnitude of MATLAB's complex s output. Not doubled and not scaled.
    • Power spectral density – |X[m]|² ÷ (fs·Σw²) with every bin but DC and Nyquist doubled: MATLAB's ps output.
    • Power spectrum – |X[m]|² ÷ (Σw)², doubled the same way: ps with 'power'.
  • Bin Spacing – Δf, the frequency step between output bins in hertz; the sampling rate follows as fs = L·Δf. It is read only by the power-spectral-density scaling, and it is the same parameter under the same name as Welch PSD's.
  • Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.

Frames and timing

A frame is the last L samples, oldest first. The first is taken when the window first fills – at sample L − 1, counting from 0 – and then every hop samples, so the output at sample L − 1 + j·hop is frame j: column j of MATLAB's spectrogram(x, window, L−hop, L). Between frames the output holds the last one, because a wire holds; before the first frame it is all zeros.

Code export

All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text. The window, the transform's basis and the scale are fixed by the configuration and inlined as numbers, so no generated core computes a sine, a cosine or a division; all five settings are structural, so re-export after changing one.

The three HDL targets form the transforms and the squares in genuine Q16.16; only the Magnitude square root goes through real (simulation-only), exactly as Quaternion Modulus's does; the two squared types are fully synthesizable. Scale the signal into roughly ±1 first: a frame sums L windowed samples and the block then squares or multiplies.

Simulink bridge

None (Support::None). spectrogram is a Signal Processing Toolbox function and that toolbox ships no Simulink library, 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: a register of L samples, a frame counter and the held frame.
  • Verified against R2026a: for a twenty-sample record at L = 8, hop = 3, fs = 100, the Magnitude, Power-spectral-density and Power-spectrum frames match MATLAB's to the last printed digit (the source banner carries the numbers).
  • It is not Welch PSD. Welch PSD averages several segments and publishes every sample; this block publishes one segment per frame, every hop samples, and is the time axis a spectrum can be watched along.
  • No state space. |X| is not linear in the window, so model reduction correctly declines to merge it.

Code facts#

FactValue
registered typeControl_Systems/Time_Frequency/Spectrogram
familyControl_Systems/Time_Frequency
solver environment classICoreBlock_0_Control_Systems_1_Time_Frequency_2_Spectrogram
sourcesrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Time_Frequency/Spectrogram/ICoreBlock_0_Control_Systems_1_Time_Frequency_2_Spectrogram.cpp
headersrc/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Time_Frequency/Spectrogram/ICoreBlock_0_Control_Systems_1_Time_Frequency_2_Spectrogram.h
default size on canvas140 × 80 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
2outICoreDoubleS

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 Length8—
Hop Size4—
WindowSS::WIN_HAMMING%~%SS::WIN_HANN%~%SS::WIN_RECT~~SS::WIN_HA…—
Spectrum TypeSS::KIND_MAGNITUDE%~%SS::KIND_PSD%~%SS::KIND_POWER~~SS::K…—
Bin Spacing1—

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): spectrogram is a Signal Processing Toolbox function, 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 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 no sample under docs/generated/samples/ — nothing to cross-check (P8.1)

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

Spectrogram -- the short-time Fourier transform of a stream, MATLAB's spectrogram X_j[m] = SUM(n = 0..L-1) w[n] * x[j*hop + n] * exp(-j*2*pi*m*n/L), m = 0 .. L/2

published as |X_j| (Magnitude), |X_j|^2 / (fs*SUM w^2) with the interior bins doubled (Power spectral density), or |X_j|^2 / (SUM w)^2 likewise doubled (Power spectrum). A frame is taken when the window first fills and every hop samples after that, and HELD in between.

MEASURED AGAINST R2026a and the conventions are what was checked, not just the answer. For x = [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 -1.4 0.66 0.2 -0.9 1.05 0.4 -0.55], L = 8, hop = 3, fs = 100, spectrogram(x, hamming(8), 5, 8, 100) has five columns, and its first is |s| = [3.0548044070854017 1.3868583627003879 1.7263507692888216 1.4186726296108347 1.1350890245495107] -- |fft(hamming(8).*x(1:8)')| over bins 0..4 to the last digit, so the magnitude is NOT doubled; its second column is the frame starting three samples later (hop, not L-hop); and ps and the 'power' output match |X|^2/(fs*SUM w^2) and |X|^2/(SUM w)^2 with DC and Nyquist left undoubled, to the last digit.

Support::None: spectrogram is a Signal Processing Toolbox FUNCTION and that toolbox ships no Simulink library, so there is no counterpart to bridge to or run a parity testbench against.

Sample results#

No sample run is committed for this block. Samples come from the headless harness (DOCS_PLAN.md P8.1) into docs/generated/samples/; until one exists this block's behaviour is witnessed by the parity and export-verification suites, not by a plot here.