Second-Order Section Filter
Libraries:
DSP System Toolbox /
Filtering /
Filter Implementations
Description
The Second-Order Section Filter block implements a cascade of second-order section (SOS) filters in Simulink®. You can specify the numerator and denominator coefficients of the filter in the block parameters dialog box or through input ports.
Examples
Filter a noisy sinusoidal signal using the Second-Order Section Filter block. Obtain the numerator and denominator coefficients of the SOS filter using the Bandpass IIR Filter Design block.
Tune the frequency specifications of the SOS filter during simulation.
Open and Run Model
Open the secondordersectionfilter model.
The input signal in the model is a sum of two sine waves with the frequencies of 100 Hz and 350 Hz. The sample rate is 1000 Hz and the number of samples in each frame is 1024. The Random Source block adds zero-mean white Gaussian noise with a variance of 1e-4 to the sum of the sine waves.
The Bandpass IIR Filter Design block designs a sixth-order bandpass IIR filter with the first and second 3-dB cutoff frequencies of 0.25
rad/sample and 0.75
rad/sample, respectively. The block generates coefficients as a cascade of second-order sections. Visualize the frequency response of the filter using the Filter Visualizer.
Run the model.
The Second-Order Section Filter block filters the noisy sinusoidal signal. Visualize the original sinusoidal signal and the filtered signal using the Spectrum Analyzer.



Tune Frequency Specifications of SOS Filter
During simulation, you can tune the frequency specifications of the SOS filter by tuning the frequency parameters in the Bandpass IIR Filter Design block. The frequency response of the SOS filter updates accordingly.
Change the second 3-dB cutoff frequency to 0.4
rad/sample in the Bandpass IIR Filter Design block. To change the parameter values more gradually during simulation, select the Smooth tuned filter parameters check box and specify a smoothing factor in the Bandpass IIR Filter Design block dialog box. The smoothing factor determines the speed at which the parameter values change until they match the desired new value. If you specify a smoothing factor of 0, the block does not smooth the parameter and immediately sets the parameter to the new value. As the smoothing factor approaches 1, the number of smoothing operations, and consequently, the number of filter redesigns increase. This example uses a smoothing factor is of 0.6.
When you change the second 3-dB cutoff frequency to 0.4
rad/sample, the second tone of the sinusoidal signal gets attenuated as it no longer falls in the passband region of the filter.


Filter a noisy sinusoidal signal using the Second-Order Section Filter block. Obtain the numerator and denominator coefficients of the SOS filter using the Bandstop IIR Filter Design block.
Tune the frequency specifications of the SOS filter during simulation.
Open and Run Model
Open the secondordersection_bandstopfilter model.
The input signal in the model is a sum of two sine waves with the frequencies of 200 Hz and 400 Hz. The sample rate is 1000 Hz and the number of samples in each frame is 1024. The Random Source block adds zero-mean white Gaussian noise with a variance of 1e-4 to the sum of the sine waves.
The Bandstop IIR Filter Design block designs a sixth-order bandstop IIR filter with the first and second 3-dB cutoff frequencies of 0.2
rad/sample and 0.75
rad/sample, respectively. The block generates coefficients as a cascade of second-order sections. Visualize the frequency response of the filter using Filter Visualizer.
Run the model.
The Second-Order Section Filter block filters the noisy sinusoidal signal. Visualize the original sinusoidal signal and the filtered signal using the Spectrum Analyzer. The first tone is attenuated as it falls in the stopband region of the filter while the second tone remains unaffected as it falls in the passband region of the filter.



Tune Frequency Specification of SOS Filter
During simulation, you can tune the frequency specifications of the SOS filter by tuning the frequency parameters in the Bandstop IIR Filter Design block. The frequency response of the SOS filter updates accordingly.
Change the first 3-dB cutoff frequency to 0.5
rad/sample in the Bandstop IIR Filter Design block. The first tone of the sinusoidal signal now falls in the passband region and is therefore unattenuated.


