Biquad Filter
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.
Ports
Input
In — Data input
vector  matrix
Data input to the block, specified as a vector or a matrix. This block supports variablesize 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 fixedpoint, it must be signed fixedpoint with binary point scaling.
This port is unnamed unless you set the Coefficient source to
Input port(s)
.
Data Types: single
 double
 int8
 int16
 int32
 int64
 fixed point
Complex Number Support: Yes
Num — Numerator coefficients
matrix
Numerator coefficients of the biquad filter, specified as a 3byN matrix, where N is the number of biquad filter sections.
If Num is fixedpoint, it must be signed fixedpoint with binary point scaling.
Dependencies
This port appears only when you set the Coefficient source to
Input port(s)
.
Data Types: single
 double
 int8
 int16
 int32
 int64
 fixed point
Den — Denominator coefficients
matrix
Denominator coefficients of the biquad filter, specified as a 2byN matrix, where N is the number of biquad filter sections.
If Den is fixedpoint, it must be signed fixedpoint with binary point scaling.
Dependencies
This port appears only when you set the Coefficient source to
Input port(s)
.
Data Types: single
 double
 int8
 int16
 int32
 int64
 fixed point
g — Scale values
row vector
Scale values of the biquad filter, specified as a 1by(N+1) vector, where N is the number of biquad filter sections.
If g is fixedpoint, it must be signed fixedpoint with binary point scaling.
Dependencies
This port appears only when you set the Coefficient source to
Input port(s)
.
Data Types: single
 double
 int8
 int16
 int32
 int64
 fixed point
Output
Out — Filtered output
vector  matrix
Filtered output, returned as a vector or a matrix.
The output dimensions always equal the dimensions of the input signal. The output of
this block numerically matches the outputs of the dsp.BiquadFilter
System object™.
If Out is fixedpoint, it must be signed fixedpoint with binary point scaling.
This port is unnamed unless you set the Coefficient source to
Input port(s)
.
Data Types: single
 double
 int8
 int16
 int32
 int64
 fixed point
Complex Number Support: Yes
Parameters
Main Tab
Coefficient source — Mode of operation
Dialog parameters
(default)  Input port(s)
 Filter object
The Biquad Filter block can operate in three different modes:
Dialog parameters
— Enter information about the filter, such as structure and coefficients, in the block mask.Input port(s)
— Enter information about the filter structure in the block mask using the Filter structure parameter. The filter coefficients come into the block through additional input ports that appear on the block icon:Num
— Specify numerator coefficients.Den
— Specify denominator coefficients.g
— Specify scale values.
The block assumes the first denominator coefficient of each section to be 1. This configuration applies when Coefficient source is set to
Input port(s)
and Scale values mode is set toSpecify via input port (g)
.Filter object
— Specify the filter using adsp.BiquadFilter
System object.
Filter — Name of filter object
BQF
(default)  dsp.BiquadFilter
System object
name
dsp.BiquadFilter
System objectSpecify the name of the discretetime 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 to
Filter object
.
Filter structure — Filter structure
Direct form II transposed
(default)  Direct form I
 Direct form I transposed
 Direct form II
Specify the filter structure.
Dependencies
This parameter is visible only when Coefficient source is set to
Dialog parameters
or Input
port(s)
.
SOS Matrix (Mx6) — SOS matrix
[1 0.3 0.4 1 0.1 0.2]
(default)  Mby6 matrix
Specify an Mby6 matrix, where M is the number of sections in the secondorder section filter. Each row of the SOS matrix contains the numerator and denominator coefficients (b_{ik} and a_{ik}) of the corresponding section in the filter.
$$\left[\begin{array}{cccccc}{b}_{01}& {b}_{11}& {b}_{21}& {a}_{01}& {a}_{11}& {a}_{21}\\ {b}_{02}& {b}_{12}& {b}_{22}& {a}_{02}& {a}_{12}& {a}_{22}\\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ {b}_{0M}& {b}_{1M}& {b}_{2M}& {a}_{0M}& {a}_{1M}& {a}_{2M}\end{array}\right]$$
The leading denominator coefficients [a_{01} a_{02} ... a_{0N}] 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 statespace or transfer function description of your
filter into the secondorder section description used by this block.
Dependencies
This parameter is visible only when Coefficient source is set to
Dialog parameters
.
Scale values — Scale values
1
(default)  scalar  vector
Specify scale values to be used between SOS sections. You can specify a realvalued scalar or a vector of length M+1:
When you enter a scalar, the value specifies the gain value before the first section of the secondorder filter. The rest of the gain values default to 1.
When you enter a vector of M+1 values, each value specifies a separate section of the filter. For example, the first element is the first gain value, the second element is the second gain value, and so on.
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 fixedpoint cases when there are unity scale values, selecting this parameter also omits certain casts. Refer to the FixedPoint section for more information.
Dependencies
This parameter is visible only when Coefficient source is set to
Dialog parameters
.
Initial conditions — Initial conditions
0
(default)  scalar  vector
Specify the initial conditions of the filter states when Filter
structure is set to Direct form II
or
Direct 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  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:

Dependencies
This parameter is only visible when Coefficient source is set to
Dialog parameters
or Input port(s)
and the Filter structure is set to Direct form
II
or Direct form II transposed
.
Initial conditions on zeros side — Initial conditions on zeros side
0
(default)  scalar  vector
Specify the initial conditions for the filter states on the side of the filter structure
with the zeros (b_{0},
b_{1}, b_{2},
…). This parameter applies only when Filter structure is set to
Direct 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  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:

Dependencies
This parameter is visible only when Coefficient source is set to
Dialog parameters
or Input port(s)
and the Filter structure is set to Direct form
I
or Direct form I transposed
.
Initial conditions on poles side — Initial conditions on poles side
0
(default)  scalar  vector
Specify the initial conditions for the filter states on the side of the filter structure
with the poles (a_{1},
a_{2}, ...). This parameter applies only when
Filter structure is set to Direct 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 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  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:

Dependencies
This parameter is visible only when Coefficient source is set to
Dialog parameters
or Input port(s)
and the Filter structure is set to Direct form
I
or Direct form I transposed
.
Scale values mode — Mode to specify scale values
Specify via input port (g)
(default)  Assume all are unity and optimize
Choose how to specify the scale values to use between filter sections. When you select
Specify via input port (g)
, you enter the scale values as a 2D
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 to
Input port(s)
.
Action when the a0 values of the SOS matrix are not one — Action when a0 values of SOS matrix are not one
Warning
(default)  None
 Error
Specify the action the block should perform when the SOS matrix
a_{0j} values do not equal one. The action can be
Warning
, Error
, or
None
.
When you choose None
, the leading coefficients
a_{0j} 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 to
Dialog parameters
.
Optimize unity scale values — Optimize unity scale values
on
(default)  off
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 fixedpoint cases when there are unity scale values, selecting this parameter also omits certain casts. See the FixedPoint section for more information.
Dependencies
This parameter is visible only when Coefficient source is set to
Dialog parameters
.
Input processing — Input processing
Columns as channels (frame based)
(default)  Elements as channels (sample based)
Specify how the block should process the input. If the input is an MbyN matrix, you can set this parameter to:
Columns as channels (frame based)
(default) — The block treats each column as a separate channel. In this mode, the block creates M instances of the same filter, each with its own independent state buffer. Each of the M filters process N input samples at every Simulink time step.Elements as channels (sample based)
— The block treats each element as a separate channel. In this mode, the block creates MN instances of the same filter, each with its own independent state buffer. Each filter processes one input sample at every Simulink time step.
View Filter Response — View filter response
button
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 the Apply button before using the View Filter Response button.
Data Types Tab
Note
This tab appears only when you set Coefficient source to either
Dialog 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.
Rounding mode — Rounding mode
Floor
(default)  Ceiling
 Convergent
 Nearest
 Round
 Simplest
 Zero
Specify the rounding mode for fixedpoint operations.
For more details, see rounding mode. The filter
coefficients do not obey this parameter; instead, they always round to
Nearest
.
Saturate on integer overflow — Method of overflow action
off
(default)  on
When you select this parameter, the block saturates the result of its fixedpoint
operation. When you clear this parameter, the block wraps the result of its fixedpoint
operation. For details on saturate
and wrap
, see overflow mode for fixedpoint operations.
The filter coefficients are always saturated and do not obey this parameter.
Section input — Section input data type
Same as input
(default)  Binary point scaling
Choose how you specify the word and fraction lengths of the fixedpoint data type going into each section of a biquadratic filter. See the FixedPoint section for illustrations depicting the use of the section input data type in this block. When you select:
Same as input
— Word length and fraction length characteristics of the Section input data type match those of the input to the block.Binary point scaling
— Enter the word and fraction lengths of the section input, in bits.
Section output — Section output data type
Same as section input
(default)  Binary point scaling
Choose how you specify the word and fraction lengths of the fixedpoint data type coming out of each section of a biquadratic filter. See the FixedPoint section for illustrations depicting the use of the section output data type in this block. When you select:
Same as section input
— Word length and fraction length characteristics of the Section output data type match with those of the input to the block.Binary point scaling
— Enter the word and fraction lengths of the section output, in bits.
Multiplicand — Multiplicand data type
Same as output
(default)  Binary point scaling
Choose how you specify the word and fraction lengths of the multiplicand data type of a
Direct form I transposed
filter structure. See the FixedPoint section for illustrations
depicting the use of the multiplicand data type in this block.
When you select:
Same as output
— Word length and fraction length characteristics of the Multiplicand data type match with those of the output of the block.Binary point scaling
— Enter the word length and the fraction length of the multiplicand, in bits.
Dependencies
This parameter is visible only when the Filter structure parameter
is set to Direct form I transposed
.
Coefficients — Coefficients data type
Same word length as input
(default)  Specify word length
 Binary point scaling
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 FixedPoint section for illustrations
depicting the use of the coefficient data types in this block. When you select:
Same word length as input
— Word length of the filter coefficients matches that of the input to the block. In this mode, the block automatically sets the fraction length of the coefficients to the binary pointonly scaling that provides the best precision possible given the value and word length of the coefficients.Specify word length
— Enter the word length of the coefficients, in bits. In this mode, the block automatically sets the fraction length of the coefficients to the binary pointonly scaling that provides the best precision possible given the value and word length of the coefficients.Binary point scaling
— Enter the word length and the fraction length of the coefficients, in bits. If applicable, enter separate fraction lengths for the numerator and denominator coefficients.
The filter coefficients do not obey the Rounding mode and the
Overflow mode parameters; instead, they are always saturated and
rounded to Nearest
.
Dependencies
This parameter is visible only when Coefficient source is set to
Dialog parameters
.
Product output — Product output data type
Same as input
(default)  Inherit via internal rule
 Binary point scaling
Specify how to designate the product output word and fraction lengths. See Multiplication Data Types and the FixedPoint section for illustrations depicting the use of the product output data type in this block. When you select:
Same as input
— Product output word length and fraction length characteristics match those of the input to the block.Inherit via internal rule
— Product output word length and fraction lengths are computed based on fullprecision rules. These rules prevent quantization from occurring within the block. Bits are added, as needed, so that no roundoff or overflow occurs. For more details, see Inherit via Internal Rule.Binary point scaling
— Enter the word length and the fraction length of the product output, in bits. If applicable, enter separate fraction lengths for the numerator and denominator product output data type.
Accumulator — Accumulator data type
Same as product output
(default)  Same as input
 Binary point scaling
Specify how to designate the accumulator word and fraction lengths. See Multiplication Data Types and the FixedPoint section for illustrations depicting the use of the accumulator data type in this block. When you select:
Same as input
— Accumulator word and fraction length characteristics match those of the input to the block.Same as product output
— Accumulator word and fraction length characteristics match those of the product output.Binary point scaling
— Enter the word length and the fraction length of the accumulator, in bits. If applicable, enter separate fraction lengths for the numerator and denominator accumulator data type.
States — States data type
Same as accumulator
(default)  Same as input
 Binary point scaling
Specify how to designate the state word and fraction lengths when Coefficient
source is set to Dialog parameters
. See the FixedPoint section for illustrations
depicting the use of the state data type in this block.
When you select:
Same as input
— State word and fraction length characteristics match those of the input to the block.Same as accumulator
— State word and fraction length characteristics match those of the accumulator.Binary point scaling
— Enter the word length and the fraction length of the state, in bits. If applicable, enter separate fraction lengths for the numerator and denominator state data type.
Dependencies
This parameter is visible only when Filter structure is set to
Direct form II
or Direct form II
transposed
.
Output — Output data type
Same as accumulator
(default)  Same as input
 Binary point scaling
Choose how you specify the output word length and fraction length. See the FixedPoint section for illustrations depicting the use of the output data type in this block. When you select:
Same as input
— Output word and fraction length characteristics match those of the input to the block.Same as accumulator
— Output word and fraction length characteristics match those of the accumulator.Binary point scaling
— Enter the word length and the fraction length of the output, in bits.
Lock data type settings against changes by the fixedpoint tools — Lock data type settings
off
(default)  on
Select this parameter to prevent the fixedpoint tools from overriding the data types you specify on the block mask.
Block Characteristics
Data Types 

Direct Feedthrough 

Multidimensional Signals 

VariableSize Signals 

ZeroCrossing Detection 

More About
FixedPoint
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 fixedpoint signals. You can set the data types shown in these diagrams in the block dialog box.
The following diagram shows the data types for one section of the filter for fixedpoint signals.
The following diagrams show the fixedpoint data types between filter sections.
When the data is not optimized:
When you select Optimize unity scale values and scale values equal 1:
The following diagram shows the data types for one section of the filter for fixedpoint signals.
The dashed casts are omitted when Optimize unity scale values is selected and scale values equal one.
The following diagrams show the fixedpoint data types between filter sections.
When the data is not optimized:
When you select Optimize unity scale values and scale values equal 1:
The following diagram shows the data types for one section of the filter for fixedpoint signals.
The dashed casts are omitted when Optimize unity scale values is selected and scale values equal one.
The following diagrams show the fixedpoint data types between filter sections.
When the data is not optimized:
When you select Optimize unity scale values and scale values equal 1:
The following diagram shows the data types for one section of the filter for fixedpoint signals.
The following diagrams show the fixedpoint data types between filter sections.
When the data is not optimized:
When you select Optimize unity scale values and scale values equal 1:
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
Note
For an HDLoptimized biquad filter architecture with hardwarefriendly 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 addmultiply 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 Toolbox Biquad Filter block into a For Each subsystem.
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
HDL Coder supports programmable filters for Biquad Filter blocks.
On the filter block mask, set Coefficient source to Input port(s).
Connect vector signals to the Num and Den coefficient ports. Matrix input signals are not supported for HDL code generation. You must use one Biquad Filter block for each secondorder section in your filter. For a filter with M secondorder sections, use a series of M Biquad Filter blocks, each with an input Num that is a 3by1 vector and an input Den that is a 2by1 vector.
The following limitations apply to the HDL optimizations for a programmable Biquad Filter block:
Fully serial and partly serial architectures are not supported. Architecture must be set to
Fully parallel
.Canonical signed digit (CSD) multiplier optimization is not supported.
CoeffMultipliers
must be set tomultiplier
.
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 the StreamingFactor parameter of the subsystem to the number of channels. See the Streaming section of Subsystem Optimizations for Filters (HDL Coder).
To use blocklevel optimizations to reduce hardware resources, select a serial
Architecture. Then set either NumMultipliers
or
Folding Factor
. See HDL Filter Properties.
When you select a serial architecture, set Filter structure to
Direct form I
or Direct form II
. The
direct form transposed structures are not supported with serial architectures.
When you use AddPipelineRegisters, registers are placed based on the filter structure. The pipeline register placement determines the latency.
Filter Structure  Pipeline Register Placement  Latency (Clock Cycles) 

Any  Pipeline registers are added between the filter sections.  NS1 , where NS is number of sections. 
This block can participate in subsystemlevel optimizations such as sharing, streaming,
and pipelining. For the block to participate in subsystemlevel optimizations, set
Architecture to Fully parallel
. See Subsystem Optimizations for Filters (HDL Coder).
AddPipelineRegisters  Insert a pipeline register between stages of computation in a filter. See also AddPipelineRegisters (HDL Coder). 
CoeffMultipliers  Specify the use of canonical signed digit (CSD) optimization to decrease filter area
by replacing coefficient multipliers with shiftandadd logic. When you choose a fully
parallel filter implementation, you can set CoeffMultipliers to

FoldingFactor  Specify a serial implementation of an IIR SOS filter by the number of cycles it takes to generate the result. See also FoldingFactor (HDL Coder). 
NumMultipliers  Specify a serial implementation of an IIR SOS filter by the number of hardware multipliers that are generated. See also NumMultipliers (HDL Coder). 
For more details about HDL filter properties, see HDL Filter Block Properties (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 is

InputPipeline  Number of input pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is

OutputPipeline  Number of output pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is

Frame input is not supported for HDL code generation. For framebased input, use the Biquad Filter (DSP HDL Toolbox) block.
You must set Initial conditions to
0
. HDL code generation is not supported for nonzero initial states.You must select Optimize unity scale values.
You cannot generate HDL for this block inside a Resettable Synchronous Subsystem (HDL Coder).
FixedPoint Conversion
Design and simulate fixedpoint systems using FixedPoint Designer™.
If the input is fixed point, it must be a signed integer or a signed fixed point value with a poweroftwo slope and zero bias.
Version History
Introduced in R2008b
See Also
Objects
Blocks
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)