Summary of Digital Signal Processing with MATLAB and Python

Digital Signal Processing with MATLAB and Python Guide

Introduction

Digital filter design is the process of creating discrete-time systems that shape or modify signals in frequency and time. This material covers IIR and FIR design methods, practical implementation in MATLAB/Python, analysis tools (frequency, impulse, step responses), and common workflows used in engineering practice.

Definition: A digital filter is a discrete-time system that maps an input sequence $x[n]$ to an output sequence $y[n]$ via a linear time-invariant relationship realized by difference equations or convolution with an impulse response.

1. Key concepts and building blocks

1.1 Analog prototypes and bilinear transform

  • Many IIR digital filters are created by transforming an analog prototype $F(s)$ into a digital transfer function $G(z)$ using the bilinear transform.
  • The bilinear transform maps the $s$-plane to the $z$-plane by substituting $$s = \frac{2F_s\left(1 - z^{-1}\right)}{1 + z^{-1}}$$
  • Given prototype coefficient vectors $B_s$ and $A_s$, toolboxes provide a function to convert them: in Python SciPy:
    from scipy.signal import bilinear
    B_z, A_z = bilinear(B_s, A_s, Fs)
    

Definition: The bilinear transform is a conformal map that preserves stability and maps the imaginary $s$-axis to the unit circle in the $z$-plane, avoiding aliasing of frequencies but introducing frequency warping.

1.2 Second-order (biquad) sections and quality factor $Q$

  • Second-order low-pass prototype commonly written as $$F(s)=\frac{\omega_c^2}{s^2 + \frac{\omega_c}{Q}s + \omega_c^2}.$$
  • Parameters:
    • $\omega_c$ — cutoff (rad/s)
    • $Q$ — quality factor controlling peak/damping
  • Poles location determines time-domain behavior (overdamped, critically damped, underdamped, unstable).
💡 Věděli jste?Fun fact: Many practical IIR filters are implemented as cascades of second-order sections (biquads) because numerical stability and coefficient quantization are easier to manage than high-order single-polynomial implementations.

1.3 IIR vs FIR trade-offs (comparison)

PropertyIIRFIR
Stability guaranteeNeeds pole check (can be unstable if designed improperly)Always stable if causal finite-length impulse response
PhaseNon-linear typicallyCan be linear (with symmetric coefficients)
Complexity for sharp responseLower order oftenHigher order needed
ImplementationRequires feedback (difference eq.)Pure convolution (no feedback)

1.4 FIR design methods covered

  • Window method (firwin): design by truncating ideal impulse response and applying a window (Hamming, Hann, Blackman, Kaiser, ...)
  • Least-squares method (firls): minimize squared error across bands, define edges and target gains explicitly

1.5 IIR design methods covered

  • Direct design from specifications (iirdesign, iirfilter) using elliptic, Butterworth, Chebyshev types
  • Design parameters: passband edge $f_{p}$, stopband edge $f_{s}$, passband ripple $A_{p}$ (dB), stopband attenuation $A_{s}$ (dB)

Definition: Passband ripple $A_{p}$ is the maximum allowed deviation (in dB) from 0 dB within the passband; stopband attenuation $A_{s}$ is the minimum required attenuation (in dB) in the stopband.

2. Practical tools and functions (MATLAB/Python)

2.1 Frequency response analysis

  • Analog: MATLAB/Python function freqs for prototype analog transfer functions.
    • Example usage in Python:
      from scipy.signal import freqs
      w, K = freqs(B, A, w)
      
  • Digital: freqz computes discrete-time frequency response from numerator/denominator or SOS.
    • Example:
      from scipy.signal import freqz
      W, H = freqz(B, A)
      f = W/(2*pi)*Fs
      

2.2 Time-domain responses

  • Unit impulse response: for FIR it is the filter coefficients; for IIR it can be obtained by filtering an impulse.
  • Unit step response: useful for transient behavior and control applications (e.g., suspension design).
  • Compute using filter (MATLAB) or lfi
Zaregistruj se pro celé shrnutí
FlashcardsKnowledge testSummaryPodcastMindmap
Start for free

Already have an account? Sign in

Digital Filter Design

