Biquad Filter - Model biquadratic IIR (SOS) filters - Simulink (original) (raw)

Model biquadratic IIR (SOS) filters

Libraries:
DSP System Toolbox / Filtering / Filter Implementations
DSP System Toolbox HDL Support / Filtering

Description

The Biquad Filter block independently filters each channel of the input signal with the specified biquadratic infinite impulse response (IIR) filter. When you specify the filter coefficients in the dialog box, the block implements static filters with fixed coefficients. When you provide the filter coefficients through an input port, you can tune the coefficients during simulation.

The Biquad Filter block supports the Simulink® state logging feature. See State (Simulink) for more information.

Note

Both the Biquad Filter and the Second-Order Section Filter blocks implement a cascade of second-order section filters in Simulink. However, they differ in a few aspects such as the filter tunability and support for fixed-point signals.

If the input signal is of single or double data type, use the Second-Order Section Filter block because it has several advantages over the Biquad Filter block. If the input signal is of built-in integer or fixed-point arithmetic, use the Biquad Filter block. You can customize theBiquad Filter block for fixed-point arithmetic operations.

For more information on key differences between the two blocks, see Difference Between Biquad Filter and Second-Order Section Filter Blocks.

Examples

Ports

Input

expand all

Data input to the block, specified as a vector or a matrix. This block supports variable-size input signals, enabling you to change the input frame size (number of rows) during simulation. However, the number of channels (number of columns) must remain constant.

If the input is fixed-point, it must be signed fixed-point with binary point scaling.

This port is unnamed unless you set the Coefficient source toInput port(s).

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

Numerator coefficients of the biquad filter, specified as a 3-by-N matrix, where N is the number of biquad filter sections.

If Num is fixed-point, it must be signed fixed-point with binary point scaling.

Dependencies

This port appears only when you set the Coefficient source toInput port(s).

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

Denominator coefficients of the biquad filter, specified as a 2-by-N matrix, where N is the number of biquad filter sections.

If Den is fixed-point, it must be signed fixed-point with binary point scaling.

Dependencies

This port appears only when you set the Coefficient source toInput port(s).

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

Scale values of the biquad filter, specified as a 1-by-(N+1) vector, where N is the number of biquad filter sections.

If g is fixed-point, it must be signed fixed-point with binary point scaling.

Dependencies

This port appears only when you set the Coefficient source toInput port(s).

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

Output

expand all

Filtered output, returned as a vector or a matrix.

The output dimensions always equal the dimensions of the input signal.

If Out is fixed-point, it must be signed fixed-point with binary point scaling.

This port is unnamed unless you set the Coefficient source toInput port(s).

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

Parameters

expand all

Main Tab

The Biquad Filter block can operate in three different modes:

Specify the name of the discrete-time filter that you want the block to implement. You must specify the filter as a dsp.BiquadFilter System object.

You can define the System object in the block mask or in a MATLAB® workspace variable.

For information on creating System objects, see Define Basic System Objects.

Dependencies

This parameter is visible only when Coefficient source is set toFilter object.

Specify the filter structure.

Dependencies

This parameter is visible only when Coefficient source is set toDialog parameters or Input port(s).

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

The leading denominator coefficients [a01 a02 ... a0N] are treated as 1s, regardless of their actual values. No scaling is applied to the SOS matrix when a0 is not 1.

The ss2sos and tf2sos functions convert a state-space or transfer function description of your filter into the second-order section description used by this block.

Dependencies

This parameter is visible only when Coefficient source is set toDialog parameters.

Specify scale values to be used between SOS sections. You can specify a real-valued scalar or a vector of length M+1:

Select the Optimize unity scale values check box to optimize your simulation when one or more scale values equal 1. Selecting this option removes the unity gains so that the values are treated like Simulink lines or wires. In some fixed-point cases when there are unity scale values, selecting this parameter also omits certain casts. Refer to the Fixed-Point Data Types section for more information.

Dependencies

This parameter is visible only when Coefficient source is set toDialog parameters.

Specify the initial conditions of the filter states when Filter structure is set to Direct form II orDirect form II transposed.

Direct form II

Direct form II transposed

The Biquad Filter block initializes the internal filter states to zero by default. To specify nonzero initial states for the filter delays, use the Initial conditions parameter.

To determine the number of initial conditions you must specify and how to specify them, see the following table on valid initial conditions.

Valid Initial Conditions

Initial Condition Description
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. M is the number of sections, and N is the number of input channels:The vector length must equal the number of delay elements in the filter, 2_M_.The matrix must have the same number of rows as the number of delay elements in the filter 2_M_ N. The matrix must also have one column for each channel of the input signal.

Dependencies

