| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Signal Processing Blockset |
| Contents | Index |
| Learn more about Signal Processing Blockset |
| On this page… |
|---|
Overview of the Digital Filter Block Implementing a Highpass Filter Filtering High-Frequency Noise |
You can use the Digital Filter block to implement digital FIR and IIR filters in your models. Use this block if you have already performed the design and analysis and know your desired filter coefficients. You can use this block to filter single-channel and multichannel signals, and to simulate floating-point and fixed-point filters. Then, you can use Real-Time Workshop to generate highly optimized C code from your filter block.
To implement a filter with the Digital Filter block, you must provide the following basic information about the filter:
Whether the filter transfer function is FIR with all zeros, IIR with all poles, or IIR with poles and zeros
The desired filter structure
The filter coefficients
Note Use the Digital Filter Design block to design and implement a filter. Use the Digital Filter block to implement a predesigned filter. Both blocks implement a filter in the same manner and have the same behavior during simulation and code generation. |
You can use the Digital Filter block to implement a digital FIR or IIR filter. In this topic, you use it to implement an FIR lowpass filter:
Define the lowpass filter coefficients in the MATLAB workspace by typing
lopassNum = [-0.0021 -0.0108 -0.0274 -0.0409 -0.0266 0.0374 0.1435 0.2465 0.2896 0.2465 0.1435 0.0374 -0.0266 -0.0409 -0.0274 -0.0108 -0.0021];
From the Signal Processing Blockset Filtering library, and then from the Filter Designs library, click-and-drag a Digital Filter block into your model.
Double-click the Digital Filter block. Set the block parameters as follows, and then click OK:
Transfer function type = FIR (all zeros)
Filter structure = Direct form transposed
Coefficient source = Specify via dialog
Numerator coefficients = lopassNum
Initial conditions = 0
Note that you can provide the filter coefficients in several ways:
Type in a variable name from the MATLAB workspace, such as lopassNum.
Type in filter design commands from Signal Processing Toolbox™ software or Filter Design Toolbox™ software, such as fir1(5, 0.2, 'low').
Type in a vector of the filter coefficient values.
The Digital Filter block in your model now represents a lowpass filter. In the next topic, Implementing a Highpass Filter, you use a Digital Filter block to implement a highpass filter. For more information about the Digital Filter block, see the Digital Filter block reference page. For more information about designing and implementing a new filter, see Digital Filter Design Block.
In this topic, you implement an FIR highpass filter using the Digital Filter block:
If the model you created in Implementing a Lowpass Filter is not open on your desktop, you can open an equivalent model by typing
doc_probe_tut1
at the MATLAB command prompt.
Define the highpass filter coefficients in the MATLAB workspace by typing
hipassNum = [-0.0051 0.0181 -0.0069 -0.0283 -0.0061 ... 0.0549 0.0579 -0.0826 -0.2992 0.5946 -0.2992 -0.0826 ... 0.0579 0.0549 -0.0061 -0.0283 -0.0069 0.0181 -0.0051];
From the Signal Processing Blockset Filtering library, and then from the Filter Designs library, click-and-drag a Digital Filter block into your model.
Double-click the Digital Filter block. Set the block parameters as follows, and then click OK:
Transfer function type = FIR (all zeros)
Filter structure = Direct form transposed
Coefficient source = Specify via dialog
Numerator coefficients = hipassNum
Initial conditions = 0
You can provide the filter coefficients in several ways:
Type in a variable name from the MATLAB workspace, such as hipassNum.
Type in filter design commands from Signal Processing Toolbox software or Filter Design Toolbox software, such as fir1(5, 0.2, 'low').
Type in a vector of the filter coefficient values.
You have now successfully implemented a highpass filter. In the next topic, Filtering High-Frequency Noise, you use these Digital Filter blocks to create a model capable of removing high frequency noise from a signal. For more information about designing and implementing a new filter, see Digital Filter Design Block.
In the previous topics, you used Digital Filter blocks to implement FIR lowpass and highpass filters. In this topic, you use these blocks to build a model that removes high frequency noise from a signal. In this model, you use the highpass filter, which is excited using a uniform random signal, to create high-frequency noise. After you add this noise to a sine wave, you use the lowpass filter to filter out the high-frequency noise:
If the model you created in Implementing a Highpass Filter is not open on your desktop, you can open an equivalent model by typing
doc_filter_ex2
at the MATLAB command prompt.
If you have not already done so, define the lowpass and highpass filter coefficients in the MATLAB workspace by typing
lopassNum = [-0.0021 -0.0108 -0.0274 -0.0409 -0.0266 ... 0.0374 0.1435 0.2465 0.2896 0.2465 0.1435 0.0374 ... -0.0266 -0.0409 -0.0274 -0.0108 -0.0021]; hipassNum = [-0.0051 0.0181 -0.0069 -0.0283 -0.0061 ... 0.0549 0.0579 -0.0826 -0.2992 0.5946 -0.2992 -0.0826 ... 0.0579 0.0549 -0.0061 -0.0283 -0.0069 0.0181 -0.0051];
Click-and-drag the following blocks into your model file.
| Block | Library | Quantity |
|---|---|---|
Add | Simulink / Math Operations library | 1 |
Matrix Concatenate | Math Functions / Matrices and Linear Algebra / Matrix Operations | 1 |
Random Source | Signal Processing Sources | 1 |
Sine Wave | Signal Processing Sources | 1 |
Vector Scope | Signal Processing Sinks | 1 |
Set the parameters for the rest of the blocks as indicated in the following table. For any parameters not listed in the table, leave them at their default settings.
| Block | Parameter Setting |
|---|---|
Add |
|
Matrix Concatenate |
|
Random Source |
|
Sine Wave |
|
Vector Scope | Scope Properties:
|
Connect the blocks and label your signals as shown in the following figure. You need to resize some of your blocks to accomplish this task.

