Cross Spectrogram — Control Systems/Time Frequency
Control_Systems/Time_Frequency/Cross_Spectrogram · 2 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.
Cross Spectrogram
Control Systems / Time Frequency
The cross spectrum of two streams, frame by frame – MATLAB's
xspectrogram, one column at a time:
Cj[m] = |Xj[m]·Yj*[m]| · scale[m]
where Xj and Yj are the windowed one-sided transforms of the same L-sample frame of each input. A bin is large where the two signals share energy at that frequency in that frame, which is what separates a common component from two unrelated ones of the same size.
Ports
- x – the first signal, scalar.
- y – the second signal, scalar. The product conjugates y's transform; the published magnitude is the same either way round.
- C – 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.
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
noverlapis L − hop. - Window – Hamming (MATLAB's default), Hann or
Rectangular: the symmetric windows MATLAB's
hamming()andhann()return, sohamming(8)starts at 0.08. - Spectrum Type – the scaling of the cross spectrum before its
magnitude is taken:
- Power spectral density – ÷
(fs·Σw²), every bin but DC and Nyquist doubled:
xspectrogram's default. - Power spectrum – ÷ (Σw)², doubled the same way:
'power'.
- Power spectral density – ÷
(fs·Σw²), every bin but DC and Nyquist doubled:
- 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
xspectrogram(x, y, 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 basis and the scale are 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; the magnitude of the cross product – a square root of a sum of squares of products – goes through real (simulation-only), exactly as Quaternion Modulus's root does. 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). xspectrogram 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: two registers of L samples, a frame counter and the held frame.
- ⚠ It publishes the MAGNITUDE.
xspectrogramreturns a real matrix – |P| of the scaled complex cross spectrum – and this block matches it, so a negative product in the Nyquist bin comes out positive. The phase between the two signals is not on the port. - Verified against R2026a: for two twenty-sample records at L = 8,
hop = 3, fs = 100, both scalings match MATLAB's to the last printed
digit, and
xspectrogram(x, x)is exactly Spectrogram's power spectral density. - No state space. The product of two transforms is not linear.
Code facts#
| Fact | Value |
|---|---|
| registered type | Control_Systems/Time_Frequency/Cross_Spectrogram |
| family | Control_Systems/Time_Frequency |
| solver environment class | ICoreBlock_0_Control_Systems_1_Time_Frequency_2_Cross_Spectrogram |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Time_Frequency/Cross_Spectrogram/ICoreBlock_0_Control_Systems_1_Time_Frequency_2_Cross_Spectrogram.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Time_Frequency/Cross_Spectrogram/ICoreBlock_0_Control_Systems_1_Time_Frequency_2_Cross_Spectrogram.h |
| default size on canvas | 140 × 92 px |
| ports at insert | 2 in, 1 out |
| code generators implemented | Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreDouble | x |
| 2 | in | ICoreDouble | y |
| 3 | out | ICoreDouble | C |
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 variable | Default | Simulink parameter |
|---|---|---|
Window Length | 8 | — |
Hop Size | 4 | — |
Window | SS::WIN_HAMMING%~%SS::WIN_HANN%~%SS::WIN_RECT~~SS::WIN_HA… | — |
Spectrum Type | SS::KIND_PSD%~%SS::KIND_POWER~~SS::KIND_PSD | — |
Bin Spacing | 1 | — |
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.
Simulink bridge#
| support | Support::None |
| Simulink path | — |
| port-count rule | PortsParam::None |
SampleTime parameter | yes |
Caveat (shown to the user): xspectrogram 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:
B0no 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).
Cross Spectrogram -- the frame-by-frame cross spectrum of two streams, MATLAB's xspectrogram C_j[m] = | X_j[m] * conj(Y_j[m]) | * scale[m]
with X_j, Y_j the windowed one-sided transforms of the same L-sample frame of each input, and scale[m] = 1/(fs*SUM w^2) (Power spectral density) or 1/(SUM w)^2 (Power spectrum), every bin but DC and Nyquist doubled. Framing and holding as Spectrogram's.
MEASURED AGAINST R2026a. ⚠ xspectrogram returns a REAL matrix: the MAGNITUDE of the scaled complex cross spectrum, not the product itself. For the twenty-sample x of Spectrogram's banner, y = [0.3 -0.5 1.1 0.9 -0.2 0.4 -1.3 0.8 0.05 0.6 -0.7 1.4 0.2 0.33 -0.45 0.9 1.2 -0.1 0.25 0.7], L = 8, hop = 3, fs = 100, the first column is [0.01384753702 0.01456165371 0.01190725483 0.01308568806 0.003431054134], and |X.*conj(Y)|/(fs*SUM w^2), interior doubled, gives exactly those numbers -- including the Nyquist bin, where the product is -0.00343 and the published value is +0.00343. 'psd' is the default; 'power' matches (SUM w)^2 likewise. And xspectrogram(x, x, ...) equals spectrogram's ps to 0, which is what ties the two blocks' scalings together.
Support::None, for Spectrogram's reason.
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.