| Filter Design Toolbox™ | ![]() |
Refer to dfilt.df2tsos in Signal Processing Toolbox™ documentation.
hd = dfilt.df2sos(s) returns a discrete-time, second-order section, direct-form II, transposed filter object hd, with coefficients given in the matrix s.
Make this filter a fixed-point or single-precision filter by changing the value of the Arithmetic property for the filter hd as follows:
To change to single-precision filtering, enter
set(hd,'arithmetic','single');
To change to fixed-point filtering, enter
set(hd,'arithmetic','fixed');
For more information about the property Arithmetic, refer to Arithmetic.
hd = dfilt.df2tsos(b1,a1,b2,a2,...) returns a discrete-time, second-order section, direct-form II, transposed filter object hd, with coefficients for the first section given in the b1 and a1 vectors, for the second section given in the b2 and a2 vectors, etc.
hd = dfilt.df2tsos(...,g) includes a gain vector g. The elements of g are the gains for each section. The maximum length of g is the number of sections plus one. If g is not specified, all gains default to one.
hd = dfilt.df2tsos returns a default, discrete-time, second-order section, direct-form II, transposed filter object, hd. This filter passes the input through to the output unchanged.
Note The leading coefficient of the denominator a(1) cannot be 0. To allow you to change the arithmetic setting to fixed or single, a(1) must be equal to 1. |
The figure below shows the signal flow for the second-order section transposed direct-form II filter implemented by dfilt.dftsos. To help you see how the filter processes the coefficients, input, and states of the filter, as well as numerical operations, the figure includes the locations of the formatting objects within the signal flow.

To help you understand where and how the filter performs fixed-point arithmetic during filtering, the figure shows various labels associated with data and functional elements in the filter. The following table describes each label in the signal flow and relates the label to the filter properties that are associated with it.
The labels use a common format — a prefix followed by the letters "frmt" (format). In this use, "frmt" indicates the word length and fraction length associated with the filter part referred to by the prefix.
For example, the InputFrmt label refers to the word length and fraction length used to interpret the data input to the filter. The format properties InputWordLength and InputFracLength (as shown in the table) store the word length and the fraction length in bits. Or consider NumFrmt, which refers to the word and fraction lengths (CoeffWordLength, NumFracLength) associated with representing filter numerator coefficients.
Signal Flow Label | Corresponding Word Length Property | Corresponding Fraction Length Property | Related Properties |
|---|---|---|---|
DenAccumFrmt | AccumWordLength | DenAccumFracLength | AccumMode, CastBeforeSum |
DenFrmt | CoeffWordLength | DenFracLength | CoeffAutoScale, Signed, Denominator |
DenProdFrmt | CoeffWordLength | DenProdFracLength | ProductMode, ProductWordLength |
InputFrmt | InputWordLength | InputFracLength | None |
NumAccumFrmt | AccumWordLength | NumAccumFracLength | AccumMode, CastBeforeSum |
NumFrmt | CoeffWordLength | NumFracLength | CoeffAutoScale, SignedNumerator |
NumProdFrmt | CoeffWordLength | NumProdFracLength | ProductWordLength, ProductMode |
OutputFrmt | OutputWordLength | OutputFracLength | OutputMode |
ScaleValueFrmt | CoeffWordLength | ScaleValueFracLength | CoeffAutoScale, , ScaleValues |
StageInputFrmt | StageInputWordLength | StageInputFracLength | StageInputAutoScale |
StageOutputFrmt | StageOutputWordLength | StageOutputFracLength | StageOutputAutoScale |
StateFrmt | StateWordLength | StateFracLength | States |
Most important is the label position in the diagram, which identifies where the format applies.
As one example, look at the label DenProdFrmt, which always follows a denominator coefficient multiplication element in the signal flow. The label indicates that denominator coefficients leave the multiplication element with the word length and fraction length associated with product operations that include denominator coefficients. From reviewing the table, you see that the DenProdFrmt refers to the properties ProdWordLength, ProductMode and DenProdFracLength that fully define the denominator format after multiply (or product) operations.
In this table you see the properties associated with second-order section implementation of transposed direct-form II dfilt objects.
Note The table lists all the properties that a filter can have. Many of the properties are dynamic, meaning they exist only in response to the settings of other properties. You might not see all of the listed properties all the time. To view all the properties for a filter at any time, use get(hd) where hd is a filter. |
For further information about the properties of this filter or any dfilt object, refer to Fixed-Point Filter Properties.
Property Name | Brief Description |
|---|---|
AccumMode | Determines how the accumulator outputs stored values. Choose from full precision (FullPrecision), or whether to keep the most significant bits (KeepMSB) or least significant bits (KeepLSB) when output results need shorter word length than the accumulator supports. To let you set the word length and the precision (the fraction length) used by the output from the accumulator, set AccumMode to SpecifyPrecision. |
AccumWordLength | Sets the word length used to store data in the accumulator/buffer. |
Arithmetic | Defines the arithmetic the filter uses. Gives you the options double, single, and fixed. In short, this property defines the operating mode for your filter. |
CastBeforeSum | Specifies whether to cast numeric data to the appropriate accumulator format (as shown in the signal flow diagrams) before performing sum operations. |
CoeffAutoScale | Specifies whether the filter automatically chooses the proper fraction length to represent filter coefficients without overflowing. Turning this off by setting the value to false enables you to change the NumFracLength and DenFracLength properties to specify the precision used. |
CoeffWordLength | Specifies the word length to apply to filter coefficients. |
DenAccumFracLength | Specifies the fraction length used to interpret data in the accumulator used to hold the results of sum operations. You can change the value for this property when you set AccumMode to SpecifyPrecision. |
DenFracLength | Set the fraction length the filter uses to interpret denominator coefficients. DenFracLength is always available, but it is read-only until you set CoeffAutoScale to false. |
DenProdFracLength | Specifies how the filter algorithm interprets the results of product operations involving denominator coefficients. You can change this property value when you set ProductMode to SpecifyPrecision. |
FilterStructure | Describes the signal flow for the filter object, including all of the active elements that perform operations during filtering — gains, delays, sums, products, and input/output. |
InputFracLength | Specifies the fraction length the filter uses to interpret input data. |
InputWordLength | Specifies the word length applied to interpret input data. |
NumAccumFracLength | Specifies how the filter algorithm interprets the results of addition operations involving numerator coefficients. You can change the value of this property after you set AccumMode to SpecifyPrecision. |
NumFracLength | Sets the fraction length used to interpret the value of numerator coefficients. |
NumProdFracLength | Specifies how the filter algorithm interprets the results of product operations involving numerator coefficients. Available to be changed when you set ProductMode to SpecifyPrecision. |
OutputFracLength | Determines how the filter interprets the filter output data. You can change the value of OutputFracLength when you set OutputMode to SpecifyPrecision. |
OutputMode | Sets the mode the filter uses to scale the filtered data for output. You have the following choices:
|
OutputWordLength | Determines the word length used for the output data. |
OverflowMode | Sets the mode used to respond to overflow conditions in fixed-point arithmetic. Choose from either saturate (limit the output to the largest positive or negative representable value) or wrap (set overflowing values to the nearest representable value using modular arithmetic). The choice you make affects only the accumulator and output arithmetic. Coefficient and input arithmetic always saturates. Finally, products never overflow — they maintain full precision. |
ProductMode | Determines how the filter handles the output of product operations. Choose from full precision (FullPrecision), or whether to keep the most significant bit (KeepMSB) or least significant bit (KeepLSB) in the result when you need to shorten the data words. For you to be able to set the precision (the fraction length) used by the output from the multiplies, you set ProductMode to SpecifyPrecision. |
ProductWordLength | Specifies the word length to use for multiplication operation results. This property becomes writable (you can change the value) when you set ProductMode to SpecifyPrecision. |
PersistentMemory | Specifies whether to reset the filter states and memory before each filtering operation. Lets you decide whether your filter retains states from previous filtering runs. False is the default setting. |
RoundMode | Sets the mode the filter uses to quantize numeric values when the values lie between representable values for the data format (word and fraction lengths).
The choice you make affects only the accumulator and output arithmetic. Coefficient and input arithmetic always round. Finally, products never overflow — they maintain full precision. |
ScaleValueFracLength | Scale values work with SOS filters. Setting this property controls how your filter interprets the scale values by setting the fraction length. Only available when you disable AutoScaleMode by setting it to false. |
Scaling for the filter objects in SOS filters. | |
Signed | Specifies whether the filter uses signed or unsigned fixed-point coefficients. Only coefficients reflect this property setting. |
SosMatrix | Holds the filter coefficients as property values — you use set and get to modify them. Displays the matrix in the format [sections x coefficients/section data type]. A [15x6 double] SOS matrix represents a filter with 6 coefficients per section and 15 sections, using data type double to represent the coefficients. |
StageInputFracLength | Lets you set the fraction length for stage inputs in SOS filters, if you set StageInputAutoScale to false. |
StageInputWordLength | Lets you set the word length for stage inputs in SOS filters, if you set StageInputAutoScale to false. |
StageOutputAutoScale | Tells the filter whether to set the stage output data format to minimize the occurrence of overflow conditions. |
StageOutputFracLength | Lets you set the fraction length for stage outputs in SOS filters, if you set StageOutputAutoScale to off. |
StageOutputWordLength | Lets you set the word length for stage outputs in SOS filters, if you set StageOutputAutoScale to false. |
StateAutoScale | Setting autoscaling for filter states to true reduces the possibility of overflows occurring during fixed-point operations. Set to false, StateAutoScale lets the filter select the fraction length to limit the overflow potential. |
StateFracLength | When you set StateAutoScale to false, you enable the StateFracLength property that lets you set the fraction length applied to interpret the filter states. |
States | This property contains the filter states before, during, and after filter operations. States act as filter memory between filtering runs or sessions. |
StateWordLength | Sets the word length used to represent the filter states. |
Construct a second-order section Butterworth filter for fixed-point filtering. Start by specifying a Butterworth filter, and then convert the filter to second-order sections, with the following code:
[z,p,k] = butter(30,0.5);
[s,g] = zp2sos(z,p,k);
hd = dfilt.df2tsos(s,g)
hd =
FilterStructure: [1x48 char]
Arithmetic: 'double'
sosMatrix: [15x6 double]
ScaleValues: [16x1 double]
PersistentMemory: false
States: [2x15 double]Now change the setting of the property Arithmetic to convert the filter to fixed-point operation.
hd.arithmetic='fixed'
hd =
FilterStructure: [1x48 char]
Arithmetic: 'fixed'
sosMatrix: [15x6 double]
ScaleValues: [16x1 double]
PersistentMemory: false
States: [1x1 embedded.fi]
CoeffWordLength: 16
CoeffAutoScale: true
Signed: true
InputWordLength: 16
InputFracLength: 15
StageInputWordLength: 16
StageInputFracLength: 15
StageOutputWordLength: 16
StageOutputFracLength: 15
OutputWordLength: 16
OutputMode: 'AvoidOverflow'
StateWordLength: 16
StateAutoScale: true
ProductMode: 'FullPrecision'
AccumMode: 'KeepMSB'
AccumWordLength: 40
CastBeforeSum: true
RoundMode: 'convergent'
OverflowMode: 'wrap' dfilt, dfilt.df1sos, dfilt.df1tsos, dfilt.df2sos
![]() | dfilt.df2t | dfilt.dfasymfir | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |