www.gusucode.com > control 案例程序 matlab源码代码 > control/CreateTunableSecondOrderFilterExample.m

    %% Create 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 $\zeta$ and the natural frequency ${\omega _n}$ are tunable parameters.

%%
% 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.

%%
% 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| model. The property |F.Blocks| lists the two tunable
% parameters |wn| and |zeta|.
F.Blocks

%%
% You can examine the number of tunable blocks in a generalized model
% using |nblocks|.
nblocks(F)

%%
% |F| has two tunable parameters, but the parameter |wn| appears five times
% - Twice in the numerator and three times in the denominator.

%%
% To reduce the number of tunable blocks, you can rewrite |F| as:
%
% $$F\left( s \right) = \frac{1}{{{{\left( {\frac{s}{{{\omega _n}}}}
% \right)}^2} + 2\zeta \left( {\frac{s}{{{\omega _n}}}} \right) + 1}}.$$
%
% Create the alternative filter.
F = tf(1,[(1/wn)^2 2*zeta*(1/wn) 1]);

%%
% Examine the number of tunable blocks in the new model.
nblocks(F)

%%
% 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 the performance 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.