Engee documentation

tf2sos

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:

Типы данных

Float64

# order — the order of the rows

+ "up" (default) | "down"

Details

The row order is set using one of the following methods:

  • "up" — arrange the sections so that the first line of the argument sos it contained the poles furthest from the unit circle;

  • "down" — arrange the sections so that the first line of the argument sos it contained the poles closest to the unit circle.

Типы данных

String

# scale — scaling of the gain and numerator

+ "none" (by default) | "inf" | "two"

Details

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.
Типы данных

String

# gain_out — number of output variables

+ false (by default) | true

Details

The number of output variables, set as:

  • false — the function returns a single variable sos;

  • true — the function returns a tuple of two variables (sos,g).

Типы данных

Bool

Output arguments

# sos — representation of the second-order section

+ the matrix

Details

The representation of the second-order section, returned as a matrix. Argument sos — this is a matrix of size

the rows of which contain the coefficients of the numerator and denominator and second-order sections of the function :

# g is the total gain of the system

+ scalar

Details

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.

tf2sos

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.

import EngeeDSP.Functions: filter

bf = [1.0, -(1+cos(dt)), cos(dt)]
af = [1.0, -2*cos(dt), 1.0]
yf = filter(bf, af, u)
plot(t, yf,
     seriestype = :stem,
     marker = :circle,
     markerstrokecolor = 1,
     markercolor = :white,
     markersize = 5,
     xlabel = "t", legend = false)

tf2sos 1

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.

import EngeeDSP.Functions: tf2sos, sosfilt

sos = tf2sos(bf, af)
yt = sosfilt(sos, u)
plot(t, yt, seriestype = :stem, marker = :circle, legend = false)

tf2sos 2

Algorithms

Function tf2sos uses a four-step algorithm to determine the representation of a second-order section for a system with an input transfer function:

  1. It finds the poles and zeros of the system specified by the parameters b and a.

  2. 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:

    1. Match the poles closest to the unit circle with the zeros closest to these poles.

    2. Match the poles closest to the unit circle with the zeros closest to these poles.

    3. 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.

  3. 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.

  4. 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

  1. Jackson, L. B. Digital Filters and Signal Processing. 3rd ed. Boston: Kluwer Academic Publishers, 1996.

  2. Mitra, S. K. Digital Signal Processing: A Computer-Based Approach. 3rd ed. New York: McGraw-Hill Higher Education, 2006.

  3. 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.