FIR Equiripple Design — Control Systems/Polynomials
Control_Systems/Polynomials/FIR_Equiripple_Design · 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.
FIR Equiripple Design
Control Systems / Polynomials
Designs a linear-phase finite impulse response filter of order
N by the Parks-McClellan method and reports its
N + 1 taps, with the centre of the transition band arriving
on a port. It is MATLAB's firpm for two bands: the taps
minimise the largest weighted error W(f)·|H(f) −
D(f)| over both bands, so the error ripples with equal height across each
band – the transition between the bands being a region it ignores.
With fc on the port and tw the transition
width, the bands are [0, fc − tw/2] and
[fc + tw/2, fs/2], which is
firpm(N, [0 fc−tw/2
fc+tw/2 fs/2]/(fs/2), [1 1 0 0],
[Wp Ws]) for a lowpass and the same with
[0 0 1 1] and the weights swapped for a highpass. The answer is
the fixed point of the Remez exchange on a dense frequency grid, and the
grid moves with the band edges, so the whole design is redone on every
step.
It designs; it does not filter. Feed b to Discrete / Transfer Fcn Direct Form II Time Varying's Num port and a Constant of 1 to its Den, as for FIR Window Design.
Ports
- fc – the centre of the transition band, in Hz. Scalar. Clamped into [tw, fs/2 − tw] – see Notes.
- b – the filter's taps, in the order a delay line consumes them, as a column of N + 1 entries. The response is symmetric, so the vector reads the same forwards and backwards.
Parameters
- Order – N, a whole number from 3 to 64
(
firpmrefuses an order below 3). The output is N + 1 long and the group delay is N/2 samples. An even order is a type I filter and an odd one a type II, whose response is zero at Nyquist. Default 12. - Filter Type – which band is the passband:
- Lowpass – desired response 1 below the transition and 0 above it. Default.
- Highpass – 0 below and 1 above. Requires an even order – see Notes.
- Transition Width (Hz) – tw, the width of the don't-care region centred on fc. Strictly positive and below fs/4, and Order × tw must not exceed 10 fs – see Notes. Default 10.
- Passband Weight – Wp, the weight on the passband error. Strictly positive. Default 1.
- Stopband Weight – Ws, the same for the stopband. Only the ratio matters: the passband ripple comes out Ws/Wp times the stopband ripple. Strictly positive. Default 1.
- Sample Rate (Hz) – fs, the rate the filter is designed FOR and the rate the band edges are measured against. Strictly positive. This is not the block's own rate. Default 100.
- 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. Every setting is structural and is baked into the generated body, so nothing is exposed as a tunable parameter on the generated core. The body is the whole of firpm – the frequency grid, the Remez exchange and the final inverse transform – as loops over local arrays, and it is the same program the block runs, printed once per language rather than transcribed ten times. Its cost per step grows with the order: the grid holds at most about 8·N points, and the exchange repeats until its set of extremal frequencies stops changing – at most 250 passes, as in MATLAB.
The three HDL targets are simulation-only, and deliberately: an
iterative exchange over real-valued arrays does not belong in a Q16.16 datapath.
The design runs in real (VHDL inside a procedure) and the taps
convert at the port boundary. The seven software targets are exact.
Simulink bridge
None (Support::None). firpm is a MATLAB
function and no Simulink library block carries it. Every design block in the
DSP System Toolbox's filter-design library is a filter – signal in,
filtered signal out – so none exposes taps a diagram could read: the
Lowpass Filter and Highpass Filter blocks design an FIR from
ripple and attenuation targets rather than from firpm's weights, the
Lowpass/Highpass FIR Filter Design blocks are window-method, and
Digital Filter Design is an interactive designer with no parameter a
model could set. There is therefore no library path this block could name. The
bridge reports it rather than dropping it silently, and it has no parity
testbench; code export verification still covers it across all ten
languages. No configuration of it crosses either, including "Sampling Time
(s)", which has no counterpart to be written to.
Notes
- Algebraic, with no state: the output depends only on the current input; the exchange starts afresh on every step.
- The port carries the CENTRE of the transition, not a band edge, so a lowpass and a highpass on the same wire split the spectrum in the same place. It is clamped into [tw, fs/2 − tw] by (|x−lo| − |x−hi| + lo + hi)/2, branchless and identical in the block and in all ten emitted bodies, so each band always keeps at least half a transition width.
- The answer is firpm's on firpm's grid, to the bit. An equiripple design is optimal on a grid of 16 points per cosine, not on the continuous band, and a grid one rounding off moves every tap. The grid is built the way MATLAB's colon operator builds it – which is not a + k·d – so the two agree to rounding rather than merely closely.
- The output moves in small steps as fc slides, because the number of grid points in each band is a whole number that changes with the band edges. Measured: sweeping fc over 0.2 Hz in steps of 10−5 Hz at orders 13, 14 and 24, no step in any tap exceeds twice the median step (largest 1.3e−5), so the grid changes are smaller than the design's own smooth movement and far below its ripple (0.07 to 0.11 on the same designs).
- An odd order is refused for a highpass, and MATLAB does something
else. A symmetric FIR of odd order has a zero at Nyquist and so cannot pass
the top of the band;
firpmquietly increments the order and warns, and this block refuses, because its output size is Order + 1. Measured:firpm(9, ...)with a highpass response returns eleven taps, not ten. - The order-times-width limit is measured, and it is where MATLAB stops
being an answer. A transition wide for its order makes a design whose error
is at the floor of double precision, and there the exchange stops converging:
MATLAB's
firpmwarns that it did not converge, and the two can differ by whole units. Inside the limit the block agrees with it to 1.9e−10 or better on every tap. - Measured against R2026a, 1546 designs across the domain: worst
disagreement with
firpmon any tap 1.9e−10, at the domain boundary; away from it, through order 33, 1.1e−14. - No state space: one scalar in and one vector out, so there is no A/B/C/D to merge and model reduction correctly declines it.
Code facts#
| Fact | Value |
|---|---|
| registered type | Control_Systems/Polynomials/FIR_Equiripple_Design |
| family | Control_Systems/Polynomials |
| solver environment class | ICoreBlock_0_Control_Systems_1_Polynomials_2_FIR_Equiripple_Design |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Polynomials/FIR_Equiripple_Design/ICoreBlock_0_Control_Systems_1_Polynomials_2_FIR_Equiripple_Design.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Polynomials/FIR_Equiripple_Design/ICoreBlock_0_Control_Systems_1_Polynomials_2_FIR_Equiripple_Design.h |
| default size on canvas | 140 × 72 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 | fc |
| 2 | out | ICoreDouble | b |
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 |
|---|---|---|
Order | 12 | — |
Filter Type | Lowpass%~%Highpass~~Lowpass | — |
Transition Width (Hz) | 10 | — |
Passband Weight | 1 | — |
Stopband Weight | 1 | — |
Sample Rate (Hz) | 100 | — |
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): designing an equiripple FIR filter is a MATLAB function (firpm), not a Simulink library block -- every design block in the DSP System Toolbox's filter-design library is a filter (signal in, filtered signal out) that exposes no taps, and its Digital Filter Design block is an interactive designer with no settable parameter, 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 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).
FIR Equiripple Design -- firpm (Parks-McClellan) on a wire, with the transition centre on a port The taps that minimise the LARGEST weighted error between the response and an ideal lowpass or highpass, over two bands with a don't-care transition between them:
band edges [0, fc - tw/2] and [fc + tw/2, fs/2] fc on the port, tw a setting error max over both bands of W(f) * |H(f) - D(f)|
which is firpm(N, [0 fc-tw/2 fc+tw/2 fs/2]/(fs/2), [1 1 0 0], [Wp Ws]) and its highpass mirror. The answer is the fixed point of the Remez exchange on a dense frequency grid, and both the grid and the exchange move with the port -- so the whole of firpm runs on every step, here and in all ten generated languages, from the program in Polynomials/ICoreFirOptimalDesignSupport.
⚠ AN EXCHANGE'S ANSWER DEPENDS ON ITS GRID, SO THE GRID IS MATLAB'S TO THE BIT. firpm's answer is the minimax design ON its grid of 16 points per cosine, not the continuous optimum, and a grid one ulp off moves every tap. The grid is built by MATLAB's colon operator, which is not a + k*d (see the support file), and reproducing it is what took the agreement from "close" to rounding.
Verified against MATLAB R2026a rather than asserted: the shipped program, run through a standalone harness, against firpm over 1546 designs inside the block's domain (orders 3 to 64, both types, three weight pairs, transition centres across the clamp range and widths up to the domain limit). Worst disagreement on any tap 1.9e-10, at the domain boundary; away from it, through order 33, 1.1e-14.
Sample results#
| t | in ICoreDouble-Out-0 | out ICoreDouble-Out-0 [13x1] entry 0 |
|---|---|---|
| 0 | -2 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 0.4 | 0.5 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 0.8 | -2 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 1.2 | 0.5 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 1.6 | -2 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 2 | 0.5 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 2.4 | -2 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 2.8 | 0.5 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 3.2 | -2 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 3.6 | 0.5 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 4 | -2 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 4.4 | 0.5 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 4.8 | -2 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
| 5.2 | 0.5 | [-0.03294, 0.003098, 0.03636, 0.08771]… |
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.03294 … -0.03294 |
ramp | Ramp: slope 1 from t = 0 | -0.03294 … -0.03294 |
sine | Sine Wave: amplitude 1, 2 rad/s, no phase, no bias | -0.03294 … -0.03294 |
step | Step: 0 -> 1 at t = 1 s | -0.03294 … -0.03294 |
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 383c0ecf1501cf1d43d89b8f688fc2fcad5e9b52 · produced by docsSample --out <folder> --blocks Ideal_Airspeed_Correction WGS84_Gravity_Model Linear_Regression_Predictor Linear_Classifier_Predictor Crossover_Pilot_Model Precision_Pilot_Model Tustin_Pilot_Model FIR_Least_Squares_Design FIR_Equiripple_Design Cartesian_To_Keplerian_Elements Keplerian_Elements_To_Cartesian --steps 60 · data docs/generated/samples/Control_Systems__Polynomials__FIR_Equiripple_Design.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).