Engee documentation

zp2sos

Converting filter parameters with zeros, poles, and gain into the form of second-order sections.

Library

EngeeDSP

Syntax

Function call

  • sos,g = zp2sos(z,p,k) — finds a matrix of second-order sections sos with a gain factor g, equivalent to the transfer function , zeros, the poles and scalar gain of which are specified in the arguments z, p and k:

  • sos,g = zp2sos(z,p,k,direction_flag,scale) — sets the scaling of the gain coefficients and the numerator of all second-order sections.

  • sos = zp2sos(___,gain_out) — integrates the overall gain of the system into the first section.

Arguments

Input arguments

# z — zeros

+ vector

Details

The zeros of the system, set as a vector. Zeros must be real or represent complex conjugate pairs.

Типы данных

Float64

Support for complex numbers

Yes

# p — poles

+ vector

Details

Poles of the system, defined as a vector. The poles must be real or represent complex conjugate pairs.

Типы данных

Float64

Support for complex numbers

Yes

# k is the scalar gain

+ scalar

Details

The scalar gain of the system, set as a scalar.

Типы данных

Float64

# direction_flag — line order

+ "up" (by 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

# zeroflag — ordering of real zeros

+ false (by default) | true

Details

The ordering of real zeros that are opposite to each other, given as a logical scalar:

  • false — the function will arrange these zeros according to their proximity to the poles;

  • true — the function will keep these zeros together. This option causes the numerator to have an average coefficient of zero.

Типы данных

Bool

# 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 :

If the transfer function has zeros and the poles, then — the nearest integer greater than or equal to .

# 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 zp2sos 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 zp2sos with two output arguments.

Examples

Formation of second-order sections based on zeros, poles, and gain

Details

Let’s develop a 5th-order Butterworth low-pass filter using the function butter, with the output data expressed in a form with zeros, poles, and a gain factor. Let’s set the cutoff frequency equal to one fifth of the Nyquist frequency. We convert the result into second-order sections. Visualize the frequency response.

import EngeeDSP.Functions: butter, zp2sos

z, p, k = butter(5, 0.2, out = 3)
sos = zp2sos(z, p, k)
3×6 Matrix{Float64}:
 0.00128258  0.00128258  0.0  1.0  -0.509525  0.0
 1.0         2.0         1.0  1.0  -1.09658   0.355447
 1.0         2.0         1.0  1.0  -1.36932   0.692569
import EngeeDSP.Functions: freqz

freqz(sos, out = :plot)

zp2sos

Algorithms

Function zp2sos uses a four-step algorithm to determine the representation of a second-order section for an input system with zeros, poles, and gain:

  1. It groups zeros and poles into complex conjugate pairs of elements using the function cplxpair.

  2. Forms the second section by matching pairs of poles and zeros in accordance with 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 zp2sos groups the real poles into sections where the real poles are closest to each other 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 zp2sos arranges the sections with poles closest to the unit circle, the last in the cascade. You can specify functions zp2sos so that it orders the sections in reverse order using the argument direction_flag.

  4. Function zp2sos 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. This scaling is an attempt 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, Sanjit Kumar. 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.