Digital Filter Design
Prince E. Adjei
Kwame Nkrumah University of Science and Technology
Topic: Digital Filters Module 2: Signal Processing
Biosignal Processes And Analysis (BME 366)
© 2025 Prince E. Adjei
Digital Filter Design
Topics:
(1). FIR vs IIR Filtering in ECG Signal Processing
(2). Design and Specification of Digital Filters
(3). Filter Effects: Phase, Delay, and Stability Considerations
(4). Real-Time vs Offline ECG Filtering Approaches
(5). Introduction to ECG Signal Compression
Learning Objectives
Differentiate between FIR and IIR filters and choose appropriate types
for ECG signal cleaning.
Design ECG band-pass and notch filters using common tools and
interpret filter specifications.
Analyze the impact of phase distortion and ensure filter stability in ECG
applications.
Compare real-time and offline filtering implementations, including
hardware constraints.
Explain the principles of ECG signal compression and evaluate quality
across different bit rates.
Review
Filtering is the process of removing unwanted components
(e.g., noise) from a signal. Filters can be applied in both the
time and frequency domains. Some types of filters include:
Low-pass filter
High-pass filter
Band-Pass filter
Notch Filter
Analogue vs Digital Filters
Analogue filters process continuous-time electrical signals before
digitization.
They are built using electronic components like resistors,
capacitors, and op-amps forming circuits that define the filter
response.
Typically placed in the front-end of ECG hardware to remove
baseline drift,high-frequency noise,and prevent aliasing.
They are difficult to modify once implemented, since changes
require replacing physical components.
Filter performance may vary due to component tolerances,
temperature changes, and aging, affecting long-term reliability.
Analogue vs Digital Filters
Digital filters operate on sampled (discrete-time) signals after
analog-to-digital conversion.
They are implemented in software or embedded hardware, like
DSPs or microcontrollers.
Offer high flexibility and precision, allowing for exact control of
filter characteristics.
Easy to modify or tune by changing software parameters.
Their behavior is consistent and reproducible across devices.
Can handle advanced processing, such as adaptive filtering.
Analogue vs Digital Filters
Aspect
Analog Filters
Digital Filters
Signal Type
Continuous
-time
Discrete
-time (sampled)
Implementation
Physical components (e.g., resistors,
op
-amps)
Software or embedded systems
(e.g., MCU)
Flexibility
Hard to modify once built
Easy to update and reconfigure
Accuracy
Affected by component tolerances
Precise and reproducible
FIR Filters
Finite Impulse Response (FIR) filters are digital filters where the
output depends only on a finite number of past input values.
They do not use feedback from past outputs.
Key Properties
Always stable (no feedback loop)
Linear phase possible, which means they preserve the shape of
waveforms (critical for things like QRS in ECG)
Simple implementation using convolution.
Require more taps than IIR for sharp transitions higher
computational cost.
Difference Equation
Only uses past input samples
Coefficients {bo,b1,...,bN} define filter behavior
Implemented using a convolution sum
The response to a single impulse input ends after a finite duration
Hence the name: Finite Impulse Response
FIR Filters
Window Method:
Simple approach using a truncated ideal filter (like sinc) multiplied
by a window function (e.g., Hamming, Blackman).
Easy to implement, but may require a high filter order for sharp
transitions.
ParksMcClellan Algorithm:
An optimal design method (equiripple) that minimizes the worst-
case error between the desired and actual response.
More efficient than windowing for tight filter specs.
FIR Filter Design Methods
IIR Filters
Infinite Impulse Response (IIR) filters are digital filters where the
output depends on both past inputs and past outputs, meaning they
use feedback.
Key Properties
Can achieve sharp filtering with fewer coefficients than FIR
Typically have a non-linear phase, which can distort time-sensitive
signals
Risk of instability if not designed carefully
Efficient for real-time or embedded applications due to lower order
IIR Filters
Difference equation
Uses both input and output history.
Coefficients {ai},{bk} determine the filter’s response.
Recursive: feedback makes it powerful, but more sensitive.
The response to an impulse theoretically continues forever.
Hence the name: Infinite Impulse Response
Filter Concepts Explained
1. Passband
The range of frequencies a filter lets through with minimal attenuation
For example: 545 Hz in an ECG filter this is the desired signal range.
2. Stopband
The frequency range where the filter strongly attenuates the signal.
Example: Below 5 Hz (baseline wander), above 45 Hz (muscle noise)
3. Cut-off frequency
The point where the filter starts to transition between passing and
attenuating
Defined at 3dB (about 70.7% of the original amplitude)
A filter may have two cutoffs in a bandpass case (e.g., 5 Hz and 45 Hz)
Common Type of IIR Filters
Butterworth:
Has a very smooth, flat response in the passband (no ripples).
It’s a good general-purpose filter but requires more order than other
types for sharp transitions.
Chebyshev Type I:
Allows ripples in the passband to achieve a sharper cutoff than
Butterworth.
However, these ripples can distort signal amplitude, especially in
ECG.
Common Type of IIR Filters
Chebyshev Type II:
Ripples are pushed to the stopband, keeping the passband flat.
This makes it better for preserving waveform shape while still
improving sharpness.
Elliptic (Cauer):
Has ripples in both passband and stopband, but gives the sharpest
transition with the lowest filter order.
Best for strict specs, but may distort signal morphology more than
others.
Common Type of IIR Filters
Questions
1) What is the main difference
between analog and digital filters?
2) Why might we choose a linear-
phase filter when working with
ECG signals?
3) What are some types of IIR filters,
and what makes each one unique?
Passband & Stopband Specification ECG Filtering
Passband:
ECG signal content mainly lies between 0.5 Hz and 40 Hz.
This range preserves P waves, QRS complexes, and T waves.
Ideal for general clinical ECG, R-peak detection, and HRV analysis.
Stopband:
Frequencies below 0.5 Hz (baseline wander) should be attenuated.
Frequencies above 40 Hz (e.g., muscle noise, EMG) should also be
removed.
Additional notch at 50 Hz (or 60 Hz) to suppress powerline
interference.
Design Demo: FIR vs IIR in Python
Goal: Design a band-pass filter (0.540 Hz) for ECG using both FIR and
IIR methods, and compare their filter order and performance.
Python Tools Used
scipy.signal.firwin
FIR design using the window method.
Requires specifying the number of taps (order),cutoff
frequencies, and window type.
scipy.signal.iirdesign
IIR design based on specified passband,stopband,ripple, and
attenuation.
Automatically chooses filter type and order
Design Demo: FIR vs IIR in Python
Phase and Group Delay
Phase delay tells you how much a specific frequency component of a
signal is delayed in time by a filter.
Mathematically:
If the filter’s phase response is ϕ(ω), then the phase delay is:
where ωis the frequency in radians/sec.
It describes how much a single frequency is shifted in time as it
passes through the system.
Group delay measures how the phase of a filter changes with
frequency.
It reflects the time delay of the overall signal envelope or a group of
nearby frequencies.
Mathematically:
If group delay is constant across all frequencies, then all
components of the signal are delayed equally, and the waveform
shape is preserved.
If it varies, then some frequencies lag more than others, and the
signal gets distorted.
Phase and Group Delay
Phase & Group Delay Demo: FIR vs IIR on QRS
ECG QRS distortion with 4-pole Butterworth vs 200-tap FIR
Filter stability & overflow
A filter is stable if its output remains bounded for any bounded input.
FIR filters are always stable because they have no feedback (no poles
outside the origin).
For IIR filters, stability depends on the location of poles (they must lie
inside the unit circle in the z-domain).
Overflow occurs when intermediate values in a filter computation exceed
the maximum range that the hardware or data type can represent.
This can lead to clipping of values,wraparound errors (e.g., 32768
becomes -32768), and unstable or distorted output.
To avoid overflows, IIR filters are implemented using cascade (biquad)
structures.
Direct-form vs Cascade (Biquads)
Direct Form implements the full IIR filter in one equation (using the full
numerator and denominator).
Common forms: Direct Form I and II.
Sensitive to numerical errors, especially in high-order filters.
Can become unstable on fixed-point systems due to:
Coefficient rounding
Overflow
Feedback accumulation
Direct-form vs Cascade (Biquads)
Cascade Form (Biquads)
Breaks a high-order filter into a series of second-order sections (SOS).
Each biquad handles a small portion of the response:
Improves:
Numerical stability
Resistance to overflow
Precision in embedded (fixed-point) implementations
IIR Filtering using Cascade (Biquads)
Questions
1) Why do we filter ECG signals
between 0.5 and 40 Hz?
2) What is phase delay, and how can
it affect the shape of ECG signals like
the QRS complex?
3) What does "filter overflow" mean,
and how can using SOS (second-order
sections) improve filter stability?
Real-time vs Offline Filtering
Offline Filtering
The entire signal is available in memory before filtering.
Ideal for: Research and analysis, ECG post-processing, HRV feature
extraction.
Allows use of floating-point, high-order filters with no concern for
real-time constraints.
Real-Time Filtering
Signal is processed sample-by-sample or in small blocks as it arrives.
Must be fast, memory-efficient, and stable.
Used in: Wearables Monitoring systems (e.g., ICU, ambulatory ECG),
Embedded medical devices
Real-Time FIR
FIR filters, especially those with a large number of taps (e.g., 200+),
can be computationally expensive in real-time.
To solve this, FFT-based block processing is used:
The input signal is split into overlapping segments.
Each block is zero-padded, transformed to the frequency domain
using the Fast Fourier Transform (FFT).
The filter is also FFT-transformed, and frequency-domain
multiplication is applied.
The result is transformed back (IFFT) to the time domain and
overlapped with previous blocks.
Real-Time IIR
In embedded devices like smartwatches, ECG patches, or
microcontrollers (MCUs), memory and speed are limited.
These systems use fixed-point arithmetic instead of floating-point.
To implement stable IIR filtering in this context:
Avoid overflow: Use proper scaling of coefficients and intermediate
values.
Preserve precision: Adopt a fixed-point format such as Q15 or Q31,
which allows fractions to be stored in integers.
Use biquad sections: Breaking the filter into Second-Order Sections
(SOS) improves numerical robustness.
Compression Primer
Long-term recordings of signals like ECG, EEG, EMG, and PPG can
generate huge data volumes, especially in high-resolution or multi-
channel setups.
Compression helps by enabling:
Efficient storage (e.g., hospital servers, wearables, implantables)
Low-bandwidth transmission (e.g., wireless body-area networks,
telehealth)
Reduced power usage in mobile/edge devices
Faster access for clinical review, machine learning pipelines, or
patient alerts
Bitrate
Bitrate is the amount of data used per second to represent a signal,
usually measured in kilobits per second (kbps).
Higher bitrate = more detail (diagnostic quality)
Lower bitrate = smaller file, but less detail
Bitrate (bps)=Sampling rate×Bits per sample ×Number of channels
Compression lowers the bitrate by:
Removing redundancy (e.g., repeated patterns in the signal)
Quantizing more aggressively (e.g., reducing precision)
Exploiting signal properties (e.g., using wavelets or predictive models)
“Quality-on-Demand” Idea
Quality on demand involves adapting signal quality based on need:
Application
Required quality
Bitrate Target
Trend tracking (e.g., HR, RR)
Low to moderate
2
8 kbps
Real
-time monitoring (e.g., ICU)
Moderate to high
8
16 kbps
Diagnostic storage/telecardiology
High (diagnostic
-grade)
16
24+ kbps
Effect of Bitrate on ECG Compression Quality (4, 8, 16 kbps)
Summary
FIR filters offer linear phase (good for preserving QRS timing) but need
a high order.
IIR filters are computationally efficient (low order) but may distort
timing due to nonlinear phase.
FIR design methods include the window method and Parks
McClellan for linear-phase filters.
Butterworth (flat), Chebyshev I/II (ripple control), and Elliptic (sharpest
cutoff) are common IIR designs.
IIR filters can be implemented using cascade biquads for stability.