DigitalFilter Block
2nd-Order Digital Butterworth Filter
Open DigitalFilter in BlockWerk →# Digital Filter Block
Description
The DigitalFilter block is a highly advanced signal processing tool designed to filter discrete-time signals during a simulation. It supports various traditional Infinite Impulse Response (IIR) filter approximations (Butterworth, Chebyshev I, Bessel) in cascading biquad structures, as well as Finite Impulse Response (FIR) Moving Average filters.
It calculates coefficients dynamically based on the current sample frequency (derived from the solver's fixed step size) to ensure mathematically accurate filtering in real-time.
Filter Types (IIR only)
- Lowpass: Passes signals with a frequency lower than the cutoff frequency and attenuates signals with frequencies higher than the cutoff frequency.
- Highpass: Passes signals with a frequency higher than the cutoff frequency.
- Bandpass: Passes frequencies within a certain range (defined by cutoff and bandwidth) and rejects frequencies outside that range.
- Notch: Rejects a specific narrow band of frequencies.
Design Methods
Butterworth
Provides a maximally flat magnitude response in the passband. It sacrifices roll-off steepness for a flat passband. Ideal for general-purpose anti-aliasing.
Chebyshev I
Allows for a steeper roll-off (transition band) at the expense of ripples in the passband.
- Ripple (dB): Defines the peak-to-peak variation of the magnitude within the passband. A higher ripple allows for an even steeper cut-off.
Bessel
Optimized to have a maximally flat group delay (linear phase response). This preserves the wave shape of filtered signals in the time domain, meaning it avoids overshoot and ringing when filtering step-like changes. The trade-off is a very slow transition/roll-off compared to Butterworth and Chebyshev.
Moving Average (FIR)
A robust and unconditionally stable filter that computes the unweighted mean of the previous $N$ samples.
- Window Size: The number of samples to average ($N$). Ideal for smoothing out high-frequency Gaussian noise from raw sensor readings.
Parameters
- Design Method: Determines the mathematical approximation used (Butterworth, Chebyshev I, Bessel, Moving Average).
- Filter Type: (IIR only) Lowpass, Highpass, Bandpass, Notch.
- Filter Order: (IIR only) Determines the steepness of the filter roll-off. Higher orders (4, 6, 8) cascade multiple 2nd-order (Biquad) sections. Each 2nd order adds -12dB/octave to the slope.
- Cutoff Freq (Hz): The frequency at which the filter begins to attenuate the signal (usually the -3dB point). _Must be strictly less than half the sample rate (Nyquist limit)._
- Bandwidth (Hz): (Bandpass & Notch only) The width of the passed or rejected frequency band.
- Ripple (dB): (Chebyshev only) The allowed ripple in the passband.
- Window Size: (Moving Average only) The amount of previous samples to average over.
Mathematical Model
For IIR filters, the block cascades $N/2$ Biquadratic (Biquad) sections in the form: $y[n] = b_0 x[n] + b_1 x[n-1] + b_2 x[n-2] - a_1 y[n-1] - a_2 y[n-2]$ The $Q$-factors and pole locations are calculated dynamically based on the chosen design method and filter order.
For the Moving Average filter, the block implements a circular buffer: $y[n] = \frac{1}{N} \sum_{k=0}^{N-1} x[n-k]$
Warning: Nyquist Limit
To prevent instability and aliasing, the Cutoff Frequency must be lower than the Nyquist limit, which is exactly half of the solver's sample frequency. $F_{nyquist} = \frac{1}{2 \cdot \text{step\_size}}$ If the cutoff frequency exceeds this limit, the block will internally clamp it to avoid simulation crashes. It is strongly advised to decrease the simulation step size (increase sample frequency) if you need to filter very high frequencies.