Main Content

Discrete FIR Filter

Model FIR filters

  • Discrete FIR Filter block

Libraries:
Simulink / Discrete
HDL Coder / Discrete
HDL Coder / HDL Floating Point Operations

Description

The Discrete FIR Filter block independently filters each channel of the input signal with the specified digital FIR filter. The block can implement static filters with fixed coefficients, and time-varying filters with coefficients that change over time. You can tune the coefficients of a static filter during simulation.

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 the input dimensions, except when you specify a matrix of filter taps for the Coefficients parameter. When you do so, the output dimensions depend on the number of different sets of filter taps you specify.

This block supports custom state attributes to customize and generate code more efficiently. For an example, see Custom State Attributes in Discrete FIR Filter block. Under certain conditions, the block also supports SIMD code generation. For details, see Code Generation.

The outputs of this block numerically match the outputs of the DSP System Toolbox Digital Filter Design (DSP System Toolbox) block.

This block supports the Simulink® state logging feature. For more information, see State.

Filter Structure Support

You can change the filter structure implemented with the Discrete FIR Filter block by selecting one of the following from the Filter structure parameter:

  • Direct form

  • Direct form symmetric

  • Direct form antisymmetric

  • Direct form transposed

  • Lattice MA

You must have an available DSP System Toolbox license to run a model with any of these filter structures other than Direct form.

For more information on the filter structures, see Algorithms.

Specifying Initial States

The Discrete FIR Filter block initializes the internal filter states to zero by default, which has the same effect as assuming that past inputs and outputs are zero. You can optionally use the Initial states parameter to specify nonzero initial conditions for the filter delays.

To determine the number of initial states you must specify and how to specify them, see the table on valid initial states. The Initial states parameter can take one of the forms described in the next table.

Valid Initial States

Initial ConditionDescription

Scalar

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

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

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

  • The vector length equals the product of the number of input channels and the number of delay elements in the filter, #_of_filter_coeffs-1 (or #_of_reflection_coeffs for Lattice MA).

  • The matrix must have the same number of rows as the number of delay elements in the filter, #_of_filter_coeffs-1 (#_of_reflection_coeffs for Lattice MA), and must have one column for each channel of the input signal.

Examples

Ports

Input

expand all

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

The Discrete FIR Filter block accepts real and complex signals of any numeric data type supported by Simulink.

Dependencies

When you set Coefficient source to Dialog parameters, the port for the input signal is unlabeled. When you set Coefficient source to Input port, the port for the input signal is labeled In.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Complex Number Support: Yes

Specify the filter coefficients as a scalar, vector, or matrix. When you specify a row vector of filter taps, the block applies a single filter to the input.

Dependencies

To enable this port, set Coefficient source to Input port.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

External reset signal, specified as a scalar. When the specified trigger event occurs, the block resets the states to their initial conditions.

Tip

The icon for this port changes based on the value of the External reset parameter.

Dependencies

To enable this port, set External reset to Rising, Falling, Either, Level, or Level hold.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Enable signal, specified as a scalar. This port can control execution of the block. The block is enabled when the input to this port is nonzero, and is disabled when the input is 0. The value of the input is checked at the same time step as the block execution.

Dependencies

To enable this port, select the Show enable port check box.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Output

expand all

Filtered output signal, returned as a scalar, vector, or a matrix. The Discrete FIR Filter block outputs real and complex signals of any numeric data type supported by Simulink.

When the input to the block is fixed-point, the data type of the block output is determined based on the value you specify in the Output parameter. When the input is floating-point, the output data type matches the input data type since floating-point inheritance takes precedence over the fixed-point settings.

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

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Parameters

expand all

Main

Choose to specify the filter coefficients using tunable dialog parameters or through an input port, which is useful for time-varying coefficients.

Programmatic Use

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

Select the filter structure you want the block to implement. For more information, see Algorithms.

Dependencies

You must have an available DSP System Toolbox license to run a model with a Discrete FIR Filter block that implements any filter structure other than Direct form.

Programmatic Use

Block Parameter: FilterStructure
Type: character vector
Values: 'Direct form' | 'Direct form symmetric' | 'Direct form antisymmetric' | 'Direct form transposed' | 'Lattice MA'
Default: 'Direct form'

Specify the coefficient vector for the transfer function. Filter coefficients must be specified as a row vector. When you specify a row vector of filter taps, the block applies a single filter to the input. To apply multiple filters to the same input, specify a matrix of coefficients, where each row represents a different set of filter taps.

Dependencies

To enable this parameter, set Coefficient source to Dialog parameters.

To implement multiple filters, Filter structure must be Direct form, and the input must be a scalar.

Programmatic Use

Block Parameter: Coefficients
Type: character vector
Values: vector
Default: '[0.5 0.5]'

Specify whether the block performs sample- or frame-based processing. You can select one of the following options:

  • Elements as channels (sample based) — Treat each element of the input as an independent channel (sample-based processing).

  • Columns as channels (frame based) — Treat each column of the input as an independent channel (frame-based processing).

    Note

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

Specify the initial conditions of the filter states. To learn how to specify initial states, see Specifying Initial States.

Programmatic Use

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

Select to control execution of this block with an enable port. The block is considered enabled when the input to this port is nonzero, and is disabled when the input is 0. The value of the input is checked at the same time step as the block execution.

Programmatic Use

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

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 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 tap sum data type of a direct form symmetric or direct form antisymmetric filter, which is the data type the filter uses when it sums the inputs prior to multiplication by the coefficients. 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)

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

This parameter is only visible when you set the Filter structure to Direct form symmetric or Direct form antisymmetric.

Programmatic Use

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

Specify the coefficient data type. You can set it to:

  • A rule that inherits a data type, for example, Inherit: Same word length 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: CoefDataTypeStr
Type: character vector
Values: 'Inherit: Same word length as input'| 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | '<data type expression>'
Default: 'Inherit: Same wordlength as input'

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

Programmatic Use

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

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

Programmatic Use

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

Specify the product 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)

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: ProductDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule' | 'Inherit: Same as input' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'fixdt(1,16,0)' | '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

Specify the accumulator 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)

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: AccumDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule' | 'Inherit: Same as input' | 'Inherit: Same as product output' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'fixdt(1,16,0)' | '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

Specify the state data type. You can set it to:

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

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

Dependencies

To enable this parameter, set the Filter structure to Lattice MA.

Programmatic Use

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

Specify the output data type. You can set it to:

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

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

When the input to the block is floating-point, the output data type matches the input data type since floating-point inheritance takes precedence over the fixed-point settings.

Programmatic Use

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

Lower value of the output range that Simulink checks.

Simulink uses the minimum to perform:

Note

Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead.

Programmatic Use

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

Upper value of the output range that Simulink checks.

Simulink uses the maximum value to perform:

Note

Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead.

Programmatic Use

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

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'

Block Characteristics

Data Types

double | fixed point | integer | single

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

yes

Zero-Crossing Detection

no

More About

expand all

Algorithms

These are the structure diagrams used within the Discrete FIR Filter block.

Direct Form

Direct Form Symmetric

It is assumed that the filter coefficients are symmetric. The block only uses the first half of the coefficients for filtering.

Direct Form Antisymmetric

It is assumed that the filter coefficients are antisymmetric. The block only uses the first half of the coefficients for filtering.

Direct Form Transposed

States are complex when either the inputs or the coefficients are complex.

Lattice MA

Extended Capabilities

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

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Version History

Introduced in R2008a

expand all