⎍

Digital Filter

Discrete
Run the live example Free · no sign-up · runs in your browser

The DigitalFilter block provides high-performance discrete-time filtering of simulation signals using cascaded second-order sections (biquads) or sliding moving-average windows. It supports classical Infinite Impulse Response (IIR) approximations—including Butterworth, Chebyshev Type I, and Bessel—across Lowpass, Highpass, Bandpass, and Notch topologies, as well as Finite Impulse Response (FIR) Moving Average smoothing.

Filter coefficients are automatically synthesized from the chosen corner frequencies, bandwidth, and the simulation sample rate, eliminating the need to manually compute digital filter difference equations.

Mathematical Model

For IIR designs, the system transfer function is synthesized as a series cascade of KK second-order biquad sections (K=order/2K = \text{order} / 2):

H(z)=∏k=1Kb0,k+b1,kz−1+b2,kz−21+a1,kz−1+a2,kz−2H(z) = \prod_{k=1}^{K} \frac{b_{0,k} + b_{1,k} z^{-1} + b_{2,k} z^{-2}}{1 + a_{1,k} z^{-1} + a_{2,k} z^{-2}}

Each biquad evaluates the Direct Form II difference equation:

wk[n]=xk[n]−a1,kwk[n−1]−a2,kwk[n−2]yk[n]=b0,kwk[n]+b1,kwk[n−1]+b2,kwk[n−2]\begin{aligned} w_k[n] &= x_k[n] - a_{1,k} w_k[n-1] - a_{2,k} w_k[n-2] \\ y_k[n] &= b_{0,k} w_k[n] + b_{1,k} w_k[n-1] + b_{2,k} w_k[n-2] \end{aligned}

For FIR Moving Average mode, the output is the unweighted arithmetic mean over window length M=windowSizeM = \text{windowSize}:

y[n]=1M∑i=0M−1u[n−i]y[n] = \frac{1}{M} \sum_{i=0}^{M-1} u[n-i]

Inputs & Outputs

Direction ID Label Type Status
→ In in In number Required
← Out out Out number Output

Parameters

Parameters Label Type Default Description
designMethod Design Method select Butterworth
filterType Filter Type select Lowpass
cutoffFreq Cutoff Freq (Hz) number 10
bandwidth Bandwidth (Hz) number 2
order Filter Order select 2
ripple Ripple (dB) number 1
windowSize Window Size number 10

Usage Examples

Example 1: Butterworth Lowpass Anti-Aliasing Filter

Attenuating 50 Hz power-line interference and high-frequency sensor noise from a 5 Hz command signal sampled at 1 kHz. Configuring designMethod = "Butterworth", filterType = "Lowpass", order = 4, and cutoffFreq = 20.0 Hz provides a maximally flat passband with −80-80 dB/decade attenuation above 20 Hz.

Example 2: Notch Filter for Mechanical Resonance Suppression

Suppressing a sharp 60 Hz structural resonance in an industrial robotic arm. Configuring designMethod = "Butterworth", filterType = "Notch", cutoffFreq = 60.0 Hz, and bandwidth = 5.0 Hz cancels the resonant vibration peak while passing motion trajectory frequencies below 40 Hz and above 80 Hz unattenuated.

Remarks & Best Practices

  • Interactive Frequency & Biquad Insights: The property editor dynamically computes and displays the magnitude and phase Bode plots alongside synthesized biquad cascade coefficients (b0,b1,b2,a1,a2b_0, b_1, b_2, a_1, a_2) across all filter design methods.
  • Nyquist Frequency Limit: The cutoff frequency must be strictly less than half the simulation sampling frequency (fNyquist=12Tsf_{\text{Nyquist}} = \frac{1}{2 T_s}). If cutoffFreq approaches or exceeds Nyquist, the block clamps the value to prevent simulation instability.
  • Biquad Cascading: High-order IIR filters are factored into cascaded second-order sections (SOS) to avoid numerical roundoff sensitivity and preserve pole stability.
  • Phase Linearity: Choose Bessel filters when preserving wave shape, step rise times, and minimizing overshoot is critical; choose Chebyshev when maximizing out-of-band rejection is paramount.
  • Moving Average Group Delay: The moving average filter introduces a constant group delay of exactly M−12\frac{M-1}{2} samples, providing linear phase and zero overshoot.

Frequently Asked Questions (FAQ)

Q: How does bilinear transform frequency warping affect digital IIR filter design?

The bilinear transform maps continuous frequencies Ω∈(−∞,∞)\Omega \in (-\infty, \infty) nonlinearly to discrete frequencies ω∈(−π,π)\omega \in (-\pi, \pi) via Ω=2Tstan⁡(ωTs2)\Omega = \frac{2}{T_s} \tan(\frac{\omega T_s}{2}). At frequencies above 0.1fs0.1 f_s, this frequency compression distorts filter cutoffs. Pre-warping the analog critical corner frequency Ωc=2Tstan⁡(ωcTs2)\Omega_c = \frac{2}{T_s} \tan(\frac{\omega_c T_s}{2}) ensures that the discretized digital filter matches the exact analog cutoff specification.

Related Components

  • DiscreteTransferFunction: User-specified arbitrary discrete transfer function H(z)H(z).
  • FFTScope: Real-time frequency spectrum analyzer to inspect filter attenuation curves.
  • LeadLag: First-order phase lead or lag compensator block.
  • uPlotDisplay: Multi-channel oscilloscope for inspecting filtered vs unfiltered waveforms.