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:
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 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)
import EngeeDSP.Functions: freqz
freqz(sos, out = :plot)
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:
It groups zeros and poles into complex conjugate pairs of elements using the function cplxpair.
Forms the second section by matching pairs of poles and zeros in accordance with 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 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.
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.
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
Jackson, L. B. Digital Filters and Signal Processing. 3rd ed. Boston: Kluwer Academic Publishers, 1996.
Mitra, Sanjit Kumar. 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.