Skip to content

About

FIR for FPGA applications in Verilog. Optional folding for reduced signal rate

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

FIR Folding Generator

A parameterized, bit-accurate FIR filter generator for FPGAs. One Verilog core (rtl/fir_folded.v) covers every folding factor — fully parallel (F=1), fully serial (F=N), and in between — a second core (rtl/fir_ssr_core.v) covers the super-sample-rate (SSR) form that processes R samples per clock, and a third (rtl/fir_polyphase.v) is the polyphase rate-changer — a D:1 decimation core (or 1:I interpolation, mirror image) whose D/I arms share ceil(N/(D*F)) MACs over a D*F-phase frame, and a fourth (rtl/fir_axi_top.v) wraps P independent streams (I/Q branches, MIMO channels) into one packed byte-aligned AXI4-Stream via the PATHS parameter. The tools emit only the coefficient ROM, a tiny parameter-binding wrapper, and the chosen parameters.

Two front-ends produce the same deliverables:

  • GUI (src/gui.py) — design the filter interactively, verify it, export the core, or print the CLI command that reproduces the design.
  • Command line (src/export_core.py) — the same export headlessly, for scripts and version control.

The exported Verilog is verified bit-exactly against cycle-accurate golden models under Verilator, Icarus Verilog and Questa FSE, and the folded core synthesizes on Xilinx (Vivado) and Lattice ECP5 (yosys + nextpnr-ecp5).

For the Python API (golden models, error analysis, stimuli), see GOLDEN_MODEL.md and src/ — the GUI/CLI are the intended entry points.

Requirements

  • Python 3.8+
  • numpy (DSP analysis / stimuli)
  • matplotlib (optional, only for plots/GUI frequency response)
pip install -e .          # all of src/ becomes importable (see pyproject.toml)
pip install -r requirements-dev.txt   # numpy + matplotlib (dev/test extras)

The core flow (config, golden models, RTL export) is pure stdlib; numpy is required by the analysis/stimuli modules and matplotlib by the plotting/GUI modules. pyproject.toml declares both as optional extras (pip install -e .[all]).

For bit-exact RTL verification, one of the simulators is needed: Verilator, Icarus Verilog, or Questa FSE (all optional; tests are skipped when absent).

GUI (recommended)

python3 src/gui.py