This parameter is only visible when Coefficient source is set toDialog parameters or Input port(s) and the Filter structure is set to Direct form II or Direct form II transposed.

Specify the initial conditions for the filter states on the side of the filter structure with the zeros (b0,b1, b2, …). This parameter applies only when Filter structure is set toDirect form I or Direct form I transposed.

Direct form I

Direct form I transposed

The Biquad Filter block initializes the internal filter states to zero by default. To specify nonzero initial states for the filter delays, use the Initial conditions on zeros side parameter.

To determine the number of initial conditions you must specify and how to specify them, see the following table on valid initial conditions.

Valid Initial Conditions

Initial Condition Description
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. Where M is the number of sections and N is the number of input channels:The vector length must equal the number of delay elements in the filter, 2_M_.The matrix must have the same number of rows as the number of delay elements in the filter 2_M_ N. The matrix must also have one column for each channel of the input signal.

Dependencies

This parameter is visible only when Coefficient source is set toDialog parameters or Input port(s) and the Filter structure is set to Direct form I or Direct form I transposed.

Specify the initial conditions for the filter states on the side of the filter structure with the poles (a1,a2, ...). This parameter applies only whenFilter structure is set to Direct form I orDirect form I transposed.

Direct form I

Direct form I transposed

The Biquad Filter block initializes the internal filter states to zero by default. To specify nonzero initial states for the filter delays, use the Initial conditions on poles side parameter.

To determine the number of initial conditions you must specify and how to specify them, see the following table on valid initial conditions.

Valid Initial Conditions

Initial Condition Description
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. Where M is the number of sections and N is the number of input channels:The vector length must equal the number of delay elements in the filter, 2_M_.The matrix must have the same number of rows as the number of delay elements in the filter 2_M_ N. The matrix must also have one column for each channel of the input signal.

Dependencies

This parameter is visible only when Coefficient source is set toDialog parameters or Input port(s) and the Filter structure is set to Direct form I or Direct form I transposed.

Choose how to specify the scale values to use between filter sections. When you selectSpecify via input port (g), you enter the scale values as a 2-D vector at port g. When you select Assume all are unity and optimize, all scale values are removed and treated like Simulink lines or wires.

Dependencies

This parameter is visible only when Coefficient source is set toInput port(s).

Specify the action the block should perform when the SOS matrix_a0j_ values do not equal one. The action can beWarning, Error, orNone.

When you choose None, the leading coefficients_a0j_ are treated as 1's, regardless of their actual values. No scaling is applied on the SOS matrix when a0 is not 1.

Dependencies

This parameter is visible only when Coefficient source is set toDialog parameters.

Select this check box to optimize your simulation when one or more scale values equal 1. Selecting this option removes the unity gains so that the values are treated like Simulink lines or wires. In some fixed-point cases when there are unity scale values, selecting this parameter also omits certain casts. See the Fixed-Point Data Types section for more information.

Dependencies

This parameter is visible only when Coefficient source is set toDialog parameters.

Specify how the block should process the input. If the input is an_M_-by-N matrix, you can set this parameter to:

This button opens the Filter Visualization Tool (FVTool) and displays the filter response of the filter specified in the dialog.

Note

When you make changes to the filter parameters on the block dialog, you must click theApply button before using the View Filter Response button.

Data Types Tab

Note

This tab appears only when you set Coefficient source to eitherDialog parameters or Input port(s). When the Coefficient source is set to Filter object, the data types specified in the filter object properties are used by the block.

Specify the rounding mode for fixed-point operations.

For more details, see rounding mode. The filter coefficients do not obey this parameter; instead, they always round toNearest.

When you select this parameter, the block saturates the result of its fixed-point operation. When you clear this parameter, the block wraps the result of its fixed-point operation. For details on saturate and wrap, see overflow mode for fixed-point operations.

The filter coefficients are always saturated and do not obey this parameter.

Choose how you specify the word and fraction lengths of the fixed-point data type going into each section of a biquadratic filter. See the Fixed-Point Data Types section for illustrations depicting the use of the section input data type in this block. When you select:

Choose how you specify the word and fraction lengths of the fixed-point data type coming out of each section of a biquadratic filter. See the Fixed-Point Data Types section for illustrations depicting the use of the section output data type in this block. When you select:

Choose how you specify the word and fraction lengths of the multiplicand data type of aDirect form I transposed filter structure. See the Fixed-Point Data Types section for illustrations depicting the use of the multiplicand data type in this block.

When you select:

Dependencies

This parameter is visible only when the Filter structure parameter is set to Direct form I transposed.

Choose how you specify the word and fraction lengths of the filter coefficients (numerator, denominator, and scale value) when Coefficient source is set to Dialog parameters. See the Fixed-Point Data Types section for illustrations depicting the use of the coefficient data types in this block. When you select:

