# tf2sos

Convert digital filter transfer function data to second-order sections form

## Syntax

``[sos,g] = tf2sos(b,a)``
``[sos,g] = tf2sos(b,a,order)``
``[sos,g] = tf2sos(b,a,order,scale)``
``sos = tf2sos(___)``

## Description

example

````[sos,g] = tf2sos(b,a)` finds a matrix `sos` in second-order section form with gain `g` that is equivalent to the digital filter represented by transfer function coefficient vectors `b` and `a`.```
````[sos,g] = tf2sos(b,a,order)` specifies the order of the rows in `sos`.```
````[sos,g] = tf2sos(b,a,order,scale)` specifies the scaling of the gain and numerator coefficients of all second-order sections.```
````sos = tf2sos(___)` embeds the overall system gain in the first section.```

## Examples

collapse all

Design a Butterworth 4th-order lowpass filter using the function `butter`. Specify the cutoff frequency as half the Nyquist frequency. Implement the filter as second-order sections. Verify that the two representations are identical by comparing their numerators and denominators.

```[nm,dn] = butter(4,0.5); [ss,gn] = tf2sos(nm,dn); numers = [conv(ss(1,1:3),ss(2,1:3))*gn;nm]```
```numers = 2×5 0.0940 0.3759 0.5639 0.3759 0.0940 0.0940 0.3759 0.5639 0.3759 0.0940 ```
`denoms = [conv(ss(1,4:6),ss(2,4:6));dn]`
```denoms = 2×5 1.0000 0.0000 0.4860 0.0000 0.0177 1.0000 0.0000 0.4860 0.0000 0.0177 ```

## Input Arguments

collapse all

Transfer function coefficients, specified as vectors. Express the transfer function in terms of `b` and `a` as

`$H\left(z\right)=\frac{B\left(z\right)}{A\left(z\right)}=\frac{{b}_{1}+{b}_{2}{z}^{-1}+\cdots +{b}_{n+1}{z}^{-n}}{{a}_{1}+{a}_{2}{z}^{-1}+\cdots +{a}_{m+1}{z}^{-m}}.$`

Example: `b = [1 3 3 1]/6` and `a = [3 0 1 0]/3` specify a third-order Butterworth filter with normalized 3 dB frequency 0.5π rad/sample.

Data Types: `double`

Row order, specified as one of the following:

• `'up'` — Order the sections so the first row of `sos` contains the poles farthest from the unit circle.

• `'down'` — Order the sections so the first row of `sos` contains the poles closest to the unit circle.

Data Types: `char`

Scaling of gain and numerator coefficients, specified as one of the following:

• `'none'` — Apply no scaling.

• `'inf'` — Apply infinity-norm scaling.

• `'two'` — Apply 2-norm scaling.

Using infinity-norm scaling with `'up'`-ordering minimizes the probability of overflow in the realization. Using 2-norm scaling with `'down'`-ordering minimizes the peak round-off noise.

### Note

Infinity-norm and 2-norm scaling are appropriate only for direct-form II implementations.

Data Types: `char`

## Output Arguments

collapse all

Second-order section representation, returned as a matrix. `sos` is an L-by-6 matrix

`$\text{sos}=\left[\begin{array}{cccccc}{b}_{01}& {b}_{11}& {b}_{21}& 1& {a}_{11}& {a}_{21}\\ {b}_{02}& {b}_{12}& {b}_{22}& 1& {a}_{12}& {a}_{22}\\ ⋮& ⋮& ⋮& ⋮& ⋮& ⋮\\ {b}_{0L}& {b}_{1L}& {b}_{2L}& 1& {a}_{1L}& {a}_{2L}\end{array}\right]$`

whose rows contain the numerator and denominator coefficients bik and aik of the second-order sections of H(z):

`$H\left(z\right)=g\prod _{k=1}^{L}{H}_{k}\left(z\right)=g\prod _{k=1}^{L}\frac{{b}_{0k}+{b}_{1k}{z}^{-1}+{b}_{2k}{z}^{-2}}{1+{a}_{1k}{z}^{-1}+{a}_{2k}{z}^{-2}}.$`

Overall system gain, returned as a real scalar.

If you call `tf2sos` with one output argument, the function embeds the overall system gain in the first section, H1(z), so that

`$H\left(z\right)=\prod _{k=1}^{L}{H}_{k}\left(z\right).$`

### Note

Embedding the gain in the first section when scaling a direct-form II structure is not recommended and can result in erratic scaling. To avoid embedding the gain, use `tf2sos` with two outputs.

## Algorithms

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

1. It finds the poles and zeros of the system given by `b` and `a`.

2. It uses the function `zp2sos`, which first groups the zeros and poles into complex conjugate pairs using the `cplxpair` function. `zp2sos` then forms the second-order sections by matching the pole and zero pairs according to the following rules:

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

2. Match the poles next closest to the unit circle with the zeros closest to those poles.

3. Continue until all of the poles and zeros are matched.

`tf2sos` groups real poles into sections with the real poles closest to them in absolute value. The same rule holds for real zeros.

3. It orders the sections according to the proximity of the pole pairs to the unit circle. `tf2sos` normally orders the sections with poles closest to the unit circle last in the cascade. You can tell `tf2sos` to order the sections in the reverse order by specifying `order` as `'down'`.

4. `tf2sos` scales the sections by the norm specified in `scale`. For arbitrary H(ω), the scaling is defined by

`${‖H‖}_{p}={\left[\frac{1}{2\pi }\underset{0}{\overset{2\pi }{\int }}{|H\left(\omega \right)|}^{p}d\omega \right]}^{1/p}$`

where p can be either ∞ or 2. See the references for details on the scaling. The algorithm follows this scaling in an attempt to minimize overflow or peak round-off noise in fixed-point filter implementations.

 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. New York: McGraw-Hill, 1998.

 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.
{"ft_lang_label":"__label__en","ft_lang_prob":0.75710976,"math_prob":0.99047905,"size":1898,"snap":"2020-24-2020-29","text_gpt3_token_len":461,"char_repetition_ratio":0.14572334,"word_repetition_ratio":0.061290324,"special_character_ratio":0.21970496,"punctuation_ratio":0.13243243,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9979639,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-07-08T15:11:54Z\",\"WARC-Record-ID\":\"<urn:uuid:1f07f090-48fd-417f-8acd-f331d535e86b>\",\"Content-Length\":\"95469\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:76261cc8-4666-4df2-96f5-c1d4c2846e42>\",\"WARC-Concurrent-To\":\"<urn:uuid:29097f91-ec22-4ef2-a03c-03326dd61844>\",\"WARC-IP-Address\":\"104.110.193.39\",\"WARC-Target-URI\":\"https://nl.mathworks.com/help/signal/ref/tf2sos.html\",\"WARC-Payload-Digest\":\"sha1:U6WALNPREQ4ELTO5XWQLLLKVP6ILZBQT\",\"WARC-Block-Digest\":\"sha1:CWR2GA6QHBTBD7HLBIS6XAM6MAEWJWIL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-29/CC-MAIN-2020-29_segments_1593655897027.14_warc_CC-MAIN-20200708124912-20200708154912-00483.warc.gz\"}"}