Case Study: Evaluating Real-Time FIR Filter Implementation on FPGA


When someone asks, "How do you compute math on an FPGA?", or when explaining digital circuit design concepts to software engineers, verbal explanations alone often fall short.

This article uses a concrete case study to step through the architectural design of a Finite Impulse Response (FIR) digital filter on an FPGA—from formal requirement derivation and block partitioning down to real-time timing budget verification on paper—before writing a single line of RTL code.


1 Introduction

Suppose we are tasked with building a real-time audio FIR filter: capturing live audio from an analog input, streaming it through a digital filter, and immediately feeding filtered output to speakers.

ภาพรวมระบบ FIR filter บน FPGA
Figure 1-1 — High-Level Signal Flow: WM8731 (ADC) → FPGA (FIR) → WM8731 (DAC)

There are two fundamental approaches to this problem:

  1. Software Approach: Ingest audio samples into a PC or MCU, process sequentially in software, and output.
  2. FPGA Hardware Approach: Synthesize dedicated pipelined hardware datapaths to process samples in parallel.
Note: Alternative Processing Platforms

In practice, dedicated DSP microprocessors or custom ASICs are viable options. This article focuses strictly on comparing general-purpose sequential execution vs FPGA hardware architectures.

Under hard real-time constraints, the latency requirement is identical regardless of platform: computation for each audio sample must finish before the next sample arrives. At a standard 44.1 kHz sampling rate, the available time budget per sample is 1 / 44,100 ≈ 22.68 µs. If processing falls behind, buffer overflows and sample dropping occur. On a desktop PC, 22.68 µs is trivial, but on small microcontrollers or multi-tasking systems, latency jitter is hazardous. In our FPGA design, the architectural target specifications are:

รายการ Value
Audio codec Wolfson WM8731 Audio Codec
Filter FIR, 128 Taps
Numeric format IEEE 754 Single-Precision Floating Point (float32)
Sample rate 44.1 kHz
Channels Stereo (Left / Right)

2 Design Requirements

The system implements a stereo digital audio filter where the FPGA interfaces with a Wolfson WM8731 CODEC over I2S/DSP serial audio streams. FIR filtering is computed independently for Left and Right channels using a fixed-point → float32 → FIR → fixed-point pipeline (chosen here to demonstrate hardware floating-point architecture, though fixed-point is commonly utilized in commercial audio DSP).

Category Parameter Specification / Requirement
Digital audio I/O Resolution 24-bit
Channels 2 Channels (Left / Right)
Sample rate 44.1 kHz
Audio Format Stereo
WM8731 clock MCLK 11.2896 MHz (= 256 × Fs)
WM8731 control Control interface I²C
WM8731 audio Digital audio interface DSP / PCM Mode
FIR Structure Direct-Form Convolution
Tap Count 128
Numeric format IEEE 754 single-precision floating point, 32-bit
โครงสร้างตัวกรอง FIR ที่อ้างอิงในตารางข้อกำหนด
Figure 2-1 — Direct-Form FIR Filter Architecture

3 System Architecture & Design

3.1 Architecture Overview

From the specifications above, the system partitions into 3 primary submodules:

บล็อกไดอะแกรมรวมของระบบ
Figure 3.1-1 — Top-Level System Block Diagram
  1. CODEC Interface: Handles I²C register initialization during startup and manages continuous serial audio reception/transmission (I2S/DSP).
  2. Format Conversion (Fixed ⇔ Float): Converts 24-bit integer samples to IEEE 754 float32 before filtering, and converts float32 outputs back to 24-bit fixed-point for the DAC.
  3. FIR Engine: Executes 128-tap convolution with parallel, independent datapaths for Left and Right channels.

3.2 Clock Domains

The FPGA operates on a 50 MHz primary system clock, with an internal PLL synthesizing the required audio master clock (MCLK):

Clock Domain ความถี่ Destination
System clock 50 MHz Conversion modules & FIR Engine
CODEC MCLK 11.2896 MHz WM8731 Master Audio Clock (MCLK)
แผนภาพสัญญาณนาฬิกาของ FPGA
Figure 3.2-1 — Clock Distribution from PLL to Functional Submodules
11.2896 MHz / 256 = 44.1 kHz

The 256 × Fs ratio is a standard master clock configuration supported by the WM8731 for 44.1 kHz sampling.

