Project 3: FIR Filter Engine (The Convolution Master)
Build a configurable FIR filter engine that applies arbitrary kernels to signals.
Project Overview
| Attribute | Value |
|---|---|
| Difficulty | Level 2: Intermediate |
| Time Estimate | Weekend |
| Main Language | C |
| Alternative Languages | Python, Rust, C++ |
| Knowledge Area | Convolution and impulse response |
| Tools | Plotting tool, test signals from P01 |
| Main Book | “Understanding Digital Signal Processing” by Richard G. Lyons |
What you’ll build: A CLI that reads a signal and a set of filter coefficients, then outputs the filtered signal.
Why it teaches DSP: Convolution is the core operation in DSP. Building it makes the filter behavior visible and testable.
Core challenges you’ll face:
- Implementing convolution efficiently
- Designing and interpreting impulse responses
- Handling boundary conditions and latency
Real World Outcome
You will be able to load a kernel file (for example, a low-pass filter) and apply it to any input signal. The output should show predictable smoothing or edge enhancement, depending on the kernel.
Example Output:
$ ./fir_filter --kernel lowpass.txt --input voice.wav --output voice_filtered.wav
Kernel taps: 64
Input samples: 88200
Wrote filtered output to voice_filtered.wav
Verification steps:
- Compare input and output waveforms
- Measure the spectrum before and after filtering
The Core Question You’re Answering
“Why does sliding a kernel across a signal equal filtering, and how do the coefficients shape the result?”
This is the moment where filters stop being mysterious and become a sum of weighted samples.
Concepts You Must Understand First
Stop and research these before coding:
- Convolution sum
- What does each coefficient contribute to the output sample?
- Book Reference: “Understanding Digital Signal Processing” by Richard G. Lyons, Ch. 5
- Impulse response
- Why does an impulse fully describe an LTI system?
- Book Reference: “The Scientist and Engineer’s Guide to DSP” by Steven W. Smith, Ch. 14
- Filter latency
- Why does an FIR filter delay the signal?
- Book Reference: “Understanding Digital Signal Processing” by Richard G. Lyons, Ch. 6
Questions to Guide Your Design
- Kernel loading
- How will you define and parse tap coefficients?
- How will you normalize kernels to avoid unintended gain?
- Boundary handling
- What happens at the start of the signal when taps reach past the first sample?
- Will you pad with zeros, repeat edges, or shrink output length?
Thinking Exercise
Manual Convolution
Given input sequence: 1, 2, 3, 2, 1 Kernel: 0.25, 0.5, 0.25
Compute the first three output samples by hand.
Questions while working:
- Which input sample has the highest influence?
- How does kernel symmetry affect the phase?
- How does the output compare to a simple moving average?
The Interview Questions They’ll Ask
Prepare to answer these:
- “Why is convolution the core operation for FIR filters?”
- “What does an impulse response tell you about a system?”
- “How does filter length affect frequency response?”
- “Why are FIR filters always stable?”
- “What causes phase delay in FIR filters?”
Hints in Layers
Hint 1: Starting Point Think of the filter output as a weighted sum of recent samples.
Hint 2: Next Level Reverse the kernel when you slide it across the input.
Hint 3: Technical Details Maintain a buffer of the last N samples and compute a dot product each step.
Hint 4: Tools/Debugging Apply a known kernel, like a simple low-pass, and verify the spectrum changes.
Books That Will Help
| Topic | Book | Chapter |
|---|---|---|
| Convolution | “Understanding Digital Signal Processing” by Richard G. Lyons | Ch. 5 |
| Impulse response | “The Scientist and Engineer’s Guide to DSP” by Steven W. Smith | Ch. 14 |
| Filter latency | “Understanding Digital Signal Processing” by Richard G. Lyons | Ch. 6 |
Implementation Hints
- Start with a small, known kernel to validate correctness.
- Normalize taps when appropriate to keep output amplitude stable.
- Provide a way to inspect the filter output numerically, not just as audio.
Learning Milestones
- First milestone: You can apply a kernel and verify the output.
- Second milestone: You can explain how kernel shape affects filtering.
- Final milestone: You can reason about FIR stability and phase delay.