DSP Blockset    
Digital Filter

Independently filter each channel of the input over time using a specified time-varying or static digital filter implementation

Library

Filtering / Filter Designs

Description

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

The block filters each channel of the input signal independently over time. The output size, frame status, dimension, and data type 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 the block numerically match the outputs of the Digital Filter Design block, the filter function in the Signal Processing Toolbox, and the filter function in Filter Design 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 filter to be IIR with poles and zeros, IIR with all poles, or FIR with all zeros, as summarized in the following table. 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.

Table 7-3: Filter Structures and Filter Coefficients 
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
  • Numerator coefficients vector [b0, b1, b2, ..., bn]
  • Denominator coefficients vector [a0, a1, a2, ..., am]
Biquadratic direct form II transposed (second-order sections)
M-by-6 second-order section (SOS) matrix.
See Specifying the SOS Matrix (Biquadratic Filter Coefficients).
IIR (all poles)
Direct form
Transposed direct form
Denominator coefficients vector [a0, a1, a2, ..., am]
Lattice AR
Reflection coefficients vector [k1, k2, ..., kn]
FIR (all zeros)
Direct form
Transposed direct form
Numerator coefficients vector [b0, b1, b2, ..., bn]
Lattice MA
Reflection coefficients vector [k1, k2, ..., kn]

Specifying Static Filters

To specify a static filter whose coefficients are fixed in time, set the Coefficient source parameter to Dialog parameter(s). 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 Table 7-3, Filter Structures and Filter Coefficients:

Tuning the Filter Coefficient Values During Simulation.   You can change the value of the static filter coefficients during a running simulation. To tune the coefficients during a simulation, double-click the block, type in the new vector(s) of filter coefficients, and click Apply. 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:

  1. Set the Coefficient source parameter to 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.

  2. Set the Coefficient update rate parameter to 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.
  3. Provide vectors of numerator, denominator, or reflection coefficients to the block input ports for filter coefficients. The series of vectors must arrive at their ports at a specific rate, and sometimes must be of certain lengths. To learn more, see Providing Filter Coefficient Vectors at Block Input Ports.
  4. Select or clear the First denominator coefficient = 1, remove 1/a0 term in the structure parameter depending on whether your first denominator coefficient is always 1. To learn more, see Removing the 1/a0 Term in the Filter Structure.

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:

Though the following figure shows the block filtering one channel, the block can filter multiple channels. (The block can apply a single filter to multiple channels, but cannot apply a different filter to each channel.) To learn how to correctly specify vectors of time-varying filter coefficients, see Providing Filter Coefficient Vectors at Block Input Ports.

Figure 7-1: Options for Updating a Time-Varying Filter for a Frame-Based Input Signal

Providing Filter Coefficient Vectors at Block Input Ports.   As illustrated in Figure 7-1, 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, dimension, and data type always match those of the input signal that is filtered, not the vector of filter coefficients.

Table 7-4: Length Requirements for Time-Varying Filter Coefficient Vectors
Coefficient Update Rate
How to Specify Filter Coefficient Vectors
(Also see Figure 7-1)
Length Requirements
Once per frame
Each coefficient vector corresponds to one input frame, and represents one filter. Specify each vector as you would any static filter: [b0, b1, b2, ..., bn], [a0, a1, a2, ..., am], or [k1, k2, ..., kn]
None
Once per sample
Each coefficient vector corresponds to one input frame, but represents multiple filters of the same length: one filter for each sample in the current frame. To create such a vector, concatenate all the filters for each sample within the input frame.
For instance, the following vector specifies length-2 numerator coefficients for each sample in a frame of three samples:

where

 filters the first sample in the input frame, 

filters the second sample, and so on.

All filters must be the same length, L.

The length of each filter coefficient vector must be L times the number of samples per frame in the input. (Each sample in the frame has one set 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.

Table 7-5: Rate Requirements for Time-Varying Filter Coefficient Vectors
Input Signal
Time-Varying Filter Coefficient Vectors
Rate Requirements
(Also see Figure 7-1)
Sample-based
Sample-based
Sample rates of input and filter coefficients must be equal
Sample-based
Frame-based
Input sample rate must equal filter coefficient frame rate
Frame-based
Sample-based
Input frame rate must equal filter coefficient sample rate
Frame-based
Frame-based
Frame rates of input and filter coefficients must be equal

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:

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.

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 Table 7-6, Valid Initial Conditions and Table 7-7, Number of Delay Elements (Filter States). The Initial conditions parameter may take one of four forms as described in the following table.

Table 7-6: Valid Initial Conditions 
Initial Condition
Examples
Description
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: [d1 d2]

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 Table 7-7).
Vector or Matrix
(for applying different delay elements to each channel)
For a 3-channel input signal and a filter with two delay elements:

