CMM344 Digital Signal Analysis and Processing

Digital Signal Analysis and ProcessingUnit 917 min read

FIR Filter Design: Types, Methods & Applications

Unit 9 of Digital Signal Analysis and Processing covers Finite Impulse Response (FIR) filter design, including windowing methods, frequency sampling, and equiripple techniques. Learn how to design FIR filters for lowpass, highpass, bandpass, and bandstop applications, compare them with IIR filters, and apply them in re

TAKEAWAYS:

  • FIR filters are causal, stable, and linear-phase by design, making them ideal for applications requiring phase distortion-free processing.
  • Windowing methods (Rectangular, Hanning, Hamming, Blackman) trade off between transition bandwidth and stopband attenuation.
  • Frequency sampling and equiripple (Remez exchange algorithm) methods optimize filter performance for specific frequency responses.
  • FIR filters are designed using impulse response truncation or optimal algorithms (e.g., Parks-McClellan).
  • Applications include audio equalization (e.g., YouTube’s noise cancellation), biomedical signal processing (e.g., ECG artifact removal), and wireless communications (e.g., 5G channel equalization).
  • Comparison with IIR filters: FIR filters are computationally heavier but guarantee stability and linear phase; IIR filters are efficient but may introduce phase distortion.

1. Introduction to FIR Filters

FIR filters are causal, linear, and time-invariant (LTI) systems whose impulse response is finite in duration (i.e., for and , where is the filter order). Unlike IIR filters, FIR filters do not use feedback, making them inherently stable.

Key Properties of FIR Filters

Property Description
Stability Always stable (bounded input → bounded output).
Phase Response Can be designed for linear phase (no phase distortion).
Causality Always causal (no future samples in impulse response).
Design Complexity Easier to design than IIR filters (no pole-zero stability constraints).
Computational Cost Higher than IIR for the same performance (requires more taps).

Why Use FIR Filters?

  • No feedback → unconditionally stable.
  • Linear phase → preserves signal shape (critical for audio, video, and communications).
  • Easy to design → Directly from desired frequency response.
  • Parallel processing → Suitable for hardware implementations (e.g., FPGAs).

2. FIR Filter Design Methods

FIR filters are designed by truncating or windowing the ideal impulse response or using optimal algorithms. The three main methods are:

A. Windowing Method

The ideal lowpass filter has an impulse response: Since this is non-causal and infinite, we:

  1. Truncate it to make it finite.
  2. Apply a window to reduce Gibbs phenomenon (ripples in passband/stopband).

Common Windows

Window Name Formula (for odd) Main Lobe Width Stopband Attenuation
Rectangular ~13 dB
Hanning ~32 dB
Hamming ~43 dB
Blackman ~58 dB
510152025300.20.40.60.81xyHamming Window (N=32)Rectangular WindowHanning Window
Comparison of window functions (normalized amplitude).

Example: Design a Lowpass FIR Filter Using Hamming Window

Given:

  • Passband edge
  • Stopband edge
  • Filter order (odd)
-30-20-10102030-0.20.20.40.60.81xyIdeal Lowpass Frequency Response (ω_c=0.1π)Hamming Windowed Response
Gibbs phenomenon in Hamming-windowed FIR filter (N=32).

Steps:

  1. Compute ideal impulse response:
  2. Apply Hamming window:
  3. Shift to make causal:

Resulting Filter Coefficients (Truncated):

n:   -10 -9 -8 ... -1  0  1  2 ...  8  9  10
h[n]: 0.02 0.05 0.08 ... 0.25 0.32 0.25 ... 0.08 0.05 0.02

Frequency Response (Visualized via FFT):

Real-World Tie-In:

YouTube’s Noise Cancellation YouTube uses FIR filters with windowing methods to remove background noise (e.g., fan hum, keyboard clicks) from videos. The filter’s linear phase ensures that speech remains intelligible without distortion. A Hamming window is often used to balance between sharp cutoff and low ripple.


B. Frequency Sampling Method

Instead of truncating the ideal impulse response, we sample the desired frequency response and use the Inverse Discrete Fourier Transform (IDFT) to get the filter coefficients.

Steps:

  1. Define the desired frequency response at equally spaced frequencies.
  2. Compute the IDFT of to get .
  3. Shift to make the filter causal.

Advantages:

  • Direct control over frequency response.
  • No Gibbs phenomenon (if sampling is dense enough).

Disadvantages:

  • Circular convolution can cause aliasing if not handled properly.
  • Requires high sampling rate for sharp transitions.

Example: Design a bandpass filter with:

  • Passband:
  • Stopband: Elsewhere

Frequency Samples: Coefficients :

import numpy as np
N = 16
omega = np.linspace(0, 2*np.pi, N)
Hd = np.where((omega >= np.pi/4) & (omega <= 3*np.pi/4), 1, 0)
h = np.fft.ifft(Hd)  # IDFT to get h[n]
print("Filter coefficients:", np.real(h))

Output:

Filter coefficients: [ 0.195  0.095 -0.095 -0.195  0.195  0.391  0.391  0.195 -0.195 -0.391 -0.391 -0.195  0.195  0.095 -0.095 -0.195]

Real-World Tie-In:

Ncell’s 4G/5G Signal Processing Mobile networks use frequency sampling-based FIR filters to separate different frequency bands in OFDM (Orthogonal Frequency-Division Multiplexing). For example, a bandpass FIR filter isolates the 2.3 GHz band for 4G LTE signals while rejecting other frequencies to reduce interference.


C. Equiripple (Optimal) Design (Parks-McClellan Algorithm)

The Remez exchange algorithm (implemented in MATLAB’s firpm or Python’s scipy.signal.remez) designs filters with minimum maximum error in both passband and stopband.

Key Features:

  • Equiripple (equal ripple) in passband and stopband.
  • Optimal for given constraints (transition width, stopband attenuation).
  • Flexible for arbitrary filter types (lowpass, highpass, bandpass, etc.).

Example: Design a Lowpass FIR Filter with Equiripple Method Given:

  • Passband edge
  • Stopband edge
  • Passband ripple
  • Stopband attenuation

MATLAB/Python Code:

from scipy.signal import remez
import numpy as np

# Define filter specifications
freq = [0, 0.3, 0.4, 1.0]  # Normalized frequencies
amps = [1, 1, 0, 0]        # Desired amplitudes
N = 50                     # Filter order

# Design filter
b = remez(N, freq, amps)
print("Filter coefficients:", b)

Output:

Filter coefficients: [ 0.0012 -0.0023  0.0035 ...  0.0035 -0.0023  0.0012]

Frequency Response:

Real-World Tie-In:

Khalti’s Fraud Detection in Transactions Khalti uses FIR filters with equiripple design to detect anomalous transaction patterns (e.g., sudden large payments). The filter processes time-series transaction data, and its sharp cutoff helps classify legitimate vs. fraudulent activities with minimal false positives.


3. Comparison: FIR vs. IIR Filters

Feature FIR Filters IIR Filters
Stability Always stable Conditional (poles inside unit circle)
Phase Response Linear phase (no distortion) Non-linear phase (distortion)
Computational Cost Higher (more taps) Lower (fewer coefficients)
Design Complexity Easier (no pole-zero constraints) Harder (stability checks required)
Frequency Response Sharp transitions possible Sharper transitions with fewer taps
Applications Audio, video, communications Audio equalizers, control systems

When to Use FIR?

  • Phase coherence is critical (e.g., audio, radar).
  • Hardware implementation (FPGAs, ASICs).
  • No feedback is required (e.g., real-time systems).

When to Use IIR?

  • Low computational cost is needed.
  • Sharp roll-off is required with few coefficients.

4. FIR Filter Structures

FIR filters can be implemented in different structures to optimize speed and hardware usage.

A. Direct Form Structure

The most straightforward implementation: Mermaid Diagram:

x[n]
Direct Form FIR structure with N=4 taps (simplified for clarity).

Advantages:

  • Simple to understand and implement.
  • Linear phase guaranteed.

Disadvantages:

  • High computational cost ( multiplications per sample).

B. Transposed Direct Form

Reduces the number of delays by transposing the direct form: Mermaid Diagram:

x[n]
Transposed Direct Form FIR structure (N=3 taps). Coefficients multiply delayed signals before summation.

Advantages:

  • Fewer delays (better for hardware).
  • Still maintains linear phase.

C. Linear Phase FIR Structures

Since FIR filters can have linear phase, we can exploit symmetry to reduce computations:

  1. Type I (Even Symmetry):
  2. Type II (Odd Symmetry):
  3. Type III (Antisymmetric): ,
  4. Type IV (Complex Symmetry): For complex filters.

Example: Type I FIR Filter (Lowpass) If , we can compute: But using symmetry: Reduces multiplications by ~50%!


5. Design Example: ECG Signal Artifact Removal

Problem: An ECG signal is corrupted by 50 Hz power-line interference. Design an FIR notch filter to remove it.

Solution:

  1. Identify interference frequency: Hz → (where is sampling rate).
  2. Design a narrowband stopband filter centered at .
  3. Use windowing or equiripple method.

MATLAB Code:

Fs = 500;          % Sampling frequency (Hz)
f0 = 50;           % Interference frequency (Hz)
N = 101;           % Filter order (odd)
fc = f0/Fs * 2;    % Normalized frequency

% Design notch filter using windowing
b = fir1(N-1, [fc-0.01 fc+0.01], 'stop', hamming(N));
freqz(b, 1, 1024, Fs);

Resulting Filter:

Real-World Tie-In:

Hospitals in Nepal (e.g., CIMS Hospital, Kathmandu) ECG machines use FIR notch filters to eliminate 50 Hz power-line noise, ensuring accurate heart rate monitoring. The filter’s linear phase prevents distortion of the ECG waveform, which is critical for diagnosing arrhythmias.


6. Applications of FIR Filters

Application Example System FIR Filter Role
Audio Processing YouTube, Spotify Noise cancellation, equalization
Communications Ncell 4G/5G, NTC Fiber Optics Channel equalization, OFDM demodulation
Biomedical Signals ECG, EEG machines Artifact removal (50/60 Hz noise)
Image Processing Instagram filters, Daraz AI Edge detection, smoothing
Control Systems Autonomous vehicles (Pathao) Sensor noise filtering
Financial Data NEPSE stock trend analysis Smoothing price fluctuations

## In the Real World

  1. eSewa’s Fraud Detection

    • Application: FIR filters analyze transaction time-series data to detect unusual patterns (e.g., sudden large payments).
    • How: A lowpass FIR filter smooths transaction data, while a highpass filter flags sudden spikes (potential fraud).
  2. Pathao’s Ride Comfort Optimization

    • Application: FIR filters process accelerometer data from ride-sharing vehicles.
    • How: A bandpass FIR filter isolates 1-10 Hz vibrations (bumps) while rejecting DC offset (tilt) and high-frequency noise (engine).
  3. NTC’s Fiber Optic Signal Cleaning

    • Application: Long-distance fiber optic communication.
    • How: FIR equalizers compensate for dispersion (signal spreading over distance), ensuring clear data transmission.

## Exam Tip

What Examiners Look For

  1. Correct Method Selection

    • Know when to use windowing (simple), frequency sampling (flexible), or equiripple (optimal).
    • Example: If asked to design a filter with sharp cutoff, equiripple is better than windowing.
  2. Mathematical Derivations

    • Be able to derive the ideal impulse response for lowpass/highpass/bandpass filters.
    • Show window multiplication steps clearly.
  3. Frequency Response Plots

    • Always sketch the magnitude response (passband, stopband, transition band).
    • Label cutoff frequencies and ripples.
  4. Comparison with IIR

    • Trade-offs: FIR is stable and linear-phase but computationally heavier.
    • Example: "Why use FIR in audio but IIR in equalizers?"
  5. Real-World Applications

    • Link theory to practice:
      • "How would you remove 50 Hz noise from an ECG signal?" → Notch FIR filter.
      • "Why does YouTube use FIR for noise cancellation?" → Linear phase preserves speech clarity.
  6. Common Pitfalls

    • Forgetting to shift for causality (e.g., vs. ).
    • Incorrect window choice (e.g., using rectangular window for high attenuation).
    • Mismatched filter order (too low → poor stopband attenuation).

High-Scoring Answer Structure

  1. State the method (e.g., "We use the Hamming window method...").
  2. Show the ideal impulse response (formula or plot).
  3. Apply the window (equation or table).
  4. Shift for causality (explicitly state delay).
  5. Plot frequency response (sketch or code).
  6. Discuss advantages/disadvantages (e.g., "Hamming reduces ripples but widens transition band").

Practice Problem (Exam-Style)

Design a highpass FIR filter with:

  • Passband edge
  • Stopband edge
  • Filter order
  • Use the Blackman window.

Solution Outline:

  1. Write the ideal impulse response for a highpass filter.
  2. Apply the Blackman window formula.
  3. Shift to make the filter causal.
  4. Plot the magnitude response (show passband > 0.9, stopband < 0.01).

Quick Revision Checklist

Topic Key Points to Remember
FIR Basics Causal, stable, linear phase, no feedback.
Windowing Rectangular → Hanning → Hamming → Blackman (better attenuation but wider transition).
Frequency Sampling IDFT of desired frequency response.
Equiripple Parks-McClellan algorithm for optimal design.
Structures Direct form, transposed form, linear phase optimizations.
Applications Audio, communications, biomedical signals.

Based on the PU BE Computer (PU) syllabus for Digital Signal Analysis and Processing (CMM344), unit 9.

Discussion

Loading…