Converting the parameters of the digital transfer function filter into second-order sections.
Library
EngeeDSP
Syntax
Function call
sos,g = tf2sos(b,a) — finds a matrix of second-order sections sos with a gain factor g, equivalent to a digital filter represented by vectors of coefficients of the transfer function b and a.
sos,g = tf2sos(b,a,order) — sets the order of the lines in the argument sos.
sos,g = tf2sos(b,a,order,scale) — sets the scaling of the gain coefficients and the numerator of all second-order sections.
sos = tf2sos(___,gain_out) — integrates the overall gain of the system into the first section.
Arguments
Input arguments
#b,a are
the coefficients of the transfer function
+
vectors
Details
The coefficients of the transfer function, set as vectors. Expression of the transfer function in terms of b and a it is written as follows:
Scaling of the gain coefficients and numerator, set using one of the following methods:
"none" — scaling is not applied;
"inf" — infinite rate scaling;
"two" — scaling according to the second norm.
Using infinite norm scaling with order "up" minimizes the chance of overflow in the implementation. Using scaling according to the second norm with the order "down" minimizes peak rounding noise.
Scaling by the infinite norm and by the second norm is suitable only for implementations in direct form II.
The total gain of the system, returned as a real scalar.
If you call the function tf2sos With one output argument, the function will embed the total gain of the system into the first section. So that
Embedding the gain in the first section when scaling a straight-form II structure is not recommended and may lead to unstable scaling. To avoid embedding the gain factor, use tf2sos with two output arguments.
Examples
Mass-spring system
Details
A one-dimensional discrete oscillatory system consists of a single mass , attached to the wall by a spring with a unit elastic constant . The sensor registers acceleration masses with frequency Hz.
Generate 50 sampling periods. Let’s define the sampling interval .
Fs = 5
dt = 1 / Fs
N = 50
t = dt * (0:N-1)
u = [1.0; zeros(N-1)]
The transfer function of the system has an analytical expression:
The system is excited by a single pulse in the positive direction. Let’s calculate the time evolution of the system using the transfer function. Let’s build a response graph.
Let’s calculate the time-dependent acceleration using the representation of the transfer function in the form of second-order sections to filter the input signal. Let’s plot the result graph. The result is the same in both cases.
Function tf2sos uses a four-step algorithm to determine the representation of a second-order section for a system with an input transfer function:
It finds the poles and zeros of the system specified by the parameters b and a.
Uses the function zp2sos, which first groups the zeros and poles into complex conjugate pairs using the function cplxpair. Then zp2sos forms second-order sections by matching pairs of poles and zeros according to the following rules:
Match the poles closest to the unit circle with the zeros closest to these poles.
Match the poles closest to the unit circle with the zeros closest to these poles.
Continue until all poles and zeros are matched.
Function tf2sos groups the real poles into sections where the real poles are closest to them in absolute value. The same rule applies for real zeros.
Arranges the sections according to the proximity of the pairs of poles to the unit circle. Usually tf2sos arranges the sections with the poles closest to the unit circle, the last in the cascade. You can specify functions tf2sos so that it orders the sections in reverse order using the argument order.
Function tf2sos scales sections according to the norm specified in the argument scale. For an arbitrary function The scaling is defined as follows:
where it can be either infinite, or 2. For more information about scaling, see in the sources in the Literature section. The algorithm follows this scaling to minimize overflow or peak rounding noise in fixed-point filter implementations.
Literature
Jackson, L. B. Digital Filters and Signal Processing. 3rd ed. Boston: Kluwer Academic Publishers, 1996.
Mitra, S. K. Digital Signal Processing: A Computer-Based Approach. 3rd ed. New York: McGraw-Hill Higher Education, 2006.
Vaidyanathan, P. P. «Robust Digital Filter Structures.» Handbook for Digital Signal Processing (S. K. Mitra and J. F. Kaiser, eds.). New York: John Wiley & Sons, 1993.