| Contents | Index |
Discrete
The Discrete Filter block independently filters each channel of the input signal with the specified digital IIR direct form II (controllable canonical) filter. The block implements static filters with fixed coefficients. You can tune the coefficients of a static filter.
This block filters each channel of the input signal independently over time. The Input processing parameter allows you to specify whether the block treats each element of the input as an independent channel (sample-based processing), or each column of the input as an independent channel (frame-based processing). To perform frame-based processing, you must have a DSP System Toolbox license.
The output dimensions equal those of the input, except when you specify a matrix of filter taps for the Numerator coefficients parameter. When you do so, the output dimensions depend on the number of different sets of filter taps you specify.
The output of this block numerically matches the output of the Signal Processing Toolbox™ dfilt.df2 object.
Use the Numerator coefficients parameter to specify the coefficients of the discrete filter numerator polynomial. Use the Denominator coefficients parameter to specify the coefficients of the denominator polynomial of the function. The Denominator coefficients parameter must be a vector of coefficients.
Specify the coefficients of the numerator and denominator polynomials in ascending powers of z-1. The Discrete Filter block lets you use polynomials in z-1 (the delay operator) to represent a discrete system, a method that signal processing engineers typically use. Conversely, the Discrete Transfer Fcn block lets you use polynomials in z to represent a discrete system, the method that control engineers typically use. The two methods are identical when the numerator and denominator polynomials have the same length.
Use the Initial states parameter to specify initial filter states. To determine the number of initial states you must specify and how to specify them, see the following tables.
Frame-Based Processing
| Input | Number of Channels | Valid Initial States (Dialog Box) | Valid Initial States (Input Port) |
|---|---|---|---|
| 1 |
|
|
| N |
|
|
Sample-Based Processing
| Input | Number of Channels | Valid Initial States (Dialog Box) | Valid Initial States (Input Port) |
|---|---|---|---|
| 1 |
|
|
| N |
|
|
| K×N |
|
|
When the Initial states is a scalar, the block initializes all filter states to the same scalar value. Enter 0 to initialize all states to zero. When the Initial states is a vector or a matrix, each vector or matrix element specifies a unique initial state for a corresponding delay element in a corresponding channel:
The vector length must equal the number of delay elements in the filter, M = max(number of zeros, number of poles).
The matrix must have the same number of rows as the number of delay elements in the filter, M = max(number of zeros, number of poles). The matrix must also have one column for each channel of the input signal.
The following example shows the relationship between the initial filter output and the initial input and state. Given an initial input u1, the first output y1 is related to the initial state [x1, x2] and initial input by:
![]()

The Discrete Filter block accepts and outputs real and complex signals of any signed numeric data type that Simulink supports. The block supports the same types for the numerator and denominator coefficients.
Numerator and denominator coefficients must have the same complexity. They can have different word lengths and fraction lengths.
The following diagrams show the filter structure and the data types used within the Discrete Filter block for fixed-point signals.

The block omits the dashed divide when you select the Optimize by skipping divide by leading denominator coefficient (a0) parameter.

The Main pane of the Discrete Filter block dialog box appears as follows.

Numerator coefficients of the discrete filter. To specify the coefficients, set the Source to Dialog. Then, enter the coefficients in Value as descending powers of z. Use a row vector to specify the coefficients for a single numerator polynomial. Use a matrix to specify coefficients for multiple filters to be applied to the same input. Each matrix row represents a set of filter taps.
Denominator coefficients of the discrete filter. To specify the coefficients, set the Source to Dialog. Then, enter the coefficients in Value as descending powers of z. Use a row vector to specify the coefficients for a single denominator polynomial. Use a matrix to specify coefficients for multiple filters to be applied to the same input. Each matrix row represents a set of filter taps.
If the Source is Dialog, then, in Value, specify the initial states of the filter states. To learn how to specify initial states, see Specifying Initial States.
If the Source is Input port, then there is nothing to be specified for Value.
Specify the trigger event to use to reset the states to the initial conditions.
| Reset Mode | Behavior |
|---|---|
| None | No reset. |
| Rising | Reset on a rising edge. |
| Falling | Reset on a falling edge. |
| Either | Reset on either a rising or falling edge. |
| Level | Reset in either of these cases:
|
| Level hold | Reset when nonzero at the current time step. |
The reset signal must be scalar.
Specify whether the block performs sample- or frame-based processing.
Elements as channels (sample based) — Process each element of the input as an independent channel.
Columns as channels (frame based) — Process each column of the input as an independent channel.
Note Frame-based processing requires a DSP System Toolbox license. For more information, see Sample- and Frame-Based Concepts in the DSP System Toolbox documentation. |
Select when the leading denominator coefficient, a0, equals one. This parameter optimizes your code.
When you select this check box, the block does not perform a divide-by-a0 either in simulation or in the generated code. An error occurs if a0 is not equal to one.
When you clear this check box, the block is fully tunable during simulation, and performs a divide-by-a0 in both simulation and code generation.
Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See How to Specify the Sample Time.
The Data Types pane of the Discrete Filter block dialog box appears as follows.

Specify the state data type. You can set it to:
A rule that inherits a data type, for example, Inherit: Same as input
A built-in integer, for example, int8
A data type object, for example, a Simulink.NumericType object
An expression that evaluates to a data type, for example, fixdt(1,16,0)
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the State parameter.
See Using the Data Type Assistant for more information.
Specify the numerator coefficient data type. You can set it to:
A rule that inherits a data type, for example, Inherit: Inherit via internal rule
A built-in integer, for example, int8
A data type object, for example, a Simulink.NumericType object
An expression that evaluates to a data type, for example, fixdt(1,16,0)
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Numerator
coefficients parameter.
See Using the Data Type Assistant for more information.
Specify the minimum value that a numerator coefficient can have. The default value is [] (unspecified). Simulink software uses this value to perform:
Parameter range checking (see Checking Parameter Values)
Automatic scaling of fixed-point data types
Specify the maximum value that a numerator coefficient can have. The default value is [] (unspecified). Simulink software uses this value to perform:
Parameter range checking (see Checking Parameter Values)
Automatic scaling of fixed-point data types
Specify the product output data type for the numerator coefficients. You can set it to:
A rule that inherits a data type, for example, Inherit: Inherit via internal rule
A built-in data type, for example, int8
A data type object, for example, a Simulink.NumericType object
An expression that evaluates to a data type, for example, fixdt(1,16,0)
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Numerator
product output parameter.
See Using the Data Type Assistant for more information.
Specify the accumulator data type for the numerator coefficients. You can set it to:
A rule that inherits a data type, for example, Inherit: Inherit via internal rule
A built-in data type, for example, int8
A data type object, for example, a Simulink.NumericType object
An expression that evaluates to a data type, for example, fixdt(1,16,0)
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Numerator
accumulator parameter.
See Using the Data Type Assistant for more information.
Specify the denominator coefficient data type. You can set it to:
A rule that inherits a data type, for example, Inherit: Inherit via internal rule
A built-in integer, for example, int8
A data type object, for example, a Simulink.NumericType object
An expression that evaluates to a data type, for example, fixdt(1,16,0)
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Denominator
coefficients parameter.
See Using the Data Type Assistant for more information.
Specify the minimum value that a denominator coefficient can have. The default value is [] (unspecified). Simulink software uses this value to perform:
Parameter range checking (see Checking Parameter Values)
Automatic scaling of fixed-point data types
Specify the maximum value that a denominator coefficient can have. The default value is [] (unspecified). Simulink software uses this value to perform:
Parameter range checking (see Checking Parameter Values)
Automatic scaling of fixed-point data types
Specify the product output data type for the denominator coefficients. You can set it to:
A rule that inherits a data type, for example, Inherit: Inherit via internal rule
A built-in data type, for example, int8
A data type object, for example, a Simulink.NumericType object
An expression that evaluates to a data type, for example, fixdt(1,16,0)
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Denominator
product output parameter.
See Using the Data Type Assistant for more information.
Specify the accumulator data type for the denominator coefficients. You can set it to:
A rule that inherits a data type, for example, Inherit: Inherit via internal rule
A built-in data type, for example, int8
A data type object, for example, a Simulink.NumericType object
An expression that evaluates to a data type, for example, fixdt(1,16,0)
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Denominator
accumulator parameter.
See Using the Data Type Assistant for more information.
Specify the output data type. You can set it to:
A rule that inherits a data type, for example, Inherit: Inherit via internal rule
A built-in data type, for example, int8
A data type object, for example, a Simulink.NumericType object
An expression that evaluates to a data type, for example, fixdt(1,16,0)
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Output parameter.
See Specifying Block Output Data Types for more information.
Specify the minimum value that the block can output. The default value is [] (unspecified). Simulink software uses this value to perform:
Simulation range checking (see Signal Ranges)
Automatic scaling of fixed-point data types
Specify the maximum value that the block can output. The default value is [] (unspecified). Simulink software uses this value to perform:
Simulation range checking (see Signal Ranges)
Automatic scaling of fixed-point data types
Select to lock all data type settings of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor. For more information, see Fixed-Point Tool and Fixed-Point Advisor in the Simulink Fixed Point documentation.
Specify the rounding mode for fixed-point operations. For more information, see Rounding in the Simulink Fixed Point User's Guide.
| Action | Reasons for Taking This Action | What Happens for Overflows | Example |
|---|---|---|---|
Select this check box. | Your model has possible overflow and you want explicit saturation protection in the generated code. | Overflows saturate to either the minimum or maximum value that the data type can represent. | An overflow associated with a signed 8-bit integer can saturate to -128 or 127. |
Do not select this check box. | You want to optimize efficiency of your generated code. You want to avoid overspecifying how a block handles out-of-range signals. For more information, see Checking for Signal Range Errors. | Overflows wrap to the appropriate value that is representable by the data type. | The number 130 does not fit in a signed 8-bit integer and wraps to -126. |
When you select this check box, saturation applies to every internal operation on the block, not just the output or result. In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.
The State Attributes pane of the Discrete Filter block dialog box appears as follows.

