Frequency Response
March 25, 2026 · View on GitHub
Overview & Motivation
The frequency response characterizes how a discrete-time linear system (filter) modifies the amplitude and phase of each frequency component in a signal. Computing and plotting the frequency response (Bode plot) is essential for verifying filter designs, understanding system behavior, and tuning parameters. This implementation evaluates the transfer function at logarithmically spaced frequencies, producing magnitude (dB) and phase (degrees) curves.
Mathematical Theory
Transfer Function Evaluation
Given a filter with feedforward coefficients and feedback coefficients , the frequency response at angular frequency is:
For FIR filters, the denominator reduces to .
Magnitude and Phase
From the complex-valued response:
Frequency Grid
Frequencies are evaluated on a logarithmic grid from to (Nyquist), where is the sampling frequency and is the number of evaluation points. The angular frequency at each point is:
Complexity Analysis
| Case | Time | Space | Notes |
|---|---|---|---|
| Average | frequency points, coefficients |
Step-by-Step Walkthrough
Given a simple first-order low-pass FIR filter with , , and Hz, evaluated at Hz:
- Compute
- Numerator: $0.5 \cdot e^{0} + 0.5 \cdot e^{-j0.2\pi} = 0.5 + 0.5(\cos(0.2\pi) - j\sin(0.2\pi))$
- Denominator: $1.0$
- |H| = \sqrt{0.905^{2} + 0.294^2} = 0.952
- Magnitude: $20\log_{10}(0.952) = -0.43$ dB
- Phase:
Pitfalls & Edge Cases
- Zero denominator: If the denominator evaluates to zero at a frequency, the implementation sets it to 1.0 to avoid division by zero. This produces a meaningful (if approximate) result near resonances.
- QNumber conversion: When coefficients are in Q15/Q31 format, they are converted to float via
math::ToFloat()before evaluation. This ensures sufficient dynamic range for the complex arithmetic. - Logarithmic spacing: Very low frequencies near DC may have sparse coverage. The lowest evaluated frequency is .
- Phase wrapping: The
std::argfunction returns phase in . Phase unwrapping is not performed.
Variants & Generalizations
- Linear frequency spacing: Alternative to logarithmic spacing for uniform frequency resolution.
- Zero-pole form: Evaluate directly from pole-zero locations rather than polynomial coefficients.
- Chirp z-transform: Generalization that evaluates the z-transform along arbitrary paths in the z-plane.
Applications
- Verifying filter coefficient designs match the desired specification
- Bode plot generation for stability analysis
- Comparing filter topologies (FIR vs. IIR, different orders)
- System identification validation
Connections to Other Algorithms
- FIR / IIR Filters: The frequency response evaluates the transfer functions implemented by
FirandIirfilters. - FFT: The DFT of a zero-padded impulse response produces the frequency response at uniformly spaced frequencies. This class generalizes to arbitrary frequency points.
- Root Locus: Both frequency response and root locus analyze the same transfer function from complementary perspectives (frequency domain vs. pole-zero domain).
- Power Density Spectrum: PDS estimates the spectral content of a signal; frequency response characterizes the system that shapes it.
References & Further Reading
- Oppenheim, A.V. and Schafer, R.W., Discrete-Time Signal Processing, 3rd ed., Pearson, 2009 — Chapters 5–6.
- Proakis, J.G. and Manolakis, D.G., Digital Signal Processing: Principles, Algorithms, and Applications, 4th ed., Pearson, 2006 — Chapter 6.
- Smith, S.W., The Scientist and Engineer's Guide to Digital Signal Processing, California Technical Publishing, 1997 — Chapter 21.