[d1 d2 D1 D2 d1 d2] or




  • 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 d1 and 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 Table 7-7).
  • The matrix must have the same number of rows as the number of delay elements in the filter (specified in Table 7-7), 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.

Table 7-7: Number of Delay Elements (Filter States)
Filter Structure
Number of Delay Elements
Direct form
#_of_filter_coeffs - 1
Direct form I
  • #_of_zeros - 1
  • #_of_poles - 1
Direct form II
max(#_of_zeros, #_of_poles) - 1
Transposed direct form
#_of_filter_coeffs - 1
Direct form I transposed
  • #_of_zeros - 1
  • #_of_poles - 1
Direct form II transposed
max(#_of_zeros, #_of_poles) - 1
Biquadratic direct form II transposed (second-order sections)
2 * #_of_filter_sections
Lattice AR and Lattice MA
#_of_reflection_coeffs

Example

You can open the following model by clicking here in the MATLAB Help browser (not in a Web browser). To build the model yourself, follow the step-by-step instructions in Implementing Predesigned Filters with the Digital Filter Block, which also provides a full explanation of the model.

Figure 7-2: Model Using the Digital Filter Block to Implement Filters

Figure 7-3: Vector Scope Display After Running the Model

Dialog Box

Transfer function type
The type of transfer function of the filter: FIR all-zero, IIR all-pole, or IIR with poles and zeros.
Filter structure
The filter's structure. The selection of structures varies depending the setting of the Transfer function type parameter; for the available structures, see Supported Filter Structures.
Coefficient source
Where to specify filter coefficients: in dialog parameter(s), or through input port(s). To specify time-varying filter coefficients that change in time, specify them through input ports (for more information on time-varying filters, see Specifying Time-Varying Filters).
Numerator coefficients
Vector of numerator coefficients of the filter's transfer function. This parameter is only visible when the Coefficient source parameter is set to Dialog parameter(s) and the filter lends itself to specification with numerator coefficients. Tunable.
Denominator coefficients
Vector of denominator coefficients of the filter's transfer function. This parameter is only visible when the Coefficient source parameter is set to Dialog parameter(s) and the filter lends itself to specification with denominator coefficients. Tunable.
Reflection coefficients
Vector of reflection coefficients of the filter's transfer function. This parameter is only visible when the Coefficient source parameter is set to Dialog parameter(s) and the filter lends itself to specification with reflection coefficients. Tunable.
SOS matrix (Mx6)
An M-by-6 SOS matrix containing coefficients of a second-order section (SOS) filter, where M is the number of sections. You can use the ss2sos and tf2sos functions from the Signal Processing Toolbox to check wether 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 visible only when the Coefficient source parameter is set to Dialog parameter(s) and the filter lends itself to specification with an SOS matrix. Tunable.
First denominator coefficient = 1, remove 1/a0 term in the structure
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). 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 visible only when the Coefficient source parameter is set to Input port(s). See Removing the 1/a0 Term in the Filter Structure for a diagram and details.
Coefficient update rate
How often the block updates time-varying filters: once per sample, or once per frame. This parameter only affects the output when the input signal is frame-based. For more information, see Specifying Time-Varying Filters.
Initial conditions
The initial conditions of the filter's states. To learn how to specify initial conditions, see Specifying Initial Conditions.
Initial conditions on zeros side
The initial conditions for the filter states on the side of the filter structure with the zeros (b0, b1, b2, ...); see the following diagram. This parameter is enabled only when the filter has both poles and zeros, and you select a structure such as direct form I, which has separate filter states corresponding to the poles (ak) and zeros (bk). To learn how to specify initial conditions, see Specifying Initial Conditions.
Initial conditions on poles side
The initial conditions for the filter states on the side of the filter structure with the poles (a0, a1, a2, ...); see the following diagram. This parameter is enabled only when the filter has both poles and zeros, and you select a structure such as direct form I, which has separate filter states corresponding to the poles (ak) and zeros (bk). To learn how to specify initial conditions, see Specifying Initial Conditions.

Supported Data Types

To learn how to convert to the above data types in MATLAB and Simulink, see Supported Data Types and How to Convert to Them.

The output data type is the same as the data type of the filtered input signal (not necessarily the same as the data type of the filter coefficients).

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