Ports
Input
Specify the input signal as a vector or a matrix. The input can be a variable-size signal, that is, the frame size of the signal can change during simulation but the number of channels cannot.
If the input is fixed-point, it must be signed only. (since R2026a)
This port is unnamed until you set the Coefficient source
parameter to Input ports.
Data Types: single | double | int8 | int16 | int32 | int64 | fixed point
Complex Number Support: Yes
Specify the numerator coefficients of the SOS filter as a P-by-3 matrix, where P is the number of filter sections. For more details on this input port, see Numerator.
During simulation, you cannot change the size of the coefficients matrix but you can change the coefficient values.
The size and complexity of the Num and Den inputs must be the same. If the Num input is fixed-point, it must be signed only. (since R2026a)
Dependencies
To enable this port, set the Coefficient source parameter
to Input ports.
Data Types: single | double | int8 | int16 | int32 | int64 | fixed point
Complex Number Support: Yes
Specify the denominator coefficients of the SOS filter as a P-by-3 matrix or a P-by-2 matrix, where P is the number of filter sections. For more details on this input port, see Denominator.
When you specify a P-by-3 matrix, the block always assumes the leading denominator coefficient to be 1. If you specify any other value in the first column, the block ignores this value and treats it as 1. If you specify a P-by-2 matrix, the block prepends each row of the matrix with a value of 1.
During simulation, you cannot change the size of the coefficients matrix but you can change the coefficient values.
The size and complexity of the Num and Den inputs must be the same. If the Den input is fixed-point, it must be signed only. (since R2026a)
Dependencies
To enable this port, set the Coefficient source parameter
to Input ports.
Data Types: single | double | int8 | int16 | int32 | int64 | fixed point
Complex Number Support: Yes
Specify the scale values that the block applies before and after each section of the SOS filter as a scalar or a vector with P + 1 elements, where P is the number of filter sections.
If you input a scalar, the block applies this gain value before the first filter
section and sets the gain values before all the other sections to
1. If you specify a vector of P + 1 values, the
block applies each value to a separate section of the filter.
If the g input is fixed-point, it must be signed only. (since R2026a)
Tunable: Yes
Dependencies
To enable this port, set Coefficient source to
Input ports and select the Specify scale
values parameter.
Data Types: single | double | int8 | int16 | int32 | int64 | fixed point
Output
Filtered output, returned as a vector or a matrix. The output has the same size as the input. The output signal is complex if the input signal, numerator coefficients, or the denominator coefficients is complex.
When the input to the block is floating-point, the output data type matches the input data type since floating-point inheritance takes precedence over the fixed-point settings. When the input to the block is fixed-point, the data type of the block output is determined based on the value you specify in the Output data type parameter.
This port is unnamed until you set the Coefficient source
parameter to Input ports.
Data Types: single | double | int8 | int16 | int32 | int64 | fixed point
Complex Number Support: Yes
Parameters
To edit block parameters interactively, use the Property Inspector. From the Simulink Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.
Main Tab
Specify the filter structure as one of these:
Direct form IDirect form I transposedDirect form IIDirect form II transposed
Specify the filter coefficient source as one of these:
Dialog parameters— Set the filter coefficients and scale values through the Numerator, Denominator, and Scale Values parameters in the block dialog box.Input ports— Set the filter coefficients and the scale values through the Num, Den, and g input ports.
Specify the numerator coefficients b of the SOS filter as a P-by-3 matrix, where P is the number of filter sections.
This equation represents the SOS filter in the transfer function form.
where
a is the denominator coefficients matrix. For more details on how to specify this matrix, see Denominator.
k is the row index.
You cannot change the size of this parameter during simulation, but you can change its value.
Dependencies
To enable this parameter, set Coefficient source to
Dialog parameters.
Tunable: Yes
Complex Number Support: Yes
Specify the denominator coefficients a of the SOS filter as a P-by-3 matrix or a P-by-2 matrix, where P is the number of filter sections.
The block algorithm assumes that the value of the leading coefficients is always 1. If the denominator is of size P-by-2, the block algorithm prepends a column of 1s to the denominator to change its size to P-by-3. If the denominator is of size P-by-3 and the elements in the first column do not equal 1, the algorithm ignores the values in the first column and sets them to 1.
This equation represents the SOS filter in the transfer function form.
where
b is the numerator coefficients matrix. For more details on how to specify this matrix, see Numerator.
k is the row index.
You cannot change the size of this parameter during simulation, but you can change its value.
Dependencies
To enable this parameter, set Coefficient source to
Dialog parameters.
Tunable: Yes
Complex Number Support: Yes
Specify if the filter has scale values for each section. When you select this parameter, you can specify the scale values using the Scale Values parameter in the block dialog box or through the g input port.
Specify the scale values that the block applies before and after each section of the SOS filter as a scalar or a vector with P + 1 elements, where P is the number of filter sections.
If you set this property to a scalar, the block applies this gain value before the
first filter section and sets the gain values before all the other sections to
1. If you set this property to a vector of P +
1 values, the block applies each value to a separate section of the filter.
Tunable: Yes
Dependencies
To enable this parameter, set Coefficient source to
Dialog parameters and select the Specify
scale values parameter.
Specify the input processing method as one of these:
Columns as channels (frame based)— The block treats each column of the input as a separate channel.For more information, see What Is Frame-Based Processing?
Elements as channels (sample based)— The block treats each element of the input as a separate channel.For more information, see What Is Sample-Based Processing?
Open the Filter Visualization tool and display the magnitude response of the SOS filter. The response is based on the parameters you select in the block dialog box. To update the magnitude response, modify the parameters in the dialog box and click Apply.
Data Types Tab
Use these parameters to control the fixed-point data type settings in the Second-Order Section Filter block. Selecting appropriate word lengths and scalings for the fixed-point parameters in your model can be challenging. To aid you, an Inherit via internal rule choice is available for the fixed-point data type parameters. For more information on these rules, see Specify Fixed-Point Attributes for Blocks. For more information on how the block uses the fixed-point block data type parameters, see Filter Structures with Fixed-Point Settings. (since R2026a)
Specify the rounding method for fixed-point operations as one of the following:
FloorCeilingConvergentNearestRoundSimplestZero
For more details, see Rounding Modes. The filter
coefficients do not obey this parameter; instead, they always round to
Nearest.
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.
When you set Coefficient source to Dialog
parameters, specify the word- and fraction-length designations of the
filter coefficients (numerator, denominator, and scale values) as one of these:
Inherit: Same word length as input— Word length of the filter coefficients matches that of the input to the block. The block automatically sets the fraction length of the coefficients to the binary point-only 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 filter coefficients, in bits. The block automatically sets the fraction length of the coefficients to the binary point-only scaling that provides the best precision possible given the value and word length of the coefficients.Specify word and fraction lengths— Enter the word length and the fraction length of the coefficients, in bits. Enter separate fraction lengths for the numerator and denominator coefficients, and for the scale values.
See the Filter Structures with Fixed-Point Settings section for illustrations depicting the use of the coefficient data types in this block.
The filter coefficients do not obey the Integer rounding mode
and the Saturate on integer overflow parameters. Instead, they
are always saturated and rounded to Nearest.
Dependencies
To enable this parameter, set Coefficient source to
Dialog parameters.
Specify the word length of the numerator and denominator coefficients and scale values as a positive integer when you specify these parameters in the block dialog box.
Dependencies
To enable this parameter, set:
Coefficient source to
Dialog parametersCoefficient data type to
Specify word and fraction lengthsorSpecify word length
Specify the fraction length of the numerator coefficients as a scalar integer when you specify the coefficients in the block dialog box.
Dependencies
To enable this parameter, set:
Coefficient source to
Dialog parametersCoefficient data type to
Specify word and fraction lengths
Specify the fraction length of the denominator coefficients as a scalar integer when you specify the coefficients in the block dialog box.
Dependencies
To enable this parameter, set:
Coefficient source to
Dialog parametersCoefficient data type to
Specify word and fraction lengths
Specify the fraction length of the scale values as a scalar integer when you specify the scale values in the block dialog box.
Dependencies
To enable this parameter:
Set Coefficient source to
Dialog parametersSelect Specify scale values
Set Coefficient data type to
Specify word and fraction lengths
Specify the section input and output word- and fraction-length designations as one of these:
Inherit: Same as input— Word length and fraction length characteristics of the section input and section output data types match those of the input to the block.Specify word and fraction lengths— Enter the word and fraction lengths of the section input and output data types, in bits.
This data type determines the word and fraction lengths of the fixed-point data type going into each section of a biquadratic filter. See the Filter Structures with Fixed-Point Settings section for illustrations depicting the use of the section input and section output data type in this block.
Dependencies
To enable this parameter, select Specify scale values.
Specify the word length of the section input and section output data types as a positive integer.
Dependencies
To enable this parameter:
Select Specify scale values
Set Section IO data type as
Specify word and fraction lengths
Specify the fraction length of the section input data type as a scalar integer.
Dependencies
To enable this parameter:
Select Specify scale values
Set Section IO data type as
Specify word and fraction lengths
Specify the fraction length of the section output data type as a scalar integer.
Dependencies
To enable this parameter:
Select Specify scale values
Set Section IO data type as
Specify word and fraction lengths
Specify the multiplicand word- and fraction-length designations of a
Direct form I transposed filter structure as one of
these:
Inherit: Inherit via internal rule— Inherit word and fraction lengths of multiplicand data type based on an internal rule.int8,int16,int32,int64,fixdt(1,16,0)— Built-in integer data type
See the Filter Structures with Fixed-Point Settings section for illustrations depicting the use of the multiplicand data type in this block.
Dependencies
To enable this parameter, set Filter structure to
Direct form I transposed.
When you set the filter structure to Direct form II,
specify the state word- and fraction-length designations as one of these:
Inherit: Inherit via internal rule— Inherit word and fraction lengths of state data type based on an internal rule.int8,int16,int32,int64,fixdt(1,16,0)— Built-in integer data type
See the Filter Structures with Fixed-Point Settings section for illustrations depicting the use of the state data type in this block.
Dependencies
To enable this parameter, set Filter structure to
Direct form II.
Specify the numerator and denominator accumulator word- and fraction-length designations as one of these:
Inherit: Inherit via internal rule— Inherit word and fraction lengths of the numerator and denominator accumulator data type based on an internal rule.Specify word and fraction lengths— Enter the word length and fraction length of the numerator and denominator accumulator data type, in bits.
See Multiplication Data Types and the Filter Structures with Fixed-Point Settings section for illustrations depicting the use of the accumulator data type in this block.
Specify the word length of the numerator and denominator accumulator data type as a positive integer.
Dependencies
To enable this parameter, set Accumulator data type to
Specify word and fraction lengths.
Specify the fraction length of the numerator accumulator data type as a scalar integer.
Dependencies
To enable this parameter, set Accumulator data type to
Specify word and fraction lengths.
Specify the fraction length of the denominator accumulator data type as a scalar integer.
Dependencies
To enable this parameter, set Accumulator data type to
Specify word and fraction lengths.
Specify the output word- and fraction-length designations as one of these:
Inherit: Inherit via internal rule— Inherit word and fraction lengths of the output data type based on an internal rule.int8,int16,int32,int64,fixdt(1,16,0)— Built-in integer data type
When the input to the block is floating-point, the output data type matches the input data type since floating-point inheritance takes precedence over the fixed-point settings.
See the Filter Structures with Fixed-Point Settings section for illustrations depicting the use of the output data type in this block.
Select this parameter to prevent the fixed-point tools from overriding the data types you specify in the block dialog box.
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
More About
These diagrams show the filter structures supported by the second-order section filter.
This is the structure of each section in the filter when you set the filter structure to
Direct form I.

