---
# System prepended metadata

title: Why might a filter introduce unexpected delays in a DSP system?
tags: [DSP]

---

Filters in [DSP](https://www.ampheo.com/c/dsp-digital-signal-processors) systems can introduce unexpected delays due to several inherent characteristics of their design and implementation. Here’s a breakdown of the key reasons and how to mitigate them:
![D-Module2-DM642](https://hackmd.io/_uploads/SJQ-v9P8le.jpg)


**1. Group Delay (Phase Response)**
Cause: Filters inherently have a non-linear phase response, especially FIR filters with asymmetric coefficients or IIR filters. This delays different frequency components by varying amounts.

* FIR Filters: Linear-phase FIR filters (symmetric coefficients) have constant group delay ((N−1)/2 samples, where N = tap count).
* IIR Filters: Non-linear phase introduces frequency-dependent delays, distorting transient signals.

Example: A 100-tap FIR filter delays the signal by 49 samples at all frequencies.

Fix:

* Use linear-phase FIR filters for constant delay.
* Compensate delays in post-processing (e.g., MATLAB’s grpdelay to measure and correct).

**2. Filter Latency (Causal Systems)**
Cause: Filters are causal (output depends only on past/present inputs). For real-time systems, this introduces a minimum delay equal to the filter’s impulse response duration.

* FIR Latency: (N−1)/2 samples (for symmetric filters).
* IIR Latency: Depends on pole locations; can be longer for narrowband filters.

Example: A 50-tap low-pass FIR filter adds a 24.5-sample delay.

Fix:

* Truncate the filter (reduce taps) if latency is critical.
* Use look-ahead techniques (non-causal filters) in offline processing.

**3. Buffering & Block Processing**
Cause: Many DSP systems process data in blocks (e.g., FFT-based filtering). Buffering introduces delays equal to the block size.

Example: A 256-sample FFT adds 256 samples of latency.

Fix:

* Use overlap-add/save methods to reduce effective latency.
* Switch to sample-by-sample processing (higher CPU load).

**4. Implementation Overheads**
Cause: Hardware/software pipelines (e.g., [FPGA](https://www.ampheo.com/c/fpgas-field-programmable-gate-array) DSP blocks, CPU SIMD) add cycles for:

* Multiplier-accumulator (MAC) latency.
* Memory read/write delays (e.g., fetching coefficients).

Example: A 10-stage [FPGA](https://www.ampheoelec.de/c/fpgas-field-programmable-gate-array) pipeline adds 10 clock cycles of delay.

Fix:

* Optimize hardware pipelines (balance stages for throughput vs. latency).
* Use parallel processing (e.g., polyphase filters).

**5. Anti-Aliasing/Imaging Filters**
Cause: Decimation/interpolation requires LPFs, which add their own delays.

* Decimation: Anti-aliasing filter delays the signal before downsampling.
* Interpolation: Upsampling’s anti-imaging filter adds delay after zero-padding.

Fix:

* Use CIC filters (low latency but droop in passband).
* Compensate delay in subsequent stages.

**6. Feedback Loops (IIR Filters)**
Cause: IIR filters use feedback, creating recursive delays that grow with:

* Pole proximity to unit circle (narrowband → longer settling time).
* Transient response (e.g., step input "rings" before stabilizing).

Example: A narrow low-pass IIR filter delays a pulse by dozens of samples.

Fix:

* Use FIR instead of IIR if latency is critical.
* Limit IIR bandwidth or use forward-backward filtering (offline only).

**Mitigation Strategies**
1. Measure Group Delay:

```
matlab
[gd, w] = grpdelay(b, a);  % MATLAB
```
2. Minimize Taps: Use least-squares or equiripple design to reduce N.
3. Hardware Acceleration: [FPGAs](https://www.onzuu.com/category/fpgas)/GPUs can reduce pipeline delays.
4. Latency Compensation:

* Delay reference signals to match filtered paths (e.g., in audio crossovers).
* Use fractional delay filters for fine-tuning.

**Example: Audio Processing**
Problem: A 200-tap FIR filter adds 100 samples of delay (2.3 ms at 44.1 kHz), causing lip-sync issues.

Solution:

* Switch to a minimum-phase FIR (reduces latency but non-linear phase).
* Delay the video stream by 2.3 ms to realign.

**Key Takeaways**
* FIR filters → Constant delay (predictable).
* IIR filters → Frequency-dependent delay (harder to compensate).
* Block processing → Adds buffering latency.
* Always check grpdelay and test with impulses/step signals!