| DSP Blockset | ![]() |
Independently filter each channel of the input over time using a specified time-varying or static digital filter implementation
Library
Filtering / Filter Designs
Description
Note
Use this block to efficiently implement floating-point and fixed-point filters for which you know the coefficients. The following DSP Blockset blocks also implement digital filters, but serve slightly different purposes:
|
The Digital Filter block independently filters each channel of the input signal with a specified digital IIR or 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 output size, frame status, and dimension are always the same as those of the input signal that is filtered. When inputs are frame based, the block treats each column as an independent channel; the block filters each column. When inputs are sample based, the block treats each element of the input as an individual channel.
The outputs of this block numerically match the outputs of the Digital Filter Design block and of the dfilt function in the Signal Processing Toolbox.
Sections of This Reference Page
Supported Filter Structures
The selection of filter structures offered in the Filter structure parameter depends on whether you set the Transfer function type to IIR (poles & zeros), IIR (all poles), or FIR (all zeros), as summarized in the table below.
| Note The IIR Biquadratic Direct Form II Transposed and FIR Direct Form modes currently support fixed-point signals as well as floating-point signals. |
The table also shows the vector or matrix of filter coefficients you must provide for each filter structure. For more information on how to specify filter coefficients for various filter structures, see Specifying Static Filters and Specifying Time-Varying Filters.
| Transfer Function Type |
Supported Filter Structures |
Filter Coefficient Specification |
IIR (poles & zeros) | Direct form I Direct form I transposed Direct form II Direct form II transposed |
|
| Biquadratic direct form II transposed (SOS)1 |
M-by-6 second-order section (SOS) matrix. See Specifying the SOS Matrix (Biquadratic Filter Coefficients). |
|
IIR (all poles) | Direct form Direct form transposed |
Denominator coefficients vector [a0, a1, a2, ..., am] |
| Lattice AR |
Reflection coefficients vector [k1, k2, ..., kn] |
|
FIR (all zeros) | Direct form2 Transposed direct form |
Numerator coefficients vector [b0, b1, b2, ..., bn] |
| Lattice MA |
Reflection coefficients vector [k1, k2, ..., kn] |
Supported for fixed-point as well as floating-point signals. Supported for fixed-point as well as floating-point signals.
|
Specifying Static Filters
To specify a static filter whose coefficients are fixed in time, set 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 the Filter Structures and Filter Coefficients table above:
Tuning the Filter Coefficient Values During Simulation. 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.
Specifying Time-Varying Filters
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. You can filter multiple channels with each filter, but you cannot apply different filters to each channel; all channels must be filtered with the same filter.
To specify a time-varying filter, you must do the following:
Input port(s), which enables extra block input ports for the time-varying filter coefficients. The following diagram shows one block with an extra port for reflection coefficients, and another with extra ports for numerator and denominator coefficients.
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.
Setting the Coefficient Update Rate. 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. If 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.
Providing Filter Coefficient Vectors at Block Input Ports. 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:
The output size, frame status, and dimension always match those of the input signal that is filtered, not the vector of filter coefficients.
The time-varying filter coefficient vectors can be sample- or frame-based row or column vectors. The vector of filter coefficients must arrive at their input ports at the same times that the frames of input data arrive at their input port, as indicated in the following table.
Removing the 1/a0 Term in the Filter Structure. If you know that the first denominator filter coefficient (a0) is always 1 for your time-varying filter, select the First denominator coefficient = 1, remove 1/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.

Specifying the SOS Matrix (Biquadratic Filter Coefficients)
The block does not support time-varying biquadratic direct form II transposed filters. To specify a static biquadratic direct form II transposed filter (also known as a second-order section or SOS direct form II transposed filter), you need to set the following parameters as indicated:
IIR (poles & zeros)
Biquadratic direct form II transposed (sos)
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. You can use the ss2sos and tf2sos functions from the Signal Processing Toolbox to convert a state-space or transfer-function description of your filter into the second-order section description used by this block.
| Note The block uses a value of 1 for the zero-delay denominator coefficients (a11 to a1M) regardless of the value specified in the SOS matrix (Mx6) parameter. |
Specifying Initial Conditions
By default, the block initializes the internal filter states to zero, which is equivalent to assuming past inputs and outputs are zero. You can optionally use the Initial conditions parameter to specify nonzero initial conditions for the filter delays.
To determine the number of initial condition values you must specify, and how to specify them, refer to the following table on Valid Initial Conditions and Number of Delay Elements (Filter States). The Initial conditions parameter may take one of four forms as described in the following table.
The number of delay elements (filter states) per input channel depends on the filter structure, as indicated in the following table.
Fixed-Point Data Types
The diagrams in this section show the data types used for the filter structures that are currently supported for fixed-point signals. You can set the coefficient, output, accumulator, product output, and state data types shown in these diagrams in the block mask. This is discussed in Dialog Box.
The following diagram shows the data types used for the FIR Direct Form filter for fixed-point signals. A filter with two stages is shown; additional stages can be inserted at the dashed lines.