Use this parameter to assign a unique name to the block state. The default is ' '. When this field is blank, no name is assigned. Consider the following when using this parameter:
A valid identifier starts with an alphabetic or underscore character, followed by alphanumeric or underscore characters.
The state name applies only to the selected block.
This parameter enables State name must resolve to Simulink signal object when you click Apply.
For more information, see States in the Simulink Coder documentation.
Select this check box to require that the state name resolve to a Simulink signal object. This check box is cleared by default.
State name enables this parameter.
Selecting this check box disables Code generation storage class.
Select a package that defines the custom storage class you want to apply. If you have defined any packages of your own, click Refresh. This action adds all user-defined packages on your search path to the package list.
From the list, select a state storage class.
Auto is the storage class to use for states that do not need to interface to external code.
The state is stored in a global variable.
model_private.h declares the state as an extern variable.
model_private.h declares the state as an extern pointer.
State name enables this parameter.
Setting this parameter to ExportedGlobal, ImportedExtern, or ImportedExternPointer enables Code generation storage type qualifier.
Specify a Simulink Coder storage type qualifier. The default is ' '. When this field is blank, no qualifier is assigned.
The Simulink Coder product does not check this string for errors; what you enter appears automatically in the variable declaration.
Setting Code generation storage class to ExportedGlobal, ImportedExtern, or ImportedExternPointer enables this parameter.
During simulation, the block uses the following values:
The initial value of the signal object to which the state name resolves
Minimum and maximum values of the signal object
For more information, see States in the Simulink Coder documentation.
Direct Feedthrough | Only when the leading numerator coefficient is not equal to zero |
Sample Time | Specified in the Sample time parameter |
Scalar Expansion | Yes, of initial states |
States | |
Dimensionalized | Yes |
Zero-Crossing Detection | No |

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