SecondOrder Section Filter
Libraries:
DSP System Toolbox /
Filtering /
Filter Implementations
Description
The SecondOrder Section Filter block implements a cascade of secondorder 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 Noisy Signal Using SecondOrder Section (SOS) Bandpass Filter in Simulink
Filter a noisy sinusoidal signal using the SecondOrder 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 by clicking the Open Model button.
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 zeromean white Gaussian noise with a variance of 1e4 to the sum of the sine waves.
The Bandpass IIR Filter Design block designs a sixthorder bandpass IIR filter with the first and second 3dB cutoff frequencies of 0.25 rad/sample and 0.75 rad/sample, respectively. The block generates coefficients as a cascade of secondorder sections. Visualize the frequency response of the filter using the Filter Visualizer.
Run the model.
The SecondOrder 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 3dB 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 3dB 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 Noisy Signal Using SecondOrder Section (SOS) Bandstop Filter in Simulink
Filter a noisy sinusoidal signal using the SecondOrder 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 by clicking the Open Model button.
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 zeromean white Gaussian noise with a variance of 1e4 to the sum of the sine waves.
The Bandstop IIR Filter Design block designs a sixthorder bandstop IIR filter with the first and second 3dB cutoff frequencies of 0.2 rad/sample and 0.75 rad/sample, respectively. The block generates coefficients as a cascade of secondorder sections. Visualize the frequency response of the filter using Filter Visualizer.
Run the model.
The SecondOrder 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 3dB 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
In — Input signal
vector  matrix
Specify the input signal as a vector or a matrix. The input can be a variablesize signal, that is, the frame size of the signal can change during simulation but the number of channels cannot.
This port is unnamed until you set the Coefficient source
parameter to Input ports
.
Data Types: single
 double
Complex Number Support: Yes
Num — Numerator coefficients
Pby3 matrix
Specify the numerator coefficients of the SOS filter as a Pby3 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.
Dependencies
To enable this port, set the Coefficient source parameter
to Input ports
.
Data Types: single
 double
Complex Number Support: Yes
Den — Denominator coefficients
Pby3 matrix  Pby2 matrix
Specify the denominator coefficients of the SOS filter as a Pby3 matrix or a Pby2 matrix, where P is the number of filter sections. For more details on this input port, see Denominator.
When you specify a Pby3 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 Pby2 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.
Dependencies
To enable this port, set the Coefficient source parameter
to Input ports
.
Data Types: single
 double
Complex Number Support: Yes
g — Scale values for each secondorder section
scalar  vector
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.
Tunable: Yes
Dependencies
To enable this port, set Coefficient source to
Input ports
and select the Specify scale
values parameter.
Data Types: single
 double
Output
Out — Filtered output
vector  matrix
Filtered output, returned as a vector or a matrix. The output has the same size and data type as the input. The output signal is complex if the input signal, numerator coefficients, or the denominator coefficients is complex.
This port is unnamed until you set the Coefficient source
parameter to Input ports
.
Data Types: single
 double
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.
Filter structure — Filter structure
Direct form II transposed
(default)  Direct form I
 Direct form I transposed
 Direct form II
Specify the filter structure as one of these:
Direct form I
Direct form I transposed
Direct form II
Direct form II transposed
Coefficient source — Filter coefficient source
Dialog parameters
(default)  Input ports
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.
Numerator — Numerator coefficients of filter
[0.0975 0.195 0.0975
] (default)  Pby3 matrix
Specify the numerator coefficients b of the SOS filter as a Pby3 matrix, where P is the number of filter sections.
$$b=\left[\begin{array}{ccc}{b}_{01}& {b}_{11}& {b}_{21}\\ {b}_{02}& {b}_{12}& {b}_{22}\\ \vdots & \vdots & \vdots \\ {b}_{0P}& {b}_{1P}& {b}_{2P}\end{array}\right]$$
This equation represents the SOS filter in the transfer function form.
$$H(z)={\displaystyle \prod _{k=1}^{P}{H}_{k}}(z)={\displaystyle \prod _{k=1}^{P}\frac{{b}_{0k}+{b}_{1k}{z}^{1}+{b}_{2k}{z}^{2}}{{a}_{0k}+{a}_{1k}{z}^{1}+{a}_{2k}{z}^{2}}},$$
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.
Tunable: Yes
Dependencies
To enable this parameter, set Coefficient source to
Dialog parameters
.
Data Types: single
 double
Complex Number Support: Yes
Denominator — Denominator coefficients of filter
[1 0.9428 0.3333
] (default)  Pby3 matrix  Pby2 matrix
Specify the denominator coefficients a of the SOS filter as a Pby3 matrix or a Pby2 matrix, where P is the number of filter sections.
$$a=\left[\begin{array}{ccc}{a}_{01}& {a}_{11}& {a}_{21}\\ {a}_{02}& {a}_{12}& {a}_{22}\\ \vdots & \vdots & \vdots \\ {a}_{0P}& {a}_{1P}& {a}_{2P}\end{array}\right]$$
The block algorithm assumes that the value of the leading coefficients is always 1. If the denominator is of size Pby2, the block algorithm prepends a column of 1s to the denominator to change its size to Pby3. If the denominator is of size Pby3 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.
$$H(z)={\displaystyle \prod _{k=1}^{P}{H}_{k}}(z)={\displaystyle \prod _{k=1}^{P}\frac{{b}_{0k}+{b}_{1k}{z}^{1}+{b}_{2k}{z}^{2}}{{a}_{0k}+{a}_{1k}{z}^{1}+{a}_{2k}{z}^{2}}},$$
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.
Tunable: Yes
Dependencies
To enable this parameter, set Coefficient source to
Dialog parameters
.
Data Types: single
 double
Complex Number Support: Yes
Specify scale values — Specify if filter has scale values for each section
off
(default)  on
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.
Scale Values — Scale values for each secondorder section
[1 1
] (default)  scalar  vector
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.
Data Types: single
 double
Input processing — Method to process input
Columns as channels (frame based)
(default)  Elements as channels (sample based)
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 FrameBased Processing?
Elements as channels (sample based)
–– The block treats each element of the input as a separate channel.For more information, see What Is SampleBased Processing?
View Filter Response — View filter response
button
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.
Block Characteristics
Data Types 

Direct Feedthrough 

Multidimensional Signals 

VariableSize Signals 

ZeroCrossing Detection 

More About
Filter Structures
These diagrams show the filter structures supported by the secondorder 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 [g_{1}, g_{2}, …, g_{P+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 [g_{1}, g_{2}, …, g_{P+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 [g_{1}, g_{2}, …, g_{P+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 [g_{1}, g_{2}, …, g_{P+1}].
This is the structure of the filter when you do not specify scale values.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2023b
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)