FFT Shift — Control Systems/Transforms
Control_Systems/Transforms/FFT_Shift · 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 Shift
Control Systems / Transforms
Swaps the halves of a spectrum so that the zero-frequency bin sits in the middle instead of at the start – the rearrangement a spectrum needs before it is plotted against a ±fs/2 axis. With p = floor(N/2):
Forward: y[k] = u[(k − p) mod N], and Inverse: y[k] = u[(k + p) mod N].
Ports
- u – the window to rotate, [N,1] or [1,N], with N any length of at least 1. There is no power-of-two rule: a rotation needs no radix.
- y – the rotated window, the same size and the same orientation as u. A column comes back a column.
Parameters
- Direction
- Forward (fftshift) – moves the zero-frequency bin to the middle. This is the default and the common direction.
- Inverse (ifftshift) – puts it back at the start, undoing the forward map. The two differ whenever N is odd, and at an odd N the forward map is not its own inverse, so this option is the only way to round-trip such a window.
- 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 rotation is settled before the run starts, so every target emits it as a fixed list of copies with no modulo and no index arithmetic at run time.
The three HDL targets are fully synthesizable and exact, not
simulation-only: a constant rotation is wiring. No value is converted to
real on the way through, so the Q-format word arrives at the output
bit for bit.
Simulink bridge
No equivalent, so nothing crosses in either direction. The Signal
Processing Toolbox offers fftshift and ifftshift as
MATLAB functions only – there is no Simulink block for either, in that
toolbox or in the DSP System Toolbox, whose transform library carries FFT, IFFT,
Magnitude FFT, DCT, IDCT, the two cepstra, the two wavelet transforms, Analytic
Signal, the two Short-Time FFTs and Zoom FFT and no shift among them. A model
that needs the rotation on the Simulink side builds it from a Selector.
Notes
- Algebraic and stateless: the output depends only on the window presented this step.
- No state space. A permutation is a genuine D matrix, but one of N² entries carrying no dynamics at all, and every target already emits the copies directly.
- At an even N the two directions coincide, and the block is then its own inverse. At an odd N they do not, and applying the forward map twice does not return the original window.
Code facts#
| Fact | Value |
|---|---|
| registered type | Control_Systems/Transforms/FFT_Shift |
| family | Control_Systems/Transforms |
| solver environment class | ICoreBlock_0_Control_Systems_1_Transforms_2_FFT_Shift |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Transforms/FFT_Shift/ICoreBlock_0_Control_Systems_1_Transforms_2_FFT_Shift.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Transforms/FFT_Shift/ICoreBlock_0_Control_Systems_1_Transforms_2_FFT_Shift.h |
| default size on canvas | 120 × 70 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 |
|---|---|---|
Direction | Forward (fftshift)%~%Inverse (ifftshift)~~Forward (fftshift) | — |
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. fftshift and ifftshift are MATLAB functions in the Signal Processing Toolbox, not blocks, and the DSP System Toolbox's transform library has no shift block either. A Simulink model that needs the rotation builds it from a Selector
Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h
Description vs code#
The lists agree. check_block_descriptions.py finds no disagreement between the description's Ports, Parameters, Code export and Simulink bridge lists and the code's.
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 Shift -- swap the halves of a spectrum, so the zero-frequency bin lands in the middle Forward: y[k] = u[(k - floor(N/2)) mod N] MATLAB fftshift Inverse: y[k] = u[(k + floor(N/2)) mod N] MATLAB ifftshift
A rotation, not arithmetic. The permutation depends only on the window length and the direction, both settled before the run starts, so every backend emits a fixed list of copies -- no modulo, no index arithmetic, nothing evaluated per sample.
⚠ FORWARD AND INVERSE ARE THE SAME MAP ONLY AT AN EVEN N. Measured against R2026a: fftshift([1 2 3 4 5]) = [4 5 1 2 3] ifftshift([4 5 1 2 3]) = [1 2 3 4 5] fftshift twice = [2 3 4 5 1] -- so it does NOT round-trip A block offering only the forward map would quietly fail to undo itself on every odd window, which is exactly why MATLAB ships the two functions separately.
N is ANY length >= 1: a rotation needs no radix, so there is no power-of-two rule here. The output keeps the input's ORIENTATION, as MATLAB's does.
Algebraic and stateless. No state space: a permutation matrix would be a true A/B/C/D, but it is a D of N^2 entries carrying no dynamics, and every backend already emits the copies directly (see the header).
Sample results#
| t | in ICoreDouble-Out-0 | out ICoreDouble-Out-0 |
|---|---|---|
| 0 | -2 | -2 |
| 0.4 | 0.5 | 0.5 |
| 0.8 | -2 | -2 |
| 1.2 | 0.5 | 0.5 |
| 1.6 | -2 | -2 |
| 2 | 0.5 | 0.5 |
| 2.4 | -2 | -2 |
| 2.8 | 0.5 | 0.5 |
| 3.2 | -2 | -2 |
| 3.6 | 0.5 | 0.5 |
| 4 | -2 | -2 |
| 4.4 | 0.5 | 0.5 |
| 4.8 | -2 | -2 |
| 5.2 | 0.5 | 0.5 |
Every 4th of 60 samples, from the table stimulus.
The same rig also ran:
| Stimulus | What it is | Output range |
|---|---|---|
impulse | Impulse: one sample of 1 at k = 5, 0 elsewhere (Repeating Sequence Stair) | 0 … 1 |
ramp | Ramp: slope 1 from t = 0 | 0 … 5.8 |
sine | Sine Wave: amplitude 1, 2 rad/s, no phase, no bias | -1 … 0.9996 |
step | Step: 0 -> 1 at t = 1 s | 0 … 1 |
Plotted: table — Repeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sample
Category static · sample time 0.1 · 60 steps · commit 2b8440534 · produced by docsSample --out <folder> --blocks FFT_Shift Bit_Reverse_Order Walsh_Hadamard_Transform Goertzel --steps 60 · data docs/generated/samples/Control_Systems__Transforms__FFT_Shift.json · the SVG is generated from those numbers by tools/docs/plot_svg.py, so it is a run and not a drawing (R-D10).