SFDR — Control Systems/Spectral Measurements
Control_Systems/Spectral_Measurements/SFDR · 1 input / 2 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.
SFDR
Control Systems / Spectral Measurements
The spurious-free dynamic range of a power spectrum, in decibels: how
far the largest remaining spur sits below the carrier once the carrier's own peak
has been taken out.
r = 10·log₁₀(Pcarrier / Pspur).
This is MATLAB's sfdr(Sxx, F, 'power'), transcribed from its
source.
The DC skirt goes first: bin 0 is doubled, and then every bin up to and including the first rise is discarded. The carrier is the largest bin left; its peak extends to where the spectrum stops falling away on each side, or to the minimum spurious distance if that is wider. The spur is the largest bin still standing after that peak is removed.
Ports
- p – the one-sided power spectrum, an [N,1] column or a [1,N] row of 3 to 64 bins. Bin k sits at frequency k·Δ, so the first bin is DC. ⚠ This is a spectrum, not a density: the values are compared directly and never integrated, which is why the bin spacing does not appear in the answer.
- sfdr – the range in dB, a scalar.
- fspur – the frequency of the spur that set it, in the axis's own units. It is the number that says whether a reading is about a real spur or about a shoulder of the carrier, which is what the distance below is for.
Parameters
- Bin Spacing – Δ, the frequency step between neighbouring bins, a single positive number. It places the axis and is compared against the distance below; it is not part of the measured ratio.
- Minimum Spurious Distance – a frequency half-width around the carrier, inside which a bin cannot be reported as a spur. Zero or more; zero is MATLAB's default and this block's. It widens the carrier's peak and never narrows it: a distance asking for less than the peak already occupies changes nothing.
- 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 bin count, the spacing and the distance are all settled before the run, so the five searches are unrolled at export time and no emitted core contains a loop or an array index that moves.
The three HDL targets are simulation-only: a base-10 logarithm
and a ratio of two run-time quantities do not belong in a Q16.16 datapath. They
carry the arithmetic in real and quantize only at the port
boundary.
Simulink bridge
No equivalent, so nothing crosses in either direction. Measured rather
than assumed: sfdr is a Signal Processing Toolbox function,
that toolbox ships no Simulink library at all, and a find_system
sweep of 2102 blocks across twenty DSP System Toolbox and Simulink library
roots – at depth 6, under masks – matches nothing for snr,
sinad, thd, sfdr, distortion, spurious or
noise ratio. Mixed-Signal Blockset, which does carry measurement blocks of
this kind, is not installed and is not one of the eight toolboxes this work
covers.
Notes
- Algebraic and stateless: the reading depends only on the spectrum presented this step.
- It is the odd one out in this family. SNR, SINAD and
THD integrate the power in a band and share one decomposition; this block
compares bin values and shares none of it. That is not a simplification – it
is what
sfdr.m's spectrum path does. - The DC skirt is removed by monotonicity, not by a band. On a spectrum that rises at its first step, nothing is removed at all – not even bin 0.
- MATLAB rejects a spectrum with an empty bin here where it accepts one for the other three readings. A streaming block cannot stop a run over one sample's value, so instead both logarithms are floored: a spectrum with no spur left reports a large positive range rather than infinity, and one with no power at all reports 0 dB.
- The spur frequency is a bin centre, never interpolated, because the measurement is a comparison of bins.
Code facts#
| Fact | Value |
|---|---|
| registered type | Control_Systems/Spectral_Measurements/SFDR |
| family | Control_Systems/Spectral_Measurements |
| solver environment class | ICoreBlock_0_Control_Systems_1_Spectral_Measurements_2_SFDR |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Spectral_Measurements/SFDR/ICoreBlock_0_Control_Systems_1_Spectral_Measurements_2_SFDR.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Spectral_Measurements/SFDR/ICoreBlock_0_Control_Systems_1_Spectral_Measurements_2_SFDR.h |
| default size on canvas | 140 × 80 px |
| ports at insert | 1 in, 2 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 | p |
| 2 | out | ICoreDouble | sfdr |
| 3 | out | ICoreDouble | fspur |
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 |
|---|---|---|
Bin Spacing | 1 | — |
Minimum Spurious Distance | 0 | — |
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): no Simulink equivalent. snr is a Signal Processing Toolbox MATLAB function, not a block; that toolbox ships no Simulink library, and a sweep of 2102 blocks across twenty DSP System Toolbox and Simulink library roots carries no signal-to-noise, SINAD, THD or SFDR measurement block
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:
B0every 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).
SFDR -- spurious-free dynamic range, from a power spectrum (MATLAB sfdr(Sxx, F, 'power') and sfdr(Sxx, F, MSD, 'power')) r = 10*log10( Pcarrier / Pspur )
⚠ IT SHARES NO ARITHMETIC WITH THE OTHER THREE READINGS IN THIS FAMILY, and that is measured rather than a design choice: sfdr.m's spectrum path never calls bandpower, never integrates a band, and never uses the bin spacing except to report a frequency. It compares BIN VALUES. So this block takes a POWER SPECTRUM where SNR, SINAD and THD take a density, and it carries its own reference and its own emitted body rather than an option on theirs. What it does share is the family's ten DIALECTS, which live once in ICoreSpectralDistortionSupport.cpp.
The whole algorithm, transcribed from psfdr() and getPeakBorder():
b = the spectrum, with the DC BIN DOUBLED every bin up to and including the FIRST RISE is zeroed (the DC skirt) carrier = the largest bin left lo, hi = where the spectrum stops falling away from it on each side, WIDENED to the minimum spurious distance if that is wider b[lo..hi] = 0 spur = the largest bin now left
⚠ MEASURED AGAINST R2026a BEFORE ANY OF THIS WAS WRITTEN, on four spectra and two distances, every number reproduced by a Python stand-in first:
p1 = [0.05 0.10 3.00 0.40 0.90 0.12 0.30 0.08 0.20 0.06 0.15 0.04], delta = 0.25 MSD 0 -> 5.2287874528033749 dB, spur -0.45757490560675118 dB at 1 Hz MSD 0.45 -> 10 dB EXACTLY, spur -5.2287874528033758 dB at 1.5 Hz p2 = [0.12 0.85 2.40 1.10 0.35 0.60 0.18 0.07], delta = 0.5 MSD 0 and 0.45 both -> 6.0205999132796242 dB, spur at 2.5 Hz p4 = sixteen bins at delta = 0.2 MSD 0 -> 4.9884050441289860 dB, spur at 1.2 Hz MSD 0.45 -> 7.6768581670547862 dB, spur at 2.4 Hz p5 = [2.50 0.80 0.30 1.90 0.25 0.40 0.15 0.06], delta = 0.5 MSD 0 and 0.45 both -> 6.7669360962486644 dB, spur at 2.5 Hz
⚠ p1 AT MSD = 0.45 IS THE ROW THAT PINS THE WIDENING: without it the spur is the carrier's own right shoulder at 1 Hz, which is the failure the parameter exists to prevent. p2 and p5 pin the opposite case -- a distance that asks for LESS than the peak already occupies changes nothing, because the two widths are combined by taking whichever is wider and never by replacing one with the other.
Sample results#
No stimulus produced a sampled output in this rig — Invalid input size at: ICore Blocks/Home/SFDR. 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 477e53523 · produced by docsSample --out <folder> --blocks SNR SINAD THD SFDR --steps 60
Sample data: docs/generated/samples/Control_Systems__Spectral_Measurements__SFDR.json