This is the structure of the filter with P sections when you specify scale values [g1, g2, …, gP+1].

This is the structure of the filter when you do not specify scale values.

This is the structure of each section in the filter when you set the filter structure to
Direct form I transposed.

This is the structure of the filter with P sections when you specify scale values [g1, g2, …, gP+1].

This is the structure of the filter when you do not specify scale values.

This is the structure of each section in the filter when you set the filter structure to
Direct form II.

This is the structure of the filter with P sections when you specify scale values [g1, g2, …, gP+1].

This is the structure of the filter when you do not specify scale values.

This is the structure of each section in the filter when you set the filter structure to
Direct form II transposed.

This is the structure of the filter with P sections when you specify scale values [g1, g2, …, gP+1].

This is the structure of the filter when you do not specify scale values.

These diagrams show the data types used in the SOS filter when the input is fixed-point. For each structure the filter supports, the data types shown in the diagrams can be set through the respective fixed-point settings.
Here is the structure of each section when you set the filter structure to
Direct form I. This diagram shows the data types when you
input fixed-point signals. The gain operations
b0,
b1,
b2,
a1, and
a2 operate in full precision.

These diagrams show the fixed-point data types between filter sections.
When the data is not optimized:

When you specify scale values to 1:

Here is the structure of each section when you set the filter structure to
Direct form I transposed. This diagram shows the data types
when you input fixed-point signals. The dashed casts are omitted when you set
HasScaleValues to false. The gain operations
b0,
b1,
b2,
a1, and
a2 operate in full precision.

