# Documentation

## Tunable Second-Order Filter

This example shows how to create a parametric model of the second-order filter:

$F\left(s\right)=\frac{{\omega }_{n}^{2}}{{s}^{2}+2\zeta {\omega }_{n}s+{\omega }_{n}^{2}},$

where the damping ζ and the natural frequency ωn are tunable parameters.

1. Define the tunable parameters using `realp`.

```wn = realp('wn',3); zeta = realp('zeta',0.8);```

`wn` and `zeta` are `realp` parameter objects, with initial values 3 and 0.8, respectively.

2. Create a model of the filter using the tunable parameters.

`F = tf(wn^2,[1 2*zeta*wn wn^2])`

The inputs to `tf` are the vectors of numerator and denominator coefficients expressed in terms of `wn` and `zeta`.

`F` is a `genss`. The property `F.Blocks` lists the two tunable parameters `wn` and `zeta`.

3. (Optional) Examine the number of tunable blocks in the model using `nblocks`.

`nblocks(F)`

This command returns the result:

```ans = 6```

`F` has two tunable parameters, but the parameter `wn` appears five times — twice in the numerator and three times in the denominator.

4. (Optional) Rewrite `F` for fewer occurrences of `wn`.

The second-order filter transfer function can be expressed as follows:

$F\left(s\right)=\frac{1}{{\left(\frac{s}{{\omega }_{n}}\right)}^{2}+2\zeta \left(\frac{s}{{\omega }_{n}}\right)+1}.$

Use this expression to create the tunable filter:

`F = tf(1,[(1/wn)^2 2*zeta*(1/wn) 1])`
5. (Optional) Examine the number of tunable blocks in the new filter model.

`nblocks(F)`

This command returns the result:

```ans = 4```

In the new formulation, there are only three occurrences of the tunable parameter `wn`. Reducing the number of occurrences of a block in a model can improve performance time of calculations involving the model. However, the number of occurrences does not affect the results of tuning the model or sampling it for parameter studies.