Main Content

Discrete Filter

Model Infinite Impulse Response (IIR) filters

  • Discrete Filter block

Libraries:
Simulink / Discrete

Description

The Discrete Filter block independently filters each channel of the input signal with the specified digital IIR filter. You can specify the filter structure as Direct form I, Direct form I transposed, Direct form II, or Direct form II transposed. The block implements static filters with fixed coefficients. You can tune the coefficients of these static filters.

This block filters each channel of the input signal independently over time. The Input processing parameter allows you to specify how the block treats each element of the input. You can specify treating input elements as an independent channel (sample-based processing), or treating 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 the input dimensions, 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.

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. Signal processing engineers typically use this method. Conversely, the Discrete Transfer Fcn block lets you use polynomials in z to represent a discrete system. Control engineers typically use this method. When the numerator and denominator polynomials have the same length, the two methods are identical.

Specifying Initial States

In Dialog parameters and Input port(s) modes, the block initializes the internal filter states to zero by default, which is equivalent to assuming past inputs and outputs are zero. You can optionally use the Initial states parameter to specify nonzero initial states for the filter delays.

To determine the number of initial state values you must specify, and how to specify them, see the following table on valid initial states and Number of Delay Elements (Filter States). The Initial states parameter can take one of four forms as described in the following table.

Valid Initial States

Initial stateExamplesDescription

Scalar

5

Each delay element for each channel is set to 5.

The block initializes all delay elements in the filter to the scalar value.

Vector
(for applying the same delay elements to each channel)

For a filter with two delay elements: [d1d2]

The delay elements for all channels are d1 and d2.

Each vector element specifies a unique initial condition for a corresponding delay element. The block applies the same vector of initial conditions to each channel of the input signal. The vector length must equal the number of delay elements in the filter (specified in the table Number of Delay Elements (Filter States)).

Vector or matrix
(for applying different delay elements to each channel)

For a three-channel input signal and a filter with two delay elements:

[d1d2D1D2d1d2] or

[d1D1d1d2D2d2]

  • The delay elements for channel 1 are d1 and d2.

  • The delay elements for channel 2 are D1 and D2.

  • The delay elements for channel 3 are d1and d2.

Each vector or matrix element specifies a unique initial condition for a corresponding delay element in a corresponding channel:

  • The vector length must be equal to the product of the number of input channels and the number of delay elements in the filter (specified in the table Number of Delay Elements (Filter States)).

  • The matrix must have the same number of rows as the number of delay elements in the filter (specified in the table Number of Delay Elements (Filter States)), and must have one column for each channel of the input signal.

Empty matrix

[ ]
Each delay element for each channel is set to 0.

The empty matrix, [], is equivalent to setting the Initial conditions parameter to the scalar value 0.

The number of delay elements (filter states) per input channel depends on the filter structure, as indicated in the following table.

Number of Delay Elements (Filter States)

Filter StructureNumber of Delay Elements Per Channel

Direct form I
Direct form I transposed

  • number of zeros - 1

  • number of poles - 1

Direct form II
Direct form II transposed

max(number of zeros, number of poles)-1

The following tables describe the valid initial states for different sizes of input and different number of channels depending on whether you set the Input processing parameter to frame based or sample based.

Frame-Based Processing

Input Number of ChannelsValid Initial States (Dialog Box)Valid Initial States (Input Port)
  • Column vector (K-by-1)

  • Unoriented vector (K)

1
  • Scalar

  • Column vector (M-by-1)

  • Row vector (1-by-M)

  • Scalar

  • Column vector (M-by-1)

  • Row vector (1-by-N)

  • Matrix (K-by-N)

N
  • Scalar

  • Column vector (M-by-1)

  • Row vector (1-by-M)

  • Matrix (M-by-N)

  • Scalar

  • Matrix (M-by-N)

Sample-Based Processing

InputNumber of ChannelsValid Initial States (Dialog Box)Valid Initial States (Input Port)
  • Scalar

1
  • Scalar

  • Column vector (M-by-1)

  • Row vector (1-by-M)

  • Scalar

  • Column vector (M-by-1)

  • Row vector (1-by-M)

  • Row vector (1-by-N)

  • Column vector (N-by–1)

  • Unoriented vector (N)

N
  • Scalar

  • Column vector (M-by-1)

  • Row vector (1-by-M)

  • Matrix (M-by-N)

  • Scalar

  • Matrix (K-by-N)

K × N
  • Scalar

  • Column vector (M-by-1)

  • Row vector (1-by-M)

  • Matrix (M-by-(K×N))

  • Scalar

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. This unique state corresponds to a 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 relationship between the initial filter output y1, the initial input u1, and the initial state [x1, x2] is given by the following equation.

y1=b1[(u1a2x1a3x2)a1]+b2x1+b3x2

where,

  • b1, b2, and b3 are the numerator coefficients of the discrete filter.

  • a1, a2, and a3 are the denominator coefficients of the discrete filter.

For an example that shows this relationship, see Specify a Vector of Initial Conditions for a Discrete Filter Block.

Ports

Input

expand all

Input signal to filter, specified as a scalar, vector, or matrix.

Dependencies

The name of this port depends on the source you specify for the numerator coefficients, denominator coefficients and initial states. When you set Numerator, Denominator, and Initial states to Dialog, there is only one input port, and the port is unlabeled. When you set Numerator, Denominator, or Initial states to Input port, this port is labeled u.

Data Types: single | double | int8 | int16 | int32 | fixed point

Numerator coefficients of the discrete filter, specified as descending powers of z. Use a row vector to specify the coefficients for a single numerator polynomial.

Dependencies

To enable this port, set Numerator to Input port.

Data Types: single | double | int8 | int16 | int32 | fixed point

Specify the denominator coefficients of the discrete filter as descending powers of z. Use a row vector to specify the coefficients for a single denominator polynomial.

Dependencies

To enable this port, set Denominator to Input port.

Data Types: single | double | int8 | int16 | int32 | fixed point

Initial states, specified as a scalar, vector, or matrix. For more information about specifying states, see Specifying Initial States.

Dependencies

To enable this port, set the Filter structure to Direct form II or Direct form II transposed, and set Initial states to Input port.

Data Types: single | double | int8 | int16 | int32 | fixed point

Output

expand all

Filtered output signal. The output dimensions equal the input dimensions, 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.

When you set Sample time to -1, sample time of the output signal is same as the sample time of the input signal u.

Data Types: single | double | int8 | int16 | int32 | fixed point

Parameters

expand all

Main

Specify the discrete IIR filter structure.

Dependencies

To use any filter structure other than Direct form II, you must have an available DSP System Toolbox license.

Programmatic Use

Block Parameter: FilterStructure
Type: character vector
Values: 'Direct form II' | 'Direct form I transposed' | 'Direct form I' | 'Direct form II transposed'
Default: 'Direct form II'

Specify the source of the numerator coefficients as Dialog or Input port.

Programmatic Use

Block Parameter: NumeratorSource
Type: character vector
Values: 'Dialog' | 'Input port'
Default: 'Dialog'

Specify the numerator coefficients of the discrete filter as descending powers of z. Use a row vector to specify the coefficients for a single numerator polynomial. To specify coefficients for multiple filters, specify a matrix of coefficients, where each row represents a different set of filter taps.

Dependencies

To enable this parameter, set the Numerator Source to Dialog.

To implement multiple filters, Filter structure must be Direct form II, Input processing must be Elements as channels (sample based), and the input must be a scalar.

Programmatic Use

Block Parameter: Numerator
Type: character vector
Values: scalar | vector | matrix
Default: '[1]'

Specify the source of the denominator coefficients as Dialog or Input port.

Programmatic Use

Block Parameter: DenominatorSource
Type: character vector
Values: 'Dialog' | 'Input port'
Default: 'Dialog'

Specify the denominator coefficients of the discrete filter as descending powers of z. Use a row vector to specify the coefficients for a single denominator polynomial.

Dependencies

To enable this parameter, set the Denominator Source to Dialog.

Programmatic Use

Block Parameter: Denominator
Type: character vector
Values: scalar | vector
Default: '[1 0.5]'

Specify the source of the initial states as Dialog or Input port.

Programmatic Use

Block Parameter: InitialStatesSource
Type: character vector
Values: 'Dialog' | 'Input port'
Default: 'Dialog'

Specify the initial filter states as a scalar, vector, or matrix. To learn how to specify initial states, see Specifying Initial States.

Dependencies

To enable this parameter, set the Filter structure to Direct form II or Direct form II transposed, and set Initial states Source to Dialog.

Programmatic Use

Block Parameter: InitialStates
Type: character vector
Values: scalar | vector | matrix
Default: '0'

Specify the initial numerator filter states as a scalar, vector, or matrix. To learn how to specify initial states, see Specifying Initial States.

Dependencies

To enable this port, set the Filter structure to Direct form I or Direct form I transposed.

Programmatic Use

Block Parameter: InitialStates
Type: character vector
Values: scalar | vector | matrix
Default: '0'

Specify the initial denominator filter states as a scalar, vector, or matrix. To learn how to specify initial states, see Specifying Initial States.

Dependencies

To enable this port, set the Filter structure to Direct form I or Direct form I transposed.

Programmatic Use

Block Parameter: InitialDenominatorStates
Type: character vector
Values: scalar | vector | matrix
Default: '0'

Specify the trigger event to use to reset the states to the initial conditions.

Reset ModeBehavior
NoneNo reset
RisingReset on a rising edge
FallingReset on a falling edge
EitherReset on either a rising or falling edge
Level

Reset in either of these cases:

  • When the reset signal is nonzero at the current time step

  • When the reset signal value changes from nonzero at the previous time step to zero at the current time step

Level holdReset when the reset signal is nonzero at the current time step

Programmatic Use

Block Parameter: ExternalReset
Type: character vector
Values: 'None' | 'Rising' | 'Falling' | 'Either' | 'Level' | 'Level hold'
Default: 'None'

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.

Dependencies

Frame-based processing requires a DSP System Toolbox license.

For more information, see Sample- and Frame-Based Concepts (DSP System Toolbox).

Programmatic Use

Block Parameter: InputProcessing
Type: character vector
Values: 'Columns as channels (frame based)' | 'Elements as channels (sample based)'
Default: 'Elements as channels (sample based)'

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. It performs a divide-by-a0 in both simulation and code generation.

Programmatic Use

Block Parameter: a0EqualsOne
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. For more information, see Specify Sample Time.

Dependencies

This parameter is visible only if you set it to a value other than -1. To learn more, see Blocks for Which Sample Time Is Not Recommended.

Programmatic Use

Block Parameter: SampleTime
Type: string scalar or character vector
Default: "-1"

Data Types

Specify the state data type. You can set this parameter 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)

The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click the Show data type assistant button. For more information, see Specify Data Types Using Data Type Assistant.

Programmatic Use

Block Parameter: StateDataTypeStr
Type: character vector
Values: 'Inherit: Same as input' | 'int8' | 'int16' | 'int32' | 'int64' | 'fixdt(1,16,0)' | '<data type expression>'
Default: 'Inherit: Same as input'

Specify the numerator coefficient data type. You can set this parameter to:

  • A rule that inherits a data type, for example, Inherit: Inherit via internal rule

  • A built-in signed 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)

The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click the Show data type assistant button. For more information, see Specify Data Types Using Data Type Assistant.

Programmatic Use

Block Parameter: NumCoeffDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule' | 'int8' | 'int16' | 'int32' | 'int64' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

Specify the minimum value that a numerator coefficient can have. The default value is [] (unspecified). Simulink® software uses this value to perform:

Programmatic Use

Block Parameter: NumCoeffMin
Type: character vector
Values: scalar
Default: '[]'

Specify the maximum value that a numerator coefficient can have. The default value is [] (unspecified). Simulink software uses this value to perform:

Programmatic Use

Block Parameter: NumCoeffMax
Type: character vector
Values: scalar
Default: '[]'

Specify the product output data type for the numerator coefficients. You can set this parameter 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)

The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click the Show data type assistant button. For more information, see Specify Data Types Using Data Type Assistant.

Programmatic Use

Block Parameter: NumProductDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule' | 'Inherit: Same as input' | 'int8' | 'int16' | 'int32' | 'int64' | 'fixdt(1,16,0)' | '<data type expression>'
Default: 'Inherit: Inherit via interal rule'

Specify the accumulator data type for the numerator coefficients. You can set this parameter 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)

The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click the Show data type assistant button. For more information, see Specify Data Types Using Data Type Assistant.

Programmatic Use

Block Parameter: NumAccumDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule' | 'Inherit: Same as input' | 'Inherit: Same as product output' | 'int8' | 'int16' | 'int32' | 'int64' | 'fixdt(1,16,0)' | '<data type expression>'
Default: 'Inherit: Inherit via interal rule'

Specify the denominator coefficient data type. You can set this parameter 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)

The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click the Show data type assistant button. For more information, see Specify Data Types Using Data Type Assistant.

Programmatic Use

Block Parameter: DenCoeffDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule' | 'int8' | 'int16' | 'int32' | 'int64' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

Specify the minimum value that a denominator coefficient can have. The default value is [] (unspecified). Simulink software uses this value to perform:

Programmatic Use

Block Parameter: DenCoeffMin
Type: character vector
Values: scalar
Default: '[]'

Specify the maximum value that a denominator coefficient can have. The default value is [] (unspecified). Simulink software uses this value to perform:

Programmatic Use

Block Parameter: DenCoeffMax
Type: character vector
Values: scalar
Default: '[]'

Specify the product output data type for the denominator coefficients. You can set this parameter 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)

The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click the Show data type assistant button. For more information, see Specify Data Types Using Data Type Assistant.

Programmatic Use

Block Parameter: DenProductDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule' | 'Inherit: Same as input' | 'int8' | 'int16' | 'int32' | 'int64' | 'fixdt(1,16,0)' | '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

Specify the accumulator data type for the denominator coefficients. You can set this parameter 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)

The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click the Show data type assistant button. For more information, see Specify Data Types Using Data Type Assistant.

Programmatic Use

Block Parameter: DenAccumDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule' | 'Inherit: Same as input' | 'Inherit: Same as product output' | 'int8' | 'int16' | 'int32' | 'int64' | 'fixdt(1,16,0)' | '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

Specify the output data type. You can set this parameter 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)

The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click the Show data type assistant button. For more information, see Specify Data Types Using Data Type Assistant.

Programmatic Use

Block Parameter: OutDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule' | 'int8' | 'int16' | 'int32' | 'int64' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

Specify the minimum value that the block can output. The default value is [] (unspecified). Simulink software uses this value to perform:

Programmatic Use

Block Parameter: OutMin
Type: character vector
Values: scalar
Default: '[]'

Specify the maximum value that the block can output. The default value is [] (unspecified). Simulink software uses this value to perform:

Programmatic Use

Block Parameter: OutMax
Type: character vector
Values: scalar
Default: '[]'

Specify the multiplicand data type. You can set this parameter to:

  • A rule that inherits a data type, for example, Inherit: Same as input

  • 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)

The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click the Show data type assistant button. For more information, see Specify Data Types Using Data Type Assistant.

Dependencies

To enable this parameter, set the Filter structure to Direct form I transposed

Programmatic Use

Block Parameter: MultiplicandDataTypeStr
Type: character vector
Values: 'Inherit: Same as input' | 'int8' | 'int16' | 'int32' | 'int64' | 'fixdt(1,16,0)' | '<data type expression>'
Default: 'Inherit: Same as input'

Select to lock data type settings of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor. For more information, see Lock the Output Data Type Setting (Fixed-Point Designer).

Programmatic Use

Block Parameter: LockScale
Values: 'off' | 'on'
Default: 'off'

Specify the rounding mode for fixed-point operations. For more information, see Rounding (Fixed-Point Designer).

Programmatic Use

Block Parameter: RndMeth
Type: character vector
Values: 'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' | 'Zero'
Default: 'Floor'

Specify whether overflows saturate or wrap.

ActionRationaleImpact on OverflowsExample

Select this check box (on).

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.

The maximum value that the int8 (signed, 8-bit integer) data type can represent is 127. Any block operation result greater than this maximum value causes overflow of the 8-bit integer. With the check box selected, the block output saturates at 127. Similarly, the block output saturates at a minimum output value of -128.

Do not select this check box (off).

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 Troubleshoot Signal Range Errors.

Overflows wrap to the appropriate value that is representable by the data type.

The maximum value that the int8 (signed, 8-bit integer) data type can represent is 127. Any block operation result greater than this maximum value causes overflow of the 8-bit integer. With the check box cleared, the software interprets the overflow-causing value as int8, which can produce an unintended result. For example, a block result of 130 (binary 1000 0010) expressed as int8, is -126.

When you select this check box, saturation applies to every internal operation on the block, not just the output, or result. Usually, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.

Programmatic Use

Block Parameter: SaturateOnIntegerOverflow
Type: character vector
Values: 'off' | 'on'
Default: 'off'

State Attributes

Assign a unique name to each state. If this field is blank (' '), no name assignment occurs.

  • To assign a name to a single state, enter the name between quotes, for example, 'position'.

  • To assign names to multiple states, enter a comma-delimited list surrounded by braces, for example, {'a', 'b', 'c'}. Each name must be unique.

  • To assign state names with a variable in the MATLAB® workspace, enter the variable without quotes. A variable can be a character vector, cell array, or structure.

Limitations

  • The state names apply only to the selected block.

  • The number of states must divide evenly among the number of state names.

  • You can specify fewer names than states, but you cannot specify more names than states.

    For example, you can specify two names in a system with four states. The first name applies to the first two states and the second name to the last two states.

Dependencies

To enable this parameter, set Filter structure to Direct form II.

Programmatic Use

Block Parameter: StateName
Type: character vector
Values: ' ' | user-defined
Default: ' '

Select this check box to require that the state name resolves to a Simulink signal object.

Dependencies

To enable this parameter, set Filter structure to Direct form II and specify a value for State name. This parameter appears only if you set the model configuration parameter Signal resolution to a value other than None.

Programmatic Use

Block Parameter: StateMustResolveToSignalObject
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Block Characteristics

Data Types

double | fixed pointa | integera | single

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

a This block only supports signed fixed-point data types.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Version History

Introduced before R2006a

expand all

See Also

| (DSP System Toolbox) | (DSP System Toolbox) | (DSP System Toolbox) | (DSP System Toolbox) | (DSP System Toolbox) | (DSP System Toolbox) | (Signal Processing Toolbox)