3.3 Audio CODEC Interface (WM8731)

In this system, the Wolfson WM8731 serves as both ADC and DAC:

  • ADC Section: Digitizes incoming analog signals from LLINEIN/RLINEIN into digital PCM samples.
  • DAC Section: Converts processed digital samples from the FPGA back into analog line output at LOUT/ROUT.

The CODEC exposes two physical interfaces to the FPGA:

  • I²C Control Bus: Programs configuration registers at power-on (audio format, word length, sample rate mode, volume control, and master/slave mode).
  • Digital Audio Serial Bus: Continuously streams serial audio data using BCLK (bit clock), ADCLRC/DACLRC (frame sync / left-right clock), and ADCDAT/DACDAT (serial data lines).
Control Interface ของ WM8731
Figure 3.3-1 — Control Interface (I²C) for WM8731 Configuration
Digital Audio Interface timing ของ WM8731
Figure 3.3-2 — Digital Audio Serial Bus Timing

3.4 Fixed-Point ⇔ Floating-Point Conversion

The WM8731 streams 24-bit signed two's-complement fixed-point data, while our FIR calculation engine utilizes IEEE 754 float32. We must convert incoming 24-bit fixed-point into floating-point before convolution, and convert float32 results back to 24-bit fixed-point before transmitting to the DAC.
The hardware pipeline converts 24-bit fixed-point → Q32.32 (64-bit) → IEEE 754 float32.

แผนภาพการแปลง Fixed เป็น Floating point
Figure 3.4-1 — Fixed-to-Float Pipeline Before FIR Engine
แผนภาพการแปลง Floating point เป็น Fixed
Figure 3.4-2 — Float-to-Fixed Pipeline After FIR Engine

3.5 Pipelined FIR Computation Architecture

An N-tap FIR filter executes convolution according to the difference equation:

y[n] = Σ(k=0..127) a[k] × s[n-k]

where a[k] represents filter tap coefficients and s[n-k] represents the current and historical sample history.

We decompose computation into two decoupled phases: Fully pipeline the multiplications first, then accumulate products in parallel. Because each tap multiplication a[k] × s[n-k] is completely independent, products can be pushed through a single deeply pipelined multiplier at full throughput without pipeline stalls.

If we naively executed multiply-accumulate (MAC) serially in sequence, the accumulator would stall waiting for the recursive feedback sum from the previous tap on every step. Decoupling multiplication and accumulation eliminates feedback stalls.

a0*s0            = result1
result1 + a1*s1  = result2   ← Must wait for result1 (feedback dependency stall)
โครงสร้างการคำนวณ FIR
Figure 3.5-1 — Mathematical Dataflow: Multiplications Followed by Accumulation

In hardware RTL, the core partitions into Delay Line, Multiplier, and Dual Accumulator blocks, utilizing FPGA on-chip Block RAM (BRAM) for sample delay lines, coefficient storage, and intermediate product FIFO buffers.

ทั้ง Left และ Right ใช้โครงสร้างเดียวกัน โดยมีส่วนหลักดังนี้:

  • Delay Line (SAMP_RAM): Circular buffer storing the 128 latest sample vectors s[n] through s[n-127].
  • Coefficient Storage: Dedicated ROM/BRAM holding tap weights a[0] through a[127].
  • Pipelined Multiplier: Single high-frequency floating-point multiplier time-multiplexed across all 128 taps at 1 product per cycle.
  • Dual Accumulator: Splits 128 products into two 64-sample banks summed in parallel to yield final convolution output y[n].

ผลคูณที่ได้จะถูกเก็บแยกเป็น 2 กลุ่ม กลุ่มละ 64 ค่า จากนั้นใช้ accumulator สองสายคำนวณผลรวมของแต่ละกลุ่มแบบขนาน แล้วนำผลรวมทั้งสองมาบวกกันเป็น output สุดท้าย วิธีนี้ช่วยลดจำนวน multiplier และ DSP block เมื่อเทียบกับการสร้าง multiplier ครบ 128 ชุด ขณะเดียวกันก็ยังแบ่งงาน accumulation ให้ทำงานขนานกันได้

บล็อกไดอะแกรมแกนคำนวณ FIR
Figure 3.5-2 — Internal Datapath: SAMP_RAM, Coefficient ROM, Pipelined Multiplier, and Dual Accumulators

3.6 Real-Time Latency & Timing Budget Evaluation

With a 50 MHz system clock, the hard real-time sample arrival period of 1 / 44,100 ≈ 22.68 µs translates into a discrete clock cycle budget of:

50,000,000 / 44,100 ≈ 1,133.8 cycles

Hence, our architectural deadline is strict: processing for each sample must complete in under 1,133 clock cycles. We tabulate the paper latency breakdown below:

Processing Stage Latency โดยประมาณ Notes / Derivation
Multiplier 128 taps 133 cycles 128 cycles continuous stream feed + 5 cycles pipeline flush latency
Adder 576 cycles 64 products × 9 cycles latency utilizing 2 parallel accumulators
Final add + control overhead 20 cycles State machine transitions and handshaking margin
Total Required Latency 729 cycles

Based on our paper analysis, the entire datapath executes in approximately 729 clock cycles, well within our budget of 1,133 cycles per sample (leaving a comfortable 35% timing margin). We mathematically prove the architecture guarantees real-time throughput.

ภาพรวม Timing ของการคำนวณ FIR
Figure 3.6-1 — Temporal Dataflow Overview
Timing แบบละเอียดของการคำนวณ FIR
Figure 3.6-2 — Cycle-Accurate Stage Timing Diagram
Floating-Point IP Latency Characteristics

The 5-cycle multiplier and 9-cycle adder latencies are realistic representative parameters for demonstration. In physical synthesis, exact latency and initiation interval depend on vendor IP configurations (Xilinx Floating-Point Operator), target clock frequency, and FPGA silicon grade.

3.7 Summary of Results

Architectural evaluation confirms that a 128-tap FIR filter at 44.1 kHz is entirely feasible on FPGA at 50 MHz, requiring ~729 cycles out of 1,133 available cycles. Once the mathematical timing proof passes, development safely advances to RTL implementation and post-place-and-route resource audits.

During physical FPGA implementation, verify the following checklist:

  • Exact latency and initiation interval of synthesized floating-point IP cores
  • DSP slice, BRAM, and logic slice utilization budgets
  • Static Timing Analysis (STA) timing closure at target frequency
  • Circular buffer address wrapping and memory read latency alignment
  • Clock Domain Crossing (CDC) synchronization between system clock and CODEC audio clock
  • Rounding, saturation, and overflow clipping logic when converting float back to 24-bit fixed-point

3.8 Technical Design Notes

Why Floating-Point?
Float32 was chosen to allow direct bit-level verification against Python/MATLAB scientific simulation models without quantization scaling artifacts. However, floating-point consumes significantly more DSP slices, logic cells, and pipeline stages than fixed-point. In resource-constrained applications, integer fixed-point DSP remains the industry benchmark.

Further Optimization via Adder Trees:
While dual serial accumulation was selected for control simplicity, throughput can be exponentially accelerated using an Adder Tree (binary parallel reduction tree). By adding product pairs in parallel (O(log2 N) depth instead of O(N)), accumulation latency drops from 576 cycles to under 20 cycles at the expense of additional adder logic.


4 Perspective: When is an FPGA Truly Necessary?

Before selecting an FPGA for mathematical computation, engineers must thoroughly evaluate workload, deadlines, power, and development cost to answer both "Can it be done?" and "Should it be done on FPGA?":

  • Offline / Batch Workloads: Batch file transcoding or non-deadline analytics do not warrant FPGA complexity; modern CPUs and GPUs excel at throughput.
  • Hard Real-Time Determinism: Zero-jitter sample deadlines (radar, audio DSP, motor control, high-frequency trading) represent the ideal FPGA domain because hardware execution timing is cycle-deterministic.
  • Massive Pipelined Parallelism: High-bandwidth multichannel data processing where customized hardware pipelines achieve orders-of-magnitude lower latency than sequential CPU interrupts.
  • Specialized Physical I/O: Tight integration with high-speed ADCs/DACs, custom serial protocols, or multi-gigabit transceivers directly into the processing fabric.
Engineering Takeaway: Hardware vs. Software Mindset

Designing algorithms in hardware requires an entirely different mental model than writing sequential software. One must account for nanosecond clock margins, silicon placement, routing delays, and spatial memory routing. Hardware computation is not just writing equations—it is orchestrating when each gate fires, what physical silicon it consumes, and how data streams across parallel pipelines.