The filter coefficients do not obey the Rounding mode and theOverflow mode parameters; instead, they are always saturated and rounded to Nearest.

Dependencies

This parameter is visible only when Coefficient source is set toDialog parameters.

Specify how to designate the product output word and fraction lengths. See Multiplication Data Types and the Fixed-Point Data Types section for illustrations depicting the use of the product output data type in this block. When you select:

Specify how to designate the accumulator word and fraction lengths. See Multiplication Data Types and the Fixed-Point Data Types section for illustrations depicting the use of the accumulator data type in this block. When you select:

Specify how to designate the state word and fraction lengths when Coefficient source is set to Dialog parameters. See the Fixed-Point Data Types section for illustrations depicting the use of the state data type in this block.

When you select:

Dependencies

This parameter is visible only when Filter structure is set toDirect form II or Direct form II transposed.

Choose how you specify the output word length and fraction length. See the Fixed-Point Data Types section for illustrations depicting the use of the output data type in this block. When you select:

Select this parameter to prevent the fixed-point tools from overriding the data types you specify on the block mask.

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

The diagrams in these sections show the filter structures supported by the Biquad Filter block. They also show the data types used in the filter structures for fixed-point signals. You can set the data types shown in these diagrams in the block dialog box.

Direct Form I

The following diagram shows the data types for one section of the filter for fixed-point signals.

The following diagrams show the fixed-point data types between filter sections.

When the data is not optimized:

When you select Optimize unity scale values and scale values equal 1:

Direct Form I Transposed

The following diagram shows the data types for one section of the filter for fixed-point signals.

The dashed casts are omitted when Optimize unity scale values is selected and scale values equal one.

The following diagrams show the fixed-point data types between filter sections.

When the data is not optimized:

When you select Optimize unity scale values and scale values equal 1:

Direct Form II

The following diagram shows the data types for one section of the filter for fixed-point signals.

The dashed casts are omitted when Optimize unity scale values is selected and scale values equal one.

The following diagrams show the fixed-point data types between filter sections.

When the data is not optimized:

When you select Optimize unity scale values and scale values equal 1:

Direct Form II Transposed

The following diagram shows the data types for one section of the filter for fixed-point signals.

The following diagrams show the fixed-point data types between filter sections.

When the data is not optimized:

When you select Optimize unity scale values and scale values equal 1:

The Biquad Filter and the Second-Order Section Filter blocks implement a cascade of second-order section filters in Simulink. However, they differ in a few aspects such as the filter tunability and support for fixed-point signals.

If the input signal is of single or double data type, use the Second-Order Section Filter block because it has several advantages over the Biquad Filter block. If the input signal is of built-in integer or fixed-point arithmetic, use the Biquad Filter block. You can customize theBiquad Filter block for fixed-point arithmetic operations.

Here is a table that lists the key differences between the two blocks.

| | Second-Order Section Filter Block | Biquad Filter Block | | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Support for built-in integer and fixed-point data types | ⨉ | ✓ | | Specify initial conditions of filter states | ⨉ | ✓ | | Ability to change coefficient values during simulation | ✓ | ⨉ | | Specify numerator and denominator coefficients separately in the block dialog box | ✓ | ⨉You must specify the filter coefficients as SOS matrices. | | Compatibility with the filter design source blocks and the Filter Visualizer block. Filter design source blocks include Lowpass IIR Filter Design, Highpass IIR Filter Design, Bandpass IIR Filter Design, and Bandstop IIR Filter Design. | ✓You can directly pass the coefficients from the filter design source blocks to the Second-Order Section Filter block and theFilter Visualizer block without modifying the coefficients in any way. For an example, see Filter Noisy Signal Using Second-Order Section (SOS) Bandpass Filter in Simulink. | ⨉You must reformat the coefficients from the filter design source blocks to a 3-by-N numerator matrix and a 2-by-N denominator matrix before passing them to the Biquad Filter block. |

Extended Capabilities

expand all

HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.

Note

For an HDL-optimized biquad filter architecture with hardware-friendly control signals, use the Biquad Filter (DSP HDL Toolbox) block. The DSP HDL Toolbox™ block simulates the latency of the HDL algorithm in Simulink. The DSP HDL Toolbox block generates a direct form II or direct form II transposed pipelined add-multiply operation that fits into the DSP block on an FPGA. It provides an optional pipelined feedback architecture that uses more multipliers but reduces the critical path and achieves higher clock rates. The DSP HDL Toolbox block does not support programmable coefficients. To perform multichannel filtering, put the DSP HDL ToolboxBiquad Filter block into a For Each subsystem.

HDL Architecture

