0
0
SimulinkHow-ToBeginner · 4 min read

How to Build a Filter in Simulink: Step-by-Step Guide

To build a filter in Simulink, use the Filter Design block or combine blocks like Discrete Filter or Digital Filter from the DSP System Toolbox. You can design the filter parameters graphically or specify coefficients manually, then connect the filter block to your signal source and sink.
📐

Syntax

In Simulink, filters are built using blocks from the DSP System Toolbox or basic Simulink blocks. The common filter blocks include:

  • Discrete Filter: Implements a digital filter with specified coefficients.
  • Digital Filter Design: Allows graphical design of filters.
  • Filter: A general block for FIR or IIR filters.

You connect these blocks by wiring input signals to the filter input and the filter output to sinks like scopes or workspaces.

text
Discrete Filter block parameters:
- Numerator coefficients (b): [b0 b1 b2 ...]
- Denominator coefficients (a): [a0 a1 a2 ...]

Example usage in Simulink model:
Signal Source --> Discrete Filter --> Scope
💻

Example

This example shows how to build a simple low-pass FIR filter in Simulink using the Discrete Filter block with manually specified coefficients.

text
1. Open Simulink and create a new model.
2. Add a <code>Sine Wave</code> block (Sources library) as input.
3. Add a <code>Discrete Filter</code> block (DSP System Toolbox > Filtering).
4. Double-click the <code>Discrete Filter</code> block and set Numerator coefficients to [0.2 0.2 0.2 0.2 0.2] (simple moving average).
5. Set Denominator coefficients to [1] (FIR filter).
6. Connect the <code>Sine Wave</code> output to the <code>Discrete Filter</code> input.
7. Add a <code>Scope</code> block (Sinks library) and connect the filter output to it.
8. Run the simulation and observe the filtered signal on the scope.
Output
The Scope shows a smoother sine wave output compared to the original, demonstrating the low-pass filtering effect of the moving average filter.
⚠️

Common Pitfalls

Common mistakes when building filters in Simulink include:

  • Using incorrect filter coefficients that cause instability or no filtering effect.
  • Forgetting to set the sample time correctly, which affects filter behavior.
  • Not connecting the blocks properly, leading to no signal flow.
  • Confusing FIR and IIR filter parameters.

Always verify coefficients and sample times before running the simulation.

text
Wrong way:
- Setting denominator coefficients to zero or empty, causing errors.

Right way:
- Denominator coefficients must start with 1 for proper filter definition, e.g., [1 0.5].
📊

Quick Reference

BlockPurposeKey Parameters
Discrete FilterImplements digital FIR/IIR filtersNumerator and Denominator coefficients
Digital Filter DesignGraphical filter design toolFilter type, order, cutoff frequency
Sine WaveSignal source for testingFrequency, amplitude, sample time
ScopeVisualize signalsNo parameters needed

Key Takeaways

Use the Discrete Filter block with correct coefficients to build filters in Simulink.
Set sample time and filter parameters carefully to ensure correct filtering behavior.
Connect signal sources and sinks properly to visualize filter effects.
Use the Digital Filter Design block for graphical filter creation if preferred.
Always test your filter with sample signals like sine waves to verify performance.