Digital Filter
DiscreteThe 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 second-order biquad sections ():
Each biquad evaluates the Direct Form II difference equation:
For FIR Moving Average mode, the output is the unweighted arithmetic mean over window length :
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 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 () across all filter design methods.
- Nyquist Frequency Limit: The cutoff frequency must be strictly less than half the simulation sampling frequency (). If
cutoffFreqapproaches 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 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 nonlinearly to discrete frequencies via . At frequencies above , this frequency compression distorts filter cutoffs. Pre-warping the analog critical corner frequency ensures that the discretized digital filter matches the exact analog cutoff specification.
Related Components
- DiscreteTransferFunction: User-specified arbitrary discrete transfer function .
- 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.