FFT Magnitude — Machine Learning/Feature Engineering
Machine_Learning/Feature_Engineering/FFT_Magnitude · 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.
FFT Magnitude
Machine Learning / Feature Engineering
The magnitude spectrum of a window – the feature front end for anything vibration- or audio-trained. Feed it a window of N samples and it returns the N spectral bins:
y[k] = |FFT(u)[k]|² (default), or |FFT(u)[k]|.
Ports
- u – the window, an [N,1] column, with N a power of two. Build it with a Tapped Delay if the signal arrives one sample at a time.
- Output – [N,1], the full-length spectrum. Both halves are emitted: for a real input the upper bins mirror the lower ones, and they are still returned rather than folded away, because that is what the Simulink block this maps to does.
Parameters
- Output
- Magnitude squared – |FFT|², the power spectrum. This is the default, matching the Simulink block, and it is the cheaper of the two because it needs no square root.
- Magnitude – |FFT|, the amplitude spectrum.
- Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.
There is deliberately no FFT-length parameter: the length is the width of the window you connect. That is what keeps this block and its Simulink counterpart in step, since the counterpart is pinned to inherit its length from the frame as well.
Code export
All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text. The transform is emitted fully unrolled with every twiddle factor baked in as a literal, so no target needs a loop, an index type or a scratch array, and no sine or cosine is evaluated at run time.
The three HDL targets are simulation-only: they carry the
spectrum in real arithmetic and quantize only at the port boundary.
A power spectrum squares its input's magnitude, so a Q16.16 datapath would
saturate on inputs a user will really produce, and the Magnitude option
needs a square root besides. Same pattern, and the same reasoning, as Dense
Layer.
Simulink bridge
Both directions, mapping to dspxfrm3/Magnitude FFT from
the DSP System Toolbox – a single block, not an FFT wired to a magnitude.
Output crosses as mag_or_magsq, and the two option strings
are Simulink's own, so the translation is 1:1 and lossless.
Three parameters are pinned rather than exposed, and each would otherwise
change the answer: fftLenInherit is on, so Simulink takes its
FFT length from the frame exactly as this block does – left off, its
fftsize default of 256 would zero-pad an 8-sample window and move
every bin; FFTImplementation is Radix-2; and
WrapInput stays at its default. ⚠ The block has no
SampleTime parameter, so the rate does not cross – a block configured
with an explicit rate reports that it did not.
Notes
- Algebraic and stateless: the spectrum depends only on the window presented this step. The windowing itself belongs upstream.
- No state space. The map is quadratic in the input for the squared option and not even polynomial for the other, so no A/B/C/D can be true of it.
- There is no 1/N scaling, matching the Simulink block: a ramp 1…8 gives y[0] = 1296, which is 36², not 162.
Code facts#
| Fact | Value |
|---|---|
| registered type | Machine_Learning/Feature_Engineering/FFT_Magnitude |
| family | Machine_Learning/Feature_Engineering |
| solver environment class | ICoreBlock_0_Machine_Learning_1_Feature_Engineering_2_FFT_Magnitude |
| source | src/ICoreSDK/ICoreBlockLibrary/Blocks/Machine_Learning/Feature_Engineering/FFT_Magnitude/ICoreBlock_0_Machine_Learning_1_Feature_Engineering_2_FFT_Magnitude.cpp |
| header | src/ICoreSDK/ICoreBlockLibrary/Blocks/Machine_Learning/Feature_Engineering/FFT_Magnitude/ICoreBlock_0_Machine_Learning_1_Feature_Engineering_2_FFT_Magnitude.h |
| default size on canvas | 130 × 80 px |
| ports at insert | 1 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 | u |
| 2 | out | ICoreDouble | y |
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 |
|---|---|---|
Output | Magnitude squared%~%Magnitude~~Magnitude squared | mag_or_magsq |
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::Both |
| Simulink path | dspxfrm3/Magnitude FFT |
| port-count rule | PortsParam::None |
SampleTime parameter | no — the counterpart defines none; the rate stays on the ICore side |
| always set | fftLenInherit = on, FFTImplementation = Radix-2 |
| ICore config | Simulink parameter | Value translation |
|---|---|---|
Output | mag_or_magsq | passes through |
Caveat (shown to the user): maps to the DSP System Toolbox's Magnitude FFT. The FFT length is NOT a parameter on either side: Simulink is pinned to inherit it from the frame (fftLenInherit = on) exactly as this block takes it from the window width, so the two cannot disagree. Note the block has no SampleTime parameter, so an explicit rate does not cross the bridge
Catalog contract: src/ICoreSDK/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).
FFT Magnitude — the magnitude spectrum of a window, bridged to dspxfrm3/Magnitude FFT Magnitude squared: y[k] = |FFT(u)[k]|^2 (Simulink's default) Magnitude: y[k] = |FFT(u)[k]|
The ONE block in this family with a real Simulink counterpart, so it is Support::Both and owes a parity testbench (§5). Every convention it implements was measured against the real block rather than assumed -- full length N, no 1/N scaling, magnitude-SQUARED by default, length inherited from the frame, and no SampleTime parameter. See the header.
⚠ The transform is emitted as an unrolled DFT with the twiddle factors baked in as literals, NOT as a staged radix-2 butterfly. For the window sizes a feature front end actually uses that is the right trade: no target needs a loop bound, an index type or a scratch array; the arithmetic is identical in all eleven evaluators by construction; and nothing transcendental runs per sample, since every cos/sin is evaluated once, here, at generation time. The cost is N^2 emitted products, which at the default N = 8 is 64 -- the same bargain Dense_Layer makes by unrolling its weights.
Sample results#
No stimulus produced a sampled output in this rig — Invalid window length at: ICore Blocks/Home/FFT Magnitude. 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 ccf005c8 · produced by docsSample --out <folder> --steps 60
Sample data: docs/generated/samples/Machine_Learning__Feature_Engineering__FFT_Magnitude.json