FIR Folding Generator GUI

  1. Coefficients — paste or load a coefficient file (one per line, # comments, blank lines ignored). The examples dropdown loads any filter from coefficients/examples/ (halfband 15-tap, highpass 33-tap, lowpass 31/16-tap — all linear-phase designs); the first entry is preloaded.

  2. FPGA family — pick a part preset (Artix-7, UltraScale+, ECP5, Gowin); this sets the sample/coefficient widths to the DSP multiplier maximums.

  3. Parameters — folding factor F, decimation D, interpolation I (1:I upsampling, folded or polyphase), SSR, paths (paths / num_paths / PATHS, multi-channel), and the sample/output/coefficient/ accumulator widths. Toggle symmetric (pre-adder halves the DSPs for linear-phase taps), halfband (skip zero taps), polyphase (the D:1 polyphase rate-changer; non-symmetric by design) and the gain target (off / 1.00000 / 0.99999; see Gain normalization). An optional output gain field adds a fixed per-sample output-gain multiplier (e.g. 2.0 to compensate the 1/I gain of a gain-1 interpolator).

  4. Live stats — DSP count (per path and total for multi-channel), coefficient depth, input/output rate, latency, the quantized DC gain and its total gain error are updated as you type; the "Derived" and "AXI stream bits" panels sit on tabs. The plot area has two tabs: Freqz plots ideal vs. quantized frequency response, and the Chirp tab sweeps a chirp through the golden model of the loaded filter and draws a before/after waterfall (spectrum vs time, with the -3 dB edge marked).

  5. Verify — bit-exact sanity check: the folded, SSR, polyphase and interpolation cores under Verilator and Icarus Verilog (all configurations are verified against the golden models; simulators are auto-detected).

  6. Export core… — writes the integrator deliverables to a directory:

    • fir_folded.v / fir_ssr_core.v / fir_polyphase.v — the chosen core (plus fir_quant.vh, the shared output-quantization include)
    • fir_top.v — the parameter-binding wrapper (wide group interface in SSR mode)
    • fir_coeffs.mem — the coefficient ROM (two's-complement hex)
    • fir_taps.mem — tap-index ROM (halfband designs only)
    • fir_params.vh — the concrete parameters as a Verilog header; compiled with -DFIR_PARAMS_VH, fir_axi_top.v takes its parameter defaults from this header (self-contained standalone build)
    • params.txt — the chosen parameters
    • coeff_map.txt — coefficient → RAM address ordering, the quantization contract, and a C float→word helper

    Every configuration is exportable: folded, SSR (wide group interface) and polyphase, with or without multi-path (PATHS) and coefficient banks (fir_axi_top + axi_lite_coeff.v ship when either is active).

    Coefficient banks (COEFF_BANKS, default 1) double the coefficient RAM and add a bank-select register — every bank is preloadable through the AXI4-Lite port and the active bank is switched at runtime with one write to the BANKSEL register (see doc/runtime_coeffs.md; fixed map: 0x000 ID, 0x004 bank select, coefficients from 0x200; the AXI4-Lite port runs in its own clock domain via s_axi_aclk / s_axi_aresetn); this is an RTL elaboration parameter on all cores and fir_axi_top. Compiling with -DFIR_COEFF_RAM_BLOCK maps the coefficient storage to block RAM instead of distributed RAM (serial builds only — NUM_MACS == 1 and INTERPOLATION == 1, checked by an elaboration error in both styles; see doc/runtime_coeffs.md). The coefficient register is driven identically in both styles, so the mapping changes resources, never latency or values. In the GUI set coeff banks > 1; the export then ships the reload-capable fir_axi_top wrapper (AXI4-Lite port exposed).

  7. CLI… — prints the src/export_core.py command line that reproduces the current design headlessly; paste it into a terminal or build script.

Quartus synthesis (src/quartus_export.py)

Synthesis for Intel/Altera devices (Cyclone V) via Quartus Prime: quartus_map runs out-of-context (no I/O pins needed) and reports DSP multiplier usage + logic cells; --synth adds the Fitter + TimeQuest.

The Cyclone V DSP target (src/dsp_target.py) models the variable-precision DSP block: high-precision 27×27 = 1 multiplier per block, native 18×18 = 2 per block (per the device handbook). The default 25×18 FIR lands in the 27×27 high-precision multipliers (Quartus: 8× "Independent 27x27" for the F=2 folded core → 8 DSP blocks):

python3 src/quartus_export.py --coeff coefficients/lowpass_16tap.txt \
  --folding-factor 2 --dsp-mode hp --outdir build/quartus

--dsp-mode native models the 18×18 mode (2 per block; note the fitter packs our MAC structure at 1 per block — the tool prints expected vs. actual).

Command-line export (src/export_core.py)

The same export as the GUI's Export core…, from the command line — the same files, same parameters, same coefficient ROM:

python3 src/export_core.py --coeff coefficients/lowpass_16tap.txt \
  --folding-factor 16 --gain 1.0 --outdir build/export

Coefficients can be passed inline instead of from a file:

python3 src/export_core.py --coeffs "0.25, 0.25, 0.25, 0.25" \
  --folding-factor 4 --outdir build/export

Writes the chosen core (fir_folded.v / fir_ssr_core.v / fir_polyphase.v), fir_top.v, fir_coeffs.mem, fir_params.vh, params.txt and coeff_map.txt into <outdir>/rtl/ (plus fir_axi_top.v + axi_lite_coeff.v when multi-path or coefficient banks are active) and prints the quantized DC gain and its total gain error.

Options

Option Meaning
--coeff FILE / --coeffs "…" coefficient file (one per line) or inline list
--folding-factor F F = N/M; 1 = parallel (max DSP), N = fully serial; need not divide N (zero-padded)
--decimation D output every D-th sample (D <= F)
--interpolation I 1:I interpolation: I outputs per input sample (I*F <= N, F >= clog2(M)+1); the I polyphase arms share ceil(N/(I*F)) MACs over an I*F-phase frame; mutually exclusive with --ssr and --decimation
--ssr R >1 = super-sample-rate core (R samples/clock, powers of 2 only; wide group interface: R samples in, R/D out per clock)
--coeff-banks B coefficient banks (power of two, default 1); with B>1 the export ships fir_axi_top + axi_lite_coeff.v with the AXI4-Lite reload port exposed in its own clock domain (preload every bank at 0x200…, switch with a write to 0x004)
--sample-width signed input width (default 25)
--output-width signed output width (defaults to sample width)
--coef-width signed coefficient width (default 18)
--coef-frac coefficient fractional bits (default 14)
--accum-width accumulator width (default 48, the native DSP sum)
--symmetric half the DSPs via the pre-adder (taps must be symmetric)
--halfband skip zero taps; auto-enables --symmetric; errors unless the taps are halfband and symmetric
--gain T normalize the quantized DC gain: 1.0 = exact unity, < 1.0 (e.g. 0.99999) = one LSB below unity
--output-gain G fixed per-sample output-gain multiplier, applied pre-quantization (one widening multiply; a pure shift for power-of-two gains). E.g. 2.0 compensates the 1/I gain of a gain-1 interpolation filter at I=2. Range (0, 16.0), quantized to 14 fractional bits
--outdir output directory (default build/export)

The GUI's CLI… button prints exactly this command for the current design.

Design concepts

AXI4-Stream byte alignment (AMBA)

All stream TDATA widths are multiples of 8 bits with every packed lane at a byte boundary (AMBA AXI4-Stream): a W-bit data word occupies the low W bits of a ceil(W/8)*8-bit lane, zero-padded above. Packed streams (the SSR group interface, and the internal R-sample gearbox) place lane i at [i*PITCH +: W] — e.g. two 12-bit samples at [11:0] and [27:16] on a 32-bit TDATA. The GUI's "AXI stream bits" panel and the exported params.txt report the byte-aligned widths.

Folding factor F

F = samples per output (MACs per lane). num_macs = ceil(N / F): F=1 is a fully parallel filter (1 sample/cycle, max DSPs), F=N is fully serial (1 MAC), anything in between is time-multiplexed. F need not divide N; the filter is zero-padded to the next multiple. The MAC stage runs continuously: steady-state throughput is one sample per F cycles, latency F + 2 + ceil(log2(M)) + 1 cycles.

Decimation D

Folds a D:1 downsampler into the F-cycle frame: D samples are accepted per frame, the delay line shifts by D once per frame, and one output is produced per frame. D <= F (a larger D would need a high-rate input commutator).

For polyphase decimation (use_polyphase, separate core doc/polyphase.md) the D polyphase arms h_p[j] = h[p + D*j] share ceil(N/(D*F)) MAC lanes over a D*F-phase frame: one shared delay line read at stride D, tap mux and coefficient ROM at the same stride-D index, one continuous accumulator per lane summing the arms in arm-major order. D× fewer multipliers than naive decimation at the same input rate, D > F becomes legal, and the symmetric pre-adder is deliberately not supported (the mirror tap of k = p + D*j lies in a different arm in the general case — see the doc). Verified bit-exactly under Icarus/Verilator, incl. output backpressure and runtime reload (fir_axi_top with USE_POLYPHASE = 1).

Interpolation I

interpolation = I is the exact mirror of D:1 decimation, in both the folded core and fir_polyphase: one input sample per frame is accepted and I outputs are emitted (one per polyphase arm h_p[j] = h[p + I*j] — the output phases). The delay line becomes a stride-1 sample window (the same window is read for every arm), and the accumulator wraps once per arm so the tree emits one sample per arm, gated by per-arm taps on the accept history. The folded and polyphase interpolators share the same arm-major datapath and are bit-identical. Constraints: I*F <= N, F >= clog2(M) + 1 (the per-arm sum tree must finish before the next arm's snapshot); symmetry, halfband, the BRAM delay line, ssr and decimation are rejected with interpolation > 1 (the mirror tap of k = p + I*j lies in another output phase, so the pre-adder cannot be applied per phase).

Gain: interpolation does not compensate the zero-stuffing 1/I — the per-output-sample DC gain of a gain-1 filter is sum(h)/I (each arm sums to 1/I). Set --output-gain I (e.g. 2.0 at I=2) to restore unity per-sample gain — a single pre-quantization multiplier, cheaper than folding the gain into the coefficients (which would cost coefficient bits and can push COEF_WIDTH past the DSP's 18-bit B input).

Super-sample-rate core (SSR = R)

SSR = R selects the SSR core instead of the folded core. The core (rtl/fir_ssr_core.v) is a pure group core with a wide interface: R samples per clock in, R/D outputs per clock out, one tvalid/tready per group. It computes R full N-tap dot products per cycle (delay line shifted by R per group). The 1:R input capture and R:1 output FIFO gearboxes are not in RTL — they live in the testbenches/caller (the sample-rate stream tests inline them next to the core). The dot-product datapath is pipelined like the folded core — fabric registers after the tap mux and coefficient RAM, DSP AREG/DREG/BREG/MREG/PREG, and a registered fabric sum tree — so it closes timing on FPGAs. Throughput is one group per clock at the group interface (R samples per clock at the sample rate). Symmetry halves the multiply count; decimation D <= R drops output phases (R/D outputs per group). SSR is restricted to powers of 2 with R <= N (the delay line is N deep) and D must divide R (the core emits R/D outputs per group); invalid combinations are rejected at config time. R = 2, 4, 8 are verified bit-exactly under Icarus/Verilator — including non-divisible N % R != 0, symmetric odd/even taps, halfband, decimation with D < R (multi-output groups), gapped tvalid and m_axis_tready backpressure (FIFO-full stalls freeze the core via its clock enable; values never change, only latency) — and the SSR core synthesizes on Artix-7 at 250 MHz (OOC: 32 DSP48E1 non-symmetric, 16 with symmetry). Runtime coefficient reload works through the same shared fir_axi_top top (USE_SSR = 1) and is verified at R = 2 and R = 4; only the synthesis export tooling is still pending — see doc/PLAN.md.

Multi-path (PATHS = P)

P independent streams at the same rate (I/Q branches, MIMO channels — not supersampled; distinct from SSR, which runs one stream at R samples/clock) are wrapped by rtl/fir_axi_top.v (PATHS=P, --multi-path P): a generate loop instantiates the folded core P times, each path with its own delay line, sharing one packed AXI4-Stream. The P lanes are byte-aligned (lane p at [p*PITCH +: W]), the tvalid/tready handshake is shared (the identical cores run in lockstep), and the single AXI4-Lite slave broadcasts coefficient-reload writes to all P coefficient RAMs. P=2, F=2 synthesizes to 16 DSP48E1 (2× the single-path 8) at WNS +0.575 ns @250 MHz on xc7a100t. A shared-MAC variant (frame partitioned across paths instead of P× area) is only worth it when DSPs are the binding constraint.

Symmetry (--symmetric)

Halves the DSP count for linear-phase filters: each symmetric tap pair x[n-k] + x[n-(N-1-k)] is summed in the DSP48 pre-adder before the multiply; the coefficient ROM holds only the ceil(N/2) unique taps. The pre-adder sum is DATA_WIDTH+1 bits, so it must fit the multiplier's A input (26-bit data on DSP48E2, 24-bit on DSP48E1 — 25-bit data on Artix falls back to a slow fabric multiply, and the tool warns about this).

Halfband (--halfband)

Halfband filters have every odd-indexed tap zero (except the center) — and a true halfband filter is also symmetric (linear phase). --halfband therefore auto-enables --symmetric and validates both criteria, erroring out if either fails (a coefficient set whose odd taps are zero but that is not symmetric is rejected too). The tools then skip the zero taps: the folded core stores the compressed nonzero taps plus a fir_taps.mem index ROM; the SSR core prunes them with a compile-time TAP_MASK. The delay line is never compressed — only the schedule — so the DSP count drops to ceil(active_taps / F).

Gain normalization (--gain)

Fixed-point quantization shifts the DC gain: the bundled 16-tap lowpass, for example, quantizes to a gain of 16386 / 2^14 = 1.000122, so a full-scale DC input overflows the output by 2048 LSB. --gain fixes this by moving the quantized taps by ±1 LSB at a time, least-error move first (so the correction is spread over the taps rather than piled onto one), until the weighted DC sum is exactly the target:

  • --gain 1.0 → sum = 2^CFRAC (exact unity — no overflow);
  • --gain 0.99999 (or any value < 1.0) → sum = 2^CFRAC - 1, one LSB below unity — a safe margin under the maximum.

Only sums that are multiples of gcd(weights) are reachable, so a below-unity target can be unreachable: with an even-length symmetric filter every weight is 2 (and on a halfband set the protected center tap usually leaves only weight-2 moves), so 2^CFRAC - 1 cannot be hit and the sum lands on the nearest even value — which may be unity itself, i.e. the margin is not bought. The CLI and GUI then print a warning rather than staying quiet, and so does a --gain request far from the coefficient set's own DC gain (e.g. --gain 1.0 on a highpass, whose tap sum is ~0: normalization would retune the filter rather than round it).

The weights are the datapath's DC weights (1 per tap, or 2 per unique tap for the symmetric pre-adder); halfband structural zeros are never touched. The adjustment is minimal (typically 1–2 taps by 1 LSB) and deterministic, and it is verified: FIRConfig.quantized_gain_sum is compared against FIRConfig.gain_target_sum, the difference is FIRConfig.gain_normalization_miss (in LSB, positive = above the request) and FIRConfig.gain_normalization_move reports how far any single tap had to move. The GUI/CLI report the total gain error of the resulting coefficients (ideal sum vs. quantized gain, in absolute, percent and dB).

Output gain (--output-gain) vs. gain normalization (--gain)

--gain works on the coefficients (nudges the quantized taps so the filter's DC gain hits the target); --output-gain is a separate fixed per-sample multiplier applied to the output datapath (pre-quantization). They are orthogonal — use --gain to set the filter's tap gain exactly, and --output-gain for a rate-change scaling that must not touch the coefficient table (e.g. the interpolation 1/I compensation: --output-gain I restores unity per-sample gain while the coefficients stay the designed taps). The output gain costs one widening multiply at the output rate (a pure shift for power-of-two gains) and keeps runtime reload, halfband masks and AXI-Lite coefficient readback unaffected.

Output width scaling

The full-precision sum is always computed at the native DSP accumulator width (48 bits) and truncated to output_width. The output fractional bits are derived automatically from the width delta (output_width - sample_width, clamped to the available precision), so a DC signal keeps the same real amplitude across width changes — e.g. a 16-bit DC value 24576 passes through a unity-gain filter to a 20-bit output as 24576 * 2^4 = 393216.

Synthesis (Vivado / ECP5)

The cores are synthesized out of context as modules in a larger design. The exporters emit the same deliverables as the GUI/CLI plus a timing constraint and a Vivado batch script.

For fully-serial long filters (num_macs == 1) the delay line can be a BRAM ring buffer instead of the FF array + tap mux: --use-bram-delay-line (or FIRConfig(use_bram_delay_line=True)). N=1024 → 1× RAMB36, 453 LUTs, 1195 FFs, WNS +0.180 ns @250 MHz vs the FF version's 26.8k FFs + 7.3k LUTs (which fails timing); N=4096 → 3× RAMB36 vs 106.7k FFs (84% of the part). See doc/bram_delay_line.md.

Vivado (src/vivado_export.py):

python3 src/vivado_export.py --coeff coefficients/lowpass_16tap.txt \
  --part xc7a100tcsg324-1 --clk-mhz 200 --synth

Options: --part, --clk-mhz, --sample-width, --coef-width, --coef-frac, --accum-width, --folding-factor, --decimation, --interpolation I (1:I upsampling; per-arm folding F), --output-gain G (fixed per-sample output multiplier), --polyphase (polyphase D:1 / 1:I core; folding-factor is then the per-arm folding F), --ssr R (super-sample-rate core, powers of 2), --symmetric, --halfband, --gain, --outdir, --name. Vivado is located via $VIVADO_BIN (default /tools/Xilinx/2026.1/Vivado/bin/vivado); the clock target is auto-selected from the part family (Artix-7 = 250 MHz, UltraScale+/Versal = 500 MHz). --impl also runs implementation; WNS/WHS within 0.5 ns are reported as passing.

Synthesis results for the 16-tap lowpass (default widths 25×18, acc=48, frac=14):

Folding DSPs xc7a100t @250 MHz xcku3p @500 MHz
F=16 (serial) 1 WNS +0.665 ns WNS +0.599 ns
F=2 (8 lanes) 8 WNS +0.665 ns WNS +0.599 ns
F=1 (parallel) 16 — WNS +1.025 ns
F=2 symmetric 4 WNS +0.665 ns (24-bit data) WNS +0.455 ns

Polyphase core (--polyphase, N=16 lowpass, 25×18):

Config M DSPs LUTs FFs xc7a100t @250 MHz xcku3p @500 MHz
D=8, F=2 1 1 123 696 WNS +0.110 ns —
D=4, F=2 2 2 167 706 WNS +0.665 ns WNS +0.599 ns
D=2, F=2 4 4 260 894 WNS +0.665 ns —

SSR core (--ssr 2, N=16 lowpass, 25×18):

Config DSPs LUTs FFs xc7a100t @250 MHz xcku3p @500 MHz
SSR=2 32 1211 3597 WNS +0.287 ns WNS +0.561 ns

ECP5 open-source (yosys + nextpnr-ecp5, 18×18 sysDSP, 85k) — the same --polyphase / --ssr options as the Vivado exporter (src/ecp5_export.py):

Config MULT18X18D LUT4s FFs DP16KD
F=2 (folded) 8 630 1589 0 (coeffs in distributed RAM)
polyphase D=4, F=2 2 501 699 0
SSR=2 32 1042 4009 0

DSP counts follow the analysis exactly: N/F for the folded core, N/(D*F) for polyphase (16/(4·2) = 2), and R·N products for SSR (2·16 = 32). Note: the SSR core's coefficient ROM is held in registers (ram_style = "registers") — yosys's memory_libmap OOMs on its constant-address parallel reads.

DSP multiplier widths per family

The GUI's family presets set the sample/coefficient widths to the DSP multiplier maximums:

Family DSP sample × coeff accumulator
Xilinx 7-series (Artix/Kintex) DSP48E1 25 × 18 48
Xilinx UltraScale+ DSP48E2 27 × 18 48
Lattice ECP5 sysDSP (MULT18X18) 18 × 18 48
Gowin GW1N/GW2A MULTADD18X18 18 × 18 48

Symmetric pre-adder needs sample+1 ≤ the multiplier A width (subtract 1 from sample when enabling symmetry); the 18×18 parts have no pre-adder, so symmetry runs in fabric there.

Plots

Two scripts plot the actual simulated hardware (Verilator), not the golden model:

PYTHONPATH=src python3 src/hw_plots.py     # impulse + chirp, time + frequency
PYTHONPATH=src python3 src/dc_plots.py     # raw DC codes (output-width scaling)
  • src/hw_plots.py writes plots/hw_impulse_time.png, plots/hw_impulse_freq.png, plots/hw_chirp_time.png and plots/hw_chirp_waterfall.png (spectrogram).
  • src/dc_plots.py feeds piecewise-constant DC levels through the core and plots the raw integer codes (plots/dc_transfer_raw.png, plots/dc_time_raw.png) with the ideal unity-gain line, plus a table of every DC level with measured and ideal raw output codes.

Verification and tests

Every exported design is checked bit-exactly against the golden models: the tool quantizes the coefficients, generates an irregular-tvalid stimulus plus expected outputs from the model, simulates rtl/fir_folded.v, and compares the hardware output word-for-word. The same vectors run under Verilator, Icarus Verilog and Questa FSE; simulator tests are skipped automatically when the tool is absent (Questa additionally needs QUESTA_BIN and a license env var — see the test file).

python3 -m unittest discover -s tests -p 'test_*.py' -v

The suite (568 tests + 91 subtests across 30 test files) covers the golden models, quantization (incl. gain normalization), stimuli, error analysis, generated-artifact consistency, the CLI export, the GUI statistics module (gui_stats), the SSR core across R = 2/4/8 with symmetry/halfband/ decimation (incl. D < R multi-output groups), runtime coefficient reload, output backpressure and full-scale DC headroom. The handshake robustness of every core is pinned bit-exactly: m_axis_tready stalls (periodic and pseudo-random) and irregular tvalid gaps, alone and combined, across all folded-core configurations (symmetry, halfband, BRAM delay line, decimation D < F, the DECIMATION == FOLD corner, interpolation, F == 1), the polyphase decimator/interpolator, and the multi-path wrapper (tb/tb_stream_bp.v, tb/tb_multichannel_bp.v freeze-aware replay: stalls must only add latency, never change values or drop samples).

Two static checks complement the simulation suite (details in doc/coverage_formal.md):

  • Code coverage — a 50-configuration Verilator sweep under build/coverage/ exercises every core across the architecture corner cases (rounding/saturation arms, output-gain multiplier, odd-node sum trees, SW coefficient write/read-back, output backpressure, AXI4-Lite reload); the merged verilator_coverage report shows 100% line coverage on all five RTL modules (rtl/fir_folded.v, rtl/fir_polyphase.v, rtl/fir_ssr_core.v, rtl/axi_lite_coeff.v, rtl/fir_axi_top.v).
  • Formal verification — the folded core is checked with the yosys SAT engine (tb/formal/fir_folded_formal.sv): AXI-Stream output stability, the output causality/latency bound, exact-F-cycle output spacing and the reset-drain property are proven for both streaming and stalling consumers (clk2fflogic + -set-init-zero; the recipe matters, see the doc).

Handshake contract for tvalid gaps: arbitrary drops are supported on every core and configuration. The SSR core needs no buffering for gaps: it only shifts the delay line on accepted groups and its group-valid pipeline propagates the gap straight into m_valid, so a gapped input simply pauses the stream (at D == 1 / interpolation a missed accept simply delays the frame); and the folded/polyphase cores at DECIMATION > 1 freeze their whole datapath while an accept-window phase waits for its sample (rtl/fir_folded.v, rtl/fir_polyphase.v), so no frame can ever commit partially — gapped input always produces exactly the dense run's values, verified bit-exactly across all configurations and simulators (TestDecimationArbitraryGaps, TestPolyphaseDecimationArbitraryGaps, the gap+stall suites, and the multi-path wrapper).

Two consequences of the D > 1 freeze are worth knowing: a decimating core holds its final partial group until its remaining window samples arrive (a producer flushes by appending zero samples — every testbench driver does), and a partially filled group stalls the core (including undelivered prior outputs) until the missing samples arrive; with any contiguous producer both are invisible. See doc/issues.md for the history. CI (.github/workflows/test.yml) runs the suite on every push/PR, installing iverilog + verilator so the RTL tests actually run.

Runtime coefficient reload

rtl/fir_axi_top.v pairs any core (folded, the SSR core when USE_SSR = 1, or the polyphase core when USE_POLYPHASE = 1) with a dual-ported distributed coefficient RAM and a minimal AXI4-Lite slave, so coefficients can be changed at runtime without rebuilding (one coefficient per 32-bit word; the RAM keeps its $readmemh power-on contents). The AXI4-Lite slave (axi_lite_coeff.v), the top wiring and the Verilator reload testbench are shared between all cores — only the core-selection parameter differs. See doc/runtime_coeffs.md and the exported coeff_map.txt for the address ordering and the C float→word helper.

File layout

src/
  gui.py           Tkinter frontend (design, verify, export core, CLI… button)
  gui_stats.py     pure-Python design statistics for the frontends (unit-tested)
  export_core.py   command-line export of the GUI deliverable set
  vivado_export.py Vivado OOC synthesis
  ecp5_export.py   yosys + nextpnr-ecp5 open-source synthesis
  fir_gen.py       Verilator/Icarus/Questa artifact generation + bit-exact verification
  golden.py        golden models (FoldedFIRGoldenModel, SSRFIRGoldenModel, ...)
  config.py        FIRConfig + QuantizationConfig
  quant.py         canonical fixed-point quantize() (rounding/saturate/wrap, gain normalization)
  analysis.py      coefficient / frequency-response / gain error metrics
  stimuli.py       impulse, chirp, step, random, irregular-valid masks
  plotting.py      PNG plots (impulse, frequency response, error, DC raw codes)
  hw_plots.py      hardware-vs-model output plots (from Verilator captures)
  dc_plots.py      raw-code DC transfer/time plots for output-width scaling
rtl/
  fir_folded.v     parameterized folded FIR core (decimation D, interpolation I)
  fir_ssr_core.v   super-sample-rate (parallel) group core: R samples/clock
                   in, R/D samples/clock out (wide group interface; the
                   sample-rate gearboxes live in the testbenches)
  fir_polyphase.v  polyphase rate-changer: D:1 decimation or 1:I interpolation
                   (the arms share M MACs over an arms*F-phase frame;
                   non-symmetric by design)
  fir_axi_top.v    folded/SSR/polyphase FIR + AXI4-Lite port (USE_SSR /
                   USE_POLYPHASE selects core) and P independent streams
                   (PATHS=P) packed into one byte-aligned AXI4-Stream
  axi_lite_coeff.v AXI4-Lite slave for runtime coefficient reload (shared)
  fir_quant.vh     shared output-quantization function (included at module
                   scope by the three cores; mirrors src/quant.py)
coefficients/      example coefficient files
doc/               architecture.md, runtime_coeffs.md, PLAN.md, report.md,
                   polyphase.md, bram_delay_line.md, coverage_formal.md, gui.png
tests/             unit + simulator test suites (568 tests + 91 subtests), plus
                   the 50-config coverage sweep and formal proofs (see
                   doc/coverage_formal.md)

AI-assisted development

A significant part of this project was written with the assistance of AI coding agents (LLM-assisted pair programming: architecture discussions, RTL, testbenches, scripts and documentation). All AI-generated code is reviewed and verified by a human, and every RTL module is exercised by the bit-exact golden-model test suite (568 tests + 91 subtests), a 50-configuration code-coverage sweep at 100% line coverage, and the formal SAT proofs — see doc/coverage_formal.md. Treat the design as human-verified rather than machine-produced.

Licence

This project is dual-licensed. You may use, study, modify, share and distribute it under either of the following, at your option:

  1. CERN Open Hardware Licence Version 2 — Strongly Reciprocal (CERN-OHL-S-2.0) — the full text is in LICENSE and at https://ohwr.org/cern_ohl_s_v2.txt. Under this strongly reciprocal licence, products built from these designs (or modified versions of them) must remain available as open hardware under CERN-OHL-S-2.0.
  2. A closed-source commercial licence, available on request from Hannes Klas <hannes.klas@gmail.com> — for projects where the reciprocity obligation does not fit.

SPDX expression: CERN-OHL-S-2.0 OR LicenseRef-Commercial.

Versions in the project history prior to the relicensing commit were distributed under CC BY-NC 4.0 and remain governed by that licence.

About

FIR for FPGA applications in Verilog. Optional folding for reduced signal rate

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages