DGT302 – LAB 02: Digital Filter Design & Quantization Effects
(Target: Slot 29 & 30 - Aligns with Syllabus Chapters 5 to 6)
1. Objectives
Design linear-phase FIR filters (Lowpass and Highpass) using the Windowing
method.
Analyze frequency responses (Magnitude & Phase) to verify system
performance.
Simulate the Analog-to-Digital Conversion (ADC) process, focusing on
quantization noise.
Verify the "6 dB per bit" rule for Signal-to-Quantization-Noise Ratio (SQNR).
2. Practical Tasks
Task 2.1: FIR Highpass Filter Design (ECG Baseline Wander Removal)
In clinical environments, ECG signals are often corrupted by low-frequency noise (1–
2 Hz) caused by a patient's breathing or physical movement, known as "Baseline
Wander."
Requirements:
1. Generate a Synthetic Signal: Create a 50 Hz useful sine wave corrupted by a
2 Hz low-frequency interference: x (t )=sin (2 π ⋅50⋅ t ) +0.5 ⋅sin ( 2 π ⋅ 2⋅t ) . Assume
F s=500 Hz.
2. Filter Specification: Design an FIR Highpass filter using a Hamming
window with a cutoff frequency f c =10 Hz and filter order M =101.
3. Frequency Analysis: Use [Link] to plot the Magnitude (in dB) and
Phase (in Radians) responses.
4. Critical Inference: Verify the Linear Phase property from the phase plot.
Explain why preserving phase linearity is crucial for biomedical signals like
ECG or image data.
Task 2.2: Quantization Simulator & SQNR Verification
This task simulates the internal logic of an ADC chip (e.g., 12-bit or 16-bit).
Requirements:
1. Implement a function uniform_mid_tread_quantizer(x, bits, V_max) to map
continuous-amplitude values to 2b discrete levels.
2. Quantize a standard sine wave using various bit depths: b=3 , 4 , 8 , 16.
3. Calculate the Quantization Error e [ n ] =x [ n ]−x q [ n ].
4. Compute the actual SQNR using the formula:
SQN Ractual =10 log 10
( )
Psignal
P noise
5. Critical Inference: Plot the actual SQNR vs. theoretical SQNR ( 6.02 b+1.76 ).
Discuss why the actual results might deviate when the bit depth is very low
(e.g., 3-bit).
3. Optional Extension (Bonus Points)
Task 2.3: The Art of Dithering in Audio
Problem: Low-bit quantization (e.g., 4-bit) creates "Harmonic Distortion"
because the error is correlated with the signal.
Practical Task:
1. Quantize a short audio clip to 4-bit and observe the harsh, metallic
distortion.
2. Apply Dithering: Add a small amount of White Gaussian Noise to the
signal before quantization.
3. Deliverable: Listen to both outputs. Plot the spectrum of the error
signal. Explain how adding noise can paradoxically make an audio signal
sound "cleaner" to the human ear.
4. Implementation Scaffolding
import numpy as np
import [Link] as plt
from scipy import signal
# --- Task 2.1 Scaffolding ---
def design_fir_highpass(fc, fs, M):
nyq = 0.5 * fs
low_cutoff = fc / nyq
# Design using firwin
taps = [Link](M, low_cutoff, pass_zero=False,
window='hamming')
return taps
# --- Task 2.2 Scaffolding ---
def uniform_quantizer(x, bits, V_max):
L = 2**bits
delta = (2 * V_max) / L
# Mid-tread rounding logic
x_q = [Link](x / delta) * delta
# Handle clipping (saturation)
x_q = [Link](x_q, -V_max, V_max - delta)
return x_q
# Students: Proceed with simulation and SQNR plotting...
5. Evaluation Rubric & Submission Requirements
Submission Requirements:
Format: A single, fully executable Jupyter Notebook file (.ipynb).
Plotting Standards: Strictly use [Link]() for continuous-time analog
signals and [Link]() for discrete-time sequences. Every plot must
contain a title, xlabel, ylabel, and a legend.
Deadline: Upload to the course portal in EduNext before the start of the next
scheduled lab session.
Evaluation Rubric (100 pts):
Mathematical Rigor (20%): Proper calculation of filter taps and
understanding of the Additive Noise Model for quantization.
Implementation (20%): Correct Python logic. The quantizer must handle
clipping and rounding without logical errors.
Visualization (15%): Accurate Bode plots (Magnitude/Phase) and SQNR
comparison graphs with proper units (dB).
Critical Inference (15%): Ability to explain why Linear Phase FIR is used
and the physical nature of quantization noise.
Viva / Oral Defense (20%): Defend the choice of filter order M and explain
the impact of transition bandwidth.
Extension (Bonus) (10%): Successful Dithering implementation and
auditory/spectral analysis of the results..