The block has HDLDataPath as a default architecture. This architecture provides additional configuration options that affect HDL implementation and synthesized logic.

HDL Block Properties

HDL Block Properties Description
InputPipeline Number of input pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is0. For more details, see InputPipeline (HDL Coder).
OutputPipeline Number of output pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is0. For more details, see OutputPipeline (HDL Coder).
ConstrainedOutputPipeline Number of registers to place at the outputs by moving existing delays within your design. Distributed pipelining does not redistribute these registers. The default is0. For more details, see ConstrainedOutputPipeline (HDL Coder).
FlattenFilter Remove hierarchy of Filter subsystem from generated HDL code. The default isauto. See FlattenHierarchy (HDL Coder).
DSPStyle Synthesis attributes for multiplier mapping. The default isnone. See also DSPStyle (HDL Coder).
SharingFactor Number of functionally equivalent resources to map to a single shared resource. The default is 0. See also Resource Sharing (HDL Coder).
StreamingFactor Number of parallel data paths, or vectors, that are time multiplexed to transform into serial, scalar data paths. The default is 0, which implements fully parallel data paths. See also Streaming (HDL Coder).
ConstMultiplierOptimization Canonical signed digit (CSD) or factored CSD optimization. The default isnone. See also ConstMultiplierOptimization (HDL Coder).
MultiplerArchitecture Select the multipler architecture as linear orshiftadd. The default is linear. For more information, see HDL Code Generation section in Product, Matrix Multiply (Simulink).
MultiplierInputPipeline Specify the number of pipeline stages to add at filter multiplier inputs. See also MultiplierInputPipeline (HDL Coder).
MultiplierOutputPipeline Specify the number of pipeline stages to add at filter multiplier outputs. See also MultiplierOutputPipeline (HDL Coder).
SectionOutputPipeline Specify the number of pipeline stages to add for section outputs. The default is0.
AdderOutputPipeline Number of output pipeline stages to insert in the generated code for addition operation. The default is 0. For more details, see OutputPipeline (HDL Coder).

Data Type Support

The block supports these data types for HDL code generation:

Input Port Dimension Fixed-Point Floating-Point Built-in Integers Bus Boolean Enumerated Complex Signal
In ScalarVectorMatrix Yes HalfSingleDouble Yes Yes Yes Yes Yes

Block Parameter Configuration

These block parameter configurations are incompatible with HDL code generation.

Block Parameter Limitations
Input processing Parameter value Columns as channels (frame based) is not supported.

Optimizations

The block participates in these HDL optimizations to optimize the speed, and area.

Area Optimization

Optimization Description
Resource Sharing (HDL Coder) Resource sharing is an area optimization in which HDL Coder identifies multiple functionally equivalent resources and replaces them with a single resource.
Streaming (HDL Coder) Streaming is an area optimization in which HDL Coder transforms a vector data path to a scalar data path (or to several smaller-sized vector data paths).

Speed Optimization

Optimization Description
Distributed Pipelining (HDL Coder) Distributed pipelining, or register retiming, is a speed optimization that moves existing delays in a design to reduce the critical path while preserving functional behavior.
Clock-Rate Pipelining (HDL Coder) Clock-rate pipelining is an optimization framework in HDL Coder that allows other speed and area optimizations to introduce latency at the clock rate.
Adaptive Pipelining (HDL Coder) Adaptive pipelining optimization creates patterns or combination of blocks with registers that can improve the achievable clock frequency and reduce the area usage on the FPGA boards by inserting pipeline registers to the blocks in your design.
Critical Path Estimation (HDL Coder) To quickly identify the most likely critical path in your design, use_Critical Path Estimation_. Critical path estimation speeds up the iterative process of finding the critical path. To know blocks that are characterized in critical path estimation, see Characterized Blocks (HDL Coder).

Limitations and Considerations

The block has these limitations:

To configure the Biquad Filter block as a programmable filter or a multichannel filter, use the following block settings:

Filter Case Considerations
Programmable Filter HDL Coder supports programmable filters for Biquad Filter blocks.On the filter block mask, set Coefficient source toInput port(s).Connect vector signals to the Num and Den coefficient ports. You must use one Biquad Filter block for each second-order section in your filter. For a filter with M second-order sections, use a series of M Biquad Filter blocks, each with an input Num that is a 3-by-1 vector and an input Den that is a 2-by-1 vector.
Multichannel Filter HDL Coder supports the use of vector inputs to Biquad Filter blocks.Connect a vector signal to the Biquad Filter block input port.Specify Input processing as Elements as channels (sample based).To reduce area by sharing the filter kernel between channels, set theStreamingFactor parameter of the block to the number of channels.

Version History

Introduced in R2008b