You are here : matlabSignal Processingtf2sos

tf2sos() - Signal Processing

```tf2sos converts a transfer function representation
of a given digital filter to an equivalent second-order section representation.[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 a and b.H(z)=B(z)A(z)=b1+b2z−1+⋯+bn+1z−na1+a2z−1+⋯+am+1z−msos is an L-by-6 matrixsos=[b01b11b211a11a21b02b12b221a12a22⋮⋮⋮⋮⋮⋮b0Lb1Lb2L1a1La2L]whose rows contain the numerator and denominator coefficients bik and aik of
the second-order sections of H(z).H(z)=g∏k=1LHk(z)=g∏k=1Lb0k+b1kz−1+b2kz−21+a1kz−1+a2kz−2[sos,g] = tf2sos(b,a,'order') specifies
the order of the rows in sos, where 'order' is'down', to order the sections so
the first row of sos contains the poles closest
to the unit circle'up', to order the sections so
the first row of sos contains the poles farthest
from the unit circle (default)[sos,g] = tf2sos(b,a,'order','scale') specifies
the desired scaling of the gain and numerator coefficients of all
second-order sections, where 'scale' is:'none', to apply no scaling (default)'inf', to apply infinity-norm scaling'two', to apply 2-norm scalingUsing infinity-norm scaling in conjunction with up-ordering
minimizes the probability of overflow in the realization. Using 2-norm
scaling in conjunction with down-ordering minimizes
the peak round-off noise.Note

Infinity-norm and 2-norm scaling are appropriate only for direct-form II implementations.sos = tf2sos(...) embeds
the overall system gain, g, in the first section, H1(z),
so thatH(z)=∏k=1LHk(z)Note

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

Syntax

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

Example

```Second-Order Section Implementation of a Butterworth FilterOpen This Example
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]
denoms = [conv(ss(1,4:6),ss(2,4:6))   ;dn]

numers =

0.0940    0.3759    0.5639    0.3759    0.0940
0.0940    0.3759    0.5639    0.3759    0.0940

denoms =

1.0000   -0.0000    0.4860   -0.0000    0.0177
1.0000   -0.0000    0.4860   -0.0000    0.0177```