Documentation Center

  • Trial Software
  • Product Updates

Discrete FIR Filter

Model FIR filters

Library

Discrete

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, as well as 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 those of the input, 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.

The outputs of this block numerically match the outputs of the DSP System Toolbox Digital Filter Design block and of the Signal Processing Toolbox™ dfilt object.

This block supports the Simulink® state logging feature. See States in the Simulink User's Guide for more information.

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.

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

Data Type Support

The Discrete FIR Filter block accepts and outputs real and complex signals of any numeric data type supported by Simulink. The block supports the same types for the coefficients.

The following diagrams show the filter structure and the data types used within the Discrete FIR Filter block for fixed-point signals.

Direct Form

You cannot specify the state data type on the block mask for this structure because the input states have the same data types as the input.

Direct Form Symmetric

You cannot specify the state data type on the block mask for this structure because the input states have the same data types as the input.

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

Direct Form Antisymmetric

You cannot specify the state data type on the block mask for this structure because the input states have the same data types as the input.

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

Parameters and Dialog Box

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

Coefficient source

Select whether you want to specify the filter coefficients on the block mask or through an input port.

Filter structure

Select the filter structure you want the block to implement. 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.

Coefficients

Specify the vector coefficients of the filter's 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. This parameter is visible only when Coefficient source is set to Dialog parameters . For multiple filter, Filter structure must be Direct form, and the input must be a scalar.

Input processing

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 in the DSP System Toolbox documentation.

Initial states

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

Sample time (-1 for inherited)

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See Specify Sample Time.

The Data Types pane of the Discrete FIR Filter block dialog box appears as follows.

Tap sum

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)

This parameter is only visible when the selected filter structure is either Direct form symmetric or Direct form antisymmetric.

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Tap sum parameter.

See Specify Data Types Using Data Type Assistant for more information.

Coefficients

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)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Coefficients parameter.

See Specify Data Types Using Data Type Assistant for more information.

Coefficients minimum

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

Coefficients maximum

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

Product output

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)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Product output parameter.

See Specify Data Types Using Data Type Assistant for more information.

Accumulator

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)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Accumulator parameter.

See Specify Data Types Using Data Type Assistant for more information.

State

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)

This parameter is only visible when the selected filter structure is Lattice MA.

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the State parameter.

See Specify Data Types Using Data Type Assistant for more information.

Output

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)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Output parameter.

See Specify Block Output Data Types for more information.

Output minimum

Specify the minimum value that the block should 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

Output maximum

Specify the maximum value that the block should 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

Lock data type settings against changes by the fixed-point tools

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 Lock the Output Data Type Setting in the Fixed-Point Designer™ documentation.

Integer rounding mode

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

Saturate on integer overflow
ActionReasons for Taking This ActionWhat Happens for OverflowsExample

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.

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.

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

Characteristics

Direct Feedthrough

Yes

Sample Time

Specified in the Sample time parameter

Scalar Expansion

Yes, of initial states

States

See Specifying Initial States

Dimensionalized

Yes

Zero-Crossing Detection

No

Was this topic helpful?