Project 5: Recursive Filters (IIR) (The Efficient Architect)
Build an IIR filter that uses feedback to achieve strong filtering with fewer coefficients.
Project Overview
| Attribute | Value |
|---|---|
| Difficulty | Level 2: Intermediate |
| Time Estimate | 1-2 weeks |
| Main Language | C |
| Alternative Languages | Python, Rust, C++ |
| Knowledge Area | Feedback systems and stability |
| Tools | Plotting tool, test signals |
| Main Book | “Digital Signal Processing” by Ifeachor & Jervis |
What you’ll build: An IIR filter module that supports a few canonical filter designs (low-pass, high-pass).
Why it teaches DSP: IIR filters reveal the power and danger of feedback. They are efficient but can become unstable.
Core challenges you’ll face:
- Implementing difference equations correctly
- Avoiding instability and runaway output
- Comparing IIR behavior to FIR equivalents
Real World Outcome
You will be able to apply an IIR filter to a signal and observe a strong filtering effect with fewer coefficients than an FIR filter.
Example Output:
$ ./iir_filter --type lowpass --cutoff 1000 --input voice.wav --output voice_iir.wav
Filter order: 2
Wrote filtered output to voice_iir.wav
Verification steps:
- Compare output to FIR filter results
- Test with a step input and observe ringing or overshoot
The Core Question You’re Answering
“How does feedback shape a signal, and why does it make a filter both powerful and risky?”
IIR filters are the first time you feel control and instability in the same design.
Concepts You Must Understand First
Stop and research these before coding:
- Difference equations
- How do past outputs influence the next output?
- Book Reference: “Digital Signal Processing” by Ifeachor & Jervis, Ch. 6
- Poles and zeros
- Why do poles near the unit circle cause ringing?
- Book Reference: “Understanding Digital Signal Processing” by Richard G. Lyons, Ch. 6
- Stability
- What conditions make an IIR filter unstable?
- Book Reference: “The Scientist and Engineer’s Guide to DSP” by Steven W. Smith, Ch. 19
Questions to Guide Your Design
- Coefficient design
- Will you hardcode example coefficients or accept external designs?
- How will you validate stability before processing?
- State handling
- How will you store previous outputs across samples?
- How do you reset state between runs?
Thinking Exercise
Feedback Behavior
Imagine a filter where the new output is 0.8 times the previous output plus the current input.
- If the input becomes zero, how fast does the output decay?
- What happens if the feedback factor is 1.1?
Questions while working:
- Why is 1.0 a critical boundary?
- How does feedback create resonance?
The Interview Questions They’ll Ask
Prepare to answer these:
- “What is the difference between FIR and IIR filters?”
- “Why can IIR filters become unstable?”
- “What do poles and zeros represent?”
- “How do you test a filter for stability?”
- “Why do IIR filters often have lower order than FIR for the same response?”
Hints in Layers
Hint 1: Starting Point Treat the filter as a recurrence that mixes current input with past outputs.
Hint 2: Next Level Store the last few output values in a small state buffer.
Hint 3: Technical Details Keep coefficients organized and apply them in a stable ordering.
Hint 4: Tools/Debugging Run a step input and check for runaway output or oscillation.
Books That Will Help
| Topic | Book | Chapter |
|---|---|---|
| IIR design | “Digital Signal Processing” by Ifeachor & Jervis | Ch. 6 |
| Poles and zeros | “Understanding Digital Signal Processing” by Richard G. Lyons | Ch. 6 |
| Stability | “The Scientist and Engineer’s Guide to DSP” by Steven W. Smith | Ch. 19 |
Implementation Hints
- Start with low-order filters to verify stability.
- Compare impulse responses to ensure the system behaves as expected.
- Provide a way to reset internal state for clean experiments.
Learning Milestones
- First milestone: You can implement a basic IIR low-pass filter.
- Second milestone: You can explain why instability happens.
- Final milestone: You can compare IIR and FIR tradeoffs confidently.