Klíčové pojmy: Use bilinear transform to convert analog prototype coefficients using $s=\frac{2F_s(1-z^{-1})}{1+z^{-1}}$, Second-order prototype: $F(s)=\frac{\omega_c^2}{s^2+\frac{\omega_c}{Q}s+\omega_c^2}$ and vary $Q$ to change damping, In Python: bilinear(B_s,A_s,Fs) returns digital numerator and denominator, Use freqz for digital and freqs for analog frequency responses, Design IIR with iirdesign(iirfilter) specifying $f_{p}$, $f_{s}$, $A_p$, $A_s$, and fs, FIR via firwin (window) or firls (least-squares) — FIR has linear phase, Implement high-order IIR as cascade of SOS (biquads) to improve numeric stability, Validate designs with magnitude, phase, pole-zero, impulse, and step responses, For offline filtering use lfilter (SciPy) or filter (MATLAB), Pre-warp frequencies when using bilinear transform or use library options that handle warping, Check pole locations to ensure digital filter stability, Pass explicit fs in SciPy functions to avoid normalized-frequency mistakes

## Introduction Digital filter design is the process of creating discrete-time systems that shape or modify signals in frequency and time. This material covers IIR and FIR design methods, practical implementation in MATLAB/Python, analysis tools (frequency, impulse, step responses), and common workflows used in engineering practice. > Definition: A digital filter is a discrete-time system that maps an input sequence $x[n]$ to an output sequence $y[n]$ via a linear time-invariant relationship realized by difference equations or convolution with an impulse response. ## 1. Key concepts and building blocks ### 1.1 Analog prototypes and bilinear transform - Many IIR digital filters are created by transforming an **analog prototype** $F(s)$ into a digital transfer function $G(z)$ using the **bilinear transform**. - The bilinear transform maps the $s$-plane to the $z$-plane by substituting $$s = \frac{2F_s\left(1 - z^{-1}\right)}{1 + z^{-1}}$$ - Given prototype coefficient vectors $B_s$ and $A_s$, toolboxes provide a function to convert them: in Python SciPy: ```python from scipy.signal import bilinear B_z, A_z = bilinear(B_s, A_s, Fs) ``` > Definition: The bilinear transform is a conformal map that preserves stability and maps the imaginary $s$-axis to the unit circle in the $z$-plane, avoiding aliasing of frequencies but introducing frequency warping. ### 1.2 Second-order (biquad) sections and quality factor $Q$ - Second-order low-pass prototype commonly written as $$F(s)=\frac{\omega_c^2}{s^2 + \frac{\omega_c}{Q}s + \omega_c^2}.$$ - Parameters: - $\omega_c$ — cutoff (rad/s) - $Q$ — quality factor controlling peak/damping - Poles location determines time-domain behavior (overdamped, critically damped, underdamped, unstable). Fun fact: Many practical IIR filters are implemented as cascades of second-order sections (biquads) because numerical stability and coefficient quantization are easier to manage than high-order single-polynomial implementations. ### 1.3 IIR vs FIR trade-offs (comparison) | Property | IIR | FIR | |---|---:|---:| | Stability guarantee | Needs pole check (can be unstable if designed improperly) | Always stable if causal finite-length impulse response | | Phase | Non-linear typically | Can be linear (with symmetric coefficients) | | Complexity for sharp response | Lower order often | Higher order needed | | Implementation | Requires feedback (difference eq.) | Pure convolution (no feedback) | ### 1.4 FIR design methods covered - Window method (firwin): design by truncating ideal impulse response and applying a window (Hamming, Hann, Blackman, Kaiser, ...) - Least-squares method (firls): minimize squared error across bands, define edges and target gains explicitly ### 1.5 IIR design methods covered - Direct design from specifications (iirdesign, iirfilter) using elliptic, Butterworth, Chebyshev types - Design parameters: passband edge $f_{p}$, stopband edge $f_{s}$, passband ripple $A_{p}$ (dB), stopband attenuation $A_{s}$ (dB) > Definition: Passband ripple $A_{p}$ is the maximum allowed deviation (in dB) from 0 dB within the passband; stopband attenuation $A_{s}$ is the minimum required attenuation (in dB) in the stopband. ## 2. Practical tools and functions (MATLAB/Python) ### 2.1 Frequency response analysis - Analog: MATLAB/Python function freqs for prototype analog transfer functions. - Example usage in Python: ```python from scipy.signal import freqs w, K = freqs(B, A, w) ``` - Digital: freqz computes discrete-time frequency response from numerator/denominator or SOS. - Example: ```python from scipy.signal import freqz W, H = freqz(B, A) f = W/(2*pi)*Fs ``` ### 2.2 Time-domain responses - Unit impulse response: for FIR it is the filter coefficients; for IIR it can be obtained by filtering an impulse. - Unit step response: useful for transient behavior and control applications (e.g., suspension design). - Compute using filter (MATLAB) or lfi