These diagrams show the fixed-point data types between filter sections.
When the data is not optimized:

When you specify scale values to 1:

Here is the structure of each section when you set the filter structure to
Direct form II. This diagram shows the data types when you
input fixed-point signals. The dashed casts are omitted when you set
HasScaleValues to false. The gain operations
b0,
b1,
b2,
a1, and
a2 operate in full precision.

These diagrams show the fixed-point data types between filter sections.
When the data is not optimized:

When you set scale values to 1:

Here is the structure of each section when you set the filter structure to
Direct form II transposed. This diagram shows the data types
when you input fixed-point signals. The gain operations
b0,
b1,
b2,
a1, and
a2 operate in full precision. When you set
HasScaleValues to false, the data type at the
section output is automatically determined by the object algorithm and is not controlled
by the value of the SectionOutputDataType property.

These diagrams show the fixed-point data types between filter sections.
When the data is not optimized:

When you specify scale values to 1:

Symbolic dimensions enable the use of symbols instead of fixed numerical values for dimensions during model development. Wherever you need to specify a signal dimension in the model, you can use symbolic dimensions instead of actual numbers, which provides flexibility for changing the dimensions.
This block supports setting symbolic dimensions for simulation and for code generation. You can specify the dimension information in the block as symbols (variables). These symbols propagate throughout the model during simulation and then go into the generated code. That way, you do not need to change the dimensions in the block each time you update this information.
The ports that support symbolic dimensions are these:
Num— The dimensions must be [P 3], where P is the number of filter sections.Den— The dimensions must be [P M], where M can be2or3.g— The dimension must be P+1.
The block supports symbolic dimensions only in the normal simulation mode.
You must have Simulink Coder™ and Embedded Coder® to use this functionality.
For more information, see Implement Symbolic Dimensions for Array Sizes in Generated Code (Embedded Coder).
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Version History
Introduced in R2023bThe Second-Order Section Filter block supports fixed-point data types in both simulation and in the generated code. If the input is fixed-point, it must be signed only.
For information on the fixed-point properties, see Data Types Tab. For information on the signal flow diagrams for fixed-point inputs, see Filter Structures with Fixed-Point Settings.
The Second-Order Section Filter block supports setting symbolic dimensions for simulation and code generation.
For more information, see Symbolic Dimension Support.
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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)