From the Simulation menu, select Configuration Parameters.
The Configuration Parameters dialog box opens.
In the Solver pane, set the parameters as follows, and then click OK:
Start time = 0
Stop time = 5
Type = Fixed-step
Solver = Discrete (no continuous states)
In the model window, from the Simulation menu, choose Start.
The model simulation begins and the Scope displays the three input signals.
Double-click the Vector Scope block and click the Display Properties tab. Select the Channel legend check box and click OK. Next time you run the simulation, a legend appears in the Vector Scope window.
You can also set the color, style, and marker of each channel.
In the Vector Scope window, from the Channels menu, point to Ch 1 and set the Style to -, Marker to None, and Color to Black.
Point to Ch 2 and set the Style to -, Marker to Diamond, and Color to Red.
Point to Ch 3 and set the Style to None, Marker to *, and Color to Blue.

Rerun the simulation and compare the original sine wave, noisy sine wave, and filtered noisy sine wave in the Vector Scope display.
You can see that the lowpass filter filters out the high-frequency noise in the noisy sine wave.

You have now used Digital Filter blocks to build a model that removes high frequency noise from a signal. For more information about designing and implementing a new filter, see Digital Filter Design Block.
You can use the Digital Filter block to specify a static filter by setting the Coefficient source parameter to Specify via dialog. Depending on the filter structure, you need to enter your filter coefficients into one or more of the following parameters. The block disables all the irrelevant parameters. To see which of these parameters correspond to each filter structure, see Supported Filter Structures in Signal Processing Blockset Reference:
Numerator coefficients — Column or row vector of numerator coefficients, [b0, b1, b2, ..., bn].
Denominator coefficients — Column or row vector of denominator coefficients, [a0, a1, a2, ..., am].
Reflection coefficients — Column or row vector of reflection coefficients, [k1, k2, ..., kn].
SOS matrix (Mx6) — M-by-6 SOS matrix. You can also use the Biquad Filter block to create a static biquadratic IIR filter.
Scale values — Scalar or vector of M+1 scale values to be used between SOS stages.
To change the static filter coefficients during simulation, double-click the block, type in the new vector(s) of filter coefficients, and click OK. You cannot change the filter order, so you cannot change the number of elements in the vector(s) of filter coefficients.
Time-varying filters are filters whose coefficients change with time. You can specify a time-varying filter that changes once per frame or once per sample and you can filter multiple channels with each filter. However, you cannot apply different filters to each channel; all channels must be filtered with the same filter.
To specify a time-varying filter:
Set the Coefficient source parameter to Input port(s), which enables extra block input ports for the time-varying filter coefficients.
Set the Coefficient update rate parameter to One filter per frame or One filter per sample depending on how often you want to update the filter coefficients. To learn more, see Setting the Coefficient Update Rate.
Provide vectors of numerator, denominator, or reflection coefficients to the block input ports for filter coefficients. The series of vectors must arrive at their ports at a specific rate, and must be of certain lengths. To learn more, see Providing Filter Coefficient Vectors at Block Input Ports.
Select or clear the First denominator coefficient = 1, remove a0 term in the structure parameter depending on whether your first denominator coefficient is always 1. To learn more, see Removing the a0 Term in the Filter Structure.
When the input is frame based, the block updates time-varying filters once every input frame, or once for every sample in an input frame, depending on the Coefficient update rate parameter:
One filter per frame — Each coefficient vector represents one filter that is applied to all samples in the current frame.
One filter per sample — Each coefficient vector represents a concatenation of filter coefficients. When you have N samples per frame and M coefficients for each filter, then the coefficient vector length is M*N. All the coefficient vectors must be of equal length.
The following figure shows the block filtering one channel; however, the block can filter multiple channels. Note that the block can apply a single filter to multiple channels, but cannot apply a different filter to each channel.

As illustrated in the previous figure, the filter coefficient vectors for filters that update once per frame are different from coefficient vectors for filters that update once per sample. See the following tables to meet the rate and length requirements of the filter coefficient vectors:
Length requirements — See the table Length Requirements for Time-Varying Filter Coefficient Vectors.
Rate requirements — See the table Rate Requirements for Time-Varying Filter Coefficient Vectors.
The output size, frame status, and dimension always match those of the input signal that is filtered, not the vector of filter coefficients.
Length Requirements for Time-Varying Filter Coefficient Vectors
| Coefficient Update Rate | How to Specify
Filter Coefficient Vectors (Also see the previous figure) | Length Requirements |
|---|---|---|
Once per frame | Each coefficient vector corresponds to one input frame and represents one filter. Specify each vector as you would any static filter: [b0, b1, b2, ..., bn], [a0, a1, a2, ..., am], or [k1, k2, ..., kn] | None |
Once per sample | Each coefficient vector corresponds to one input frame. However, the vector represents multiple filters of the same length with one filter for each sample in the current frame. To create such a vector, concatenate all the filters for each sample within the input frame. For instance, the following vector specifies length-2 numerator coefficients for each sample in a three-sample frame
where
| All filters must be the same length, L. The length of each filter coefficient vector must be L times the number of samples per frame in the input. (Each sample in the frame has one set of filter coefficients.) |
The time-varying filter coefficient vectors can be sample- or frame-based row or column vectors. The vectors of filter coefficients must arrive at their input port at the same times that the frames of input data arrive at their input port, as indicated in the following table.
Rate Requirements for Time-Varying Filter Coefficient Vectors
| Input Signal | Time-Varying Filter Coefficient Vectors | Rate Requirements (Also see the previous figure) |
|---|---|---|
Sample based | Sample based | Sample rates of input and filter coefficients must be equal. |
Sample based | Frame based | Input sample rate must equal filter coefficient frame rate. |
Frame based | Sample based | Input frame rate must equal filter coefficient sample rate. |
Frame based | Frame based | Frame rates of input and filter coefficients must be equal. |
When you know that the first denominator filter coefficient (a0) is always 1 for your time-varying filter, select the First denominator coefficient = 1, remove a0 term in the structure parameter. Selecting this parameter reduces the number of computations the block must make to produce the output (the block omits the 1 / a0 term in the filter structure, as illustrated in the following figure). The block output is invalid if you select this parameter when the first denominator filter coefficient is not always 1 for your time-varying filter. Note that the block ignores the First denominator coefficient = 1, remove a0 term in the structure parameter for fixed-point inputs, since this block does not support nonunity a0 coefficients for fixed-point inputs.

The Digital Filter block does not support time-varying biquadratic filters. To specify a static biquadratic filter (also known as a second-order section or SOS filter) using the Digital Filter Block, you need to set the following parameters as indicated:
Transfer function type — IIR (poles & zeros)
Filter structure — Biquad direct form I (SOS), or Biquad direct form I transposed (SOS), or , or Biquad direct form II transposed (SOS)
SOS matrix (Mx6) M-by-6 SOS matrix
The SOS matrix is an M-by-6 matrix, where M is the number of sections in the second-order section filter. Each row of the SOS matrix contains the numerator and denominator coefficients (bik and aik) of the corresponding section in the filter.
Scale values Scalar or vector of M+1 scale values to be used between SOS stages
If you enter a scalar, the value is used as the gain value before the first section of the second-order filter. The rest of the gain values are set to 1.
If you enter a vector of M+1 values, each value is used for a separate section of the filter. For example, the first element is the first gain value, the second element is the second gain value, and so on.

You can use the ss2sos and tf2sos functions from Signal Processing Toolbox software to convert a state-space or transfer function description of your filter into the second-order section description used by this block.

The block normalizes each row by a1i to ensure a value of 1 for the zero-delay denominator coefficients.
Note You can also use the Biquad Filter block to implement a static biquadratic IIR filter. |
![]() | Filters | Digital Filter Design Block | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |