# sos2ss

Convert digital filter second-order section parameters to state-space form

## Syntax

```[A,B,C,D] = sos2ss(sos) [A,B,C,D] = sos2ss(sos,g) ```

## Description

`sos2ss` converts a second-order section representation of a digital filter to an equivalent state-space representation.

`[A,B,C,D] = sos2ss(sos)` converts `sos`, a system expressed in second-order section form, to a single-input, single-output state-space representation:

`$\begin{array}{ll}x\left(n+1\right)\hfill & =Ax\left(n\right)+Bu\left(n\right),\hfill \\ y\left(n\right)\hfill & =Cx\left(n\right)+Du\left(n\right).\hfill \end{array}$`

The discrete transfer function in second-order section form is given by

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

`sos` is a L × 6 matrix organized as

`$\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].$`

The entries of `sos` must be real for proper conversion to state space. The returned matrix `A` is of size 2L × 2L, `B` is a 2L × 1 column vector, `C` is a 1 × 2L row vector, and `D` is a 1 × 1 scalar.

`[A,B,C,D] = sos2ss(sos,g)` converts to state space a system `sos` in second-order section form with gain `g`:

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

## Examples

collapse all

Compute the state-space representation of a simple second-order section system with a gain of 2.

```sos = [1 1 1 1 0 -1 ; -2 3 1 1 10 1]; [A,B,C,D] = sos2ss(sos,2)```
```A = 4×4 -10 0 10 1 1 0 0 0 0 1 0 0 0 0 1 0 ```
```B = 4×1 1 0 0 0 ```
```C = 1×4 42 4 -32 -2 ```
```D = -4 ```

## Algorithms

`sos2ss` first converts from second-order sections to transfer function using `sos2tf`, and then from transfer function to state-space using `tf2ss`.