The following diagram shows the data types used for one section of the IIR Biquadratic Direct Form II Transposed filter for fixed-point signals.
| Note For this filter, the numerator coefficient word and fraction lengths must be the same as the denominator coefficient word and fraction lengths. |
For a multiple-stage IIR Biquadratic Direct Form II Transposed filter, the output of each stage is cast to the input data type before entering the next stage of the filter. The following diagram shows an example with three stages.

Examples
The following Simulink model is digitalfilter_tut.mdl. To build the model yourself, follow the step-by-step instructions in Digital Filter Block, which also provides a full explanation of the model.

After building and running the model, the vector scope display should look like the following.
Dialog Box
IIR (poles & zeros), IIR (all poles), or FIR (all zeros). Refer to Supported Filter Structures for more information.
Specify via dialog, the applicable coefficients parameters are available. If you select Input ports(s), filter coefficients must come in through block ports.
Dialog parameter(s) and when the selected filter structure lends itself to specification with numerator coefficients. Tunable.
Dialog parameter(s) and when the selected filter structure lends itself to specification with denominator coefficients. Tunable.
Dialog parameter(s) and when the selected filter structure lends itself to specification with reflection coefficients. Tunable.
ss2sos and tf2sos functions from the Signal Processing Toolbox to check whether your SOS matrix is valid. For more on the requirements of the SOS matrix, see Specifying the SOS Matrix (Biquadratic Filter Coefficients). This parameter is only visible when the Coefficient source parameter is set to Dialog parameter(s) and when the selected filter structure lends itself to specification with an SOS matrix. Tunable.
1 / a0 term in the filter structure. 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. This parameter is only enabled when the Coefficient source parameter is set to Input port(s) and when the selected filter structure lends itself to this specification. See Removing the 1/a0 Term in the Filter Structure for a diagram and details.
Input port(s). For more information, see Specifying Time-Varying Filters.
When the Show coefficient fixed-point attributes, Show output fixed-point attributes, Show accumulator fixed-point attributes, Show product output fixed-point attributes, or Show state memory fixed-point attributes check box is selected, additional parameters become available, as discussed in the following sections:
Same as input, the numerator coefficient word and fraction lengths are the same as those of the input to the block. If you select User-defined, the Numerator coefficient word length and Numerator coefficient fraction length parameters become visible.
User-defined is specified for the Numerator coefficient attributes parameter.
User-defined is specified for the Numerator coefficients attributes parameter.
Same as numerator, the denominator coefficient word and fraction lengths are the same as those of the numerator coefficients. If you select Same as input, they are the same as those of the input to the block. If you select User-defined, the Denominator coefficient word length and Denominator coefficient fraction length parameters become visible.
User-defined is specified for the Denominator coefficient attributes parameter.
User-defined is specified for the Denominator coefficients attributes parameter.
Same as input, the output word and fraction lengths are the same as those of the input to the block. If you select User-defined, the Output word length and Output fraction length parameters become visible.
User-defined is specified for the Output attributes parameter.
User-defined is specified for the Output attributes parameter.
Same as output, the accumulator word and fraction lengths are the same as those of the output of the block. If you select User-defined, the Accumulator word length and Accumulator fraction length parameters become visible.
User-defined is specified for the Accumulator attributes parameter.
User-defined is specified for the Accumulator attributes parameter.
Same as output, the product output word and fraction lengths are the same as those of the output of the block. If you select Same as accumulator, they match those of the accumulator. If you select User-defined, the Product output word length and Product output fraction length parameters become visible.
User-defined is specified for the Product output attributes parameter.
User-defined is specified for the Product output attributes parameter.
Same as input, Same as output, or Same as accumulator, the state memory word and fraction lengths are the same as those of the input, output, or accumulator of the block, respectively. If you select User-defined, the State memory word length and State memory fraction length parameters become visible.
User-defined is specified for the State memory attributes parameter.
User-defined is specified for the State memory attributes parameter.
Nearest.
Supported Data Types
To learn how to convert your data types to the above data types in MATLAB and Simulink, see Supported Data Types and How to Convert to Them.
See Also
| Digital Filter Design |
DSP Blockset |
| Filter Realization Wizard |
DSP Blockset |
fdatool |
Signal Processing Toolbox |
fvtool |
Signal Processing Toolbox |
sptool |
Signal Processing Toolbox |
| Difference | Digital Filter Design | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |