Documentation |
On this page… |
---|
Explicit Conversion Between Model Types Automatic Conversion Between Model Types Recommended Working Representation |
You can explicitly convert a model from one representation to another using the model-creation command for the target model type. For example, convert to state-space representation usingss, and convert to parallel-form PID using pid. For information about converting to a particular model type, see the reference page for that model type.
In general, you can convert from any model type to any other. However, there are a few limitations. For example, you cannot convert:
frd models to analytic model types such as ss, tf, or zpk (unless you perform system identification with System Identification Toolbox™ software).
ss models with internal delays to tf or zpk.
You can convert between Numeric LTI models and Generalized LTI models.
Converting a Generalized LTI model to a Numeric LTI model evaluates any Control Design Blocks at their current (nominal) value.
Converting a Numeric LTI model to a Generalized LTI model creates a Generalized LTI model with an empty Blocks property.
Some algorithms operate only on one type of model object. For example, the algorithm for zero-order-hold discretization with c2d can only be performed on state-space models. Similarly, commands such as tfdata or piddata expect a particular type of model (tf or pid, respectively). For convenience, such commands automatically convert input models to the appropriate or required model type. For example:
sys = ss(0,1,1,0) [num,den] = tfdata(sys)
tfdata automatically converts the state-space model sys to transfer function form to return numerator and denominator data.
Conversions to state-space form are not uniquely defined. For this reason, automatic conversions to state space do not occur when the result depends on the choice of state coordinates. For example, the initial and kalman commands require state-space models.
You can represent numeric system components using any model type. However, Numeric LTI model types are not equally well-suited for numerical computations. In general, it is recommended that you work with state-space (ss) or frequency response data (frd) models, for the following reasons:
The accuracy of computations using high-order transfer functions (tf or zpk models) is sometimes poor, particularly for MIMO or high-order systems. Conversions to a transfer function representation can incur a loss of accuracy.
When you convert tf or zpk models to state space using ss, the software automatically performs balancing and scaling operations. Balancing and scaling improves the numeric accuracy of computations involving the model. For more information about balancing and scaling state-space models, see Scaling State-Space Models.
In addition, converting back and forth between model types can introduce additional states or orders, or introduce numeric inaccuracies. For example, conversions to state space are not uniquely defined, and are not guaranteed to produce a minimal realization for MIMO models. For a given state-space model sys,
ss(tf(sys))
can return a model with different state-space matrices, or even a different number of states in the MIMO case.
This example shows how to convert a PID controller model to a transfer function model.
You can use the technique of this example to convert any type of model to another type of model.
Create a PID controller.
pid_sys = pid(1,1.5,3);
Convert pid_sys to a transfer function model.
C = tf(pid_sys);
C is a tf model representation of pid_sys.
You can similarly convert transfer function models to pid models, provided the tf model object represents a parallel-form PID controller with Tf ≥ 0.
This example shows how to get the current value of a generalized model by converting it to a numeric model. This conversion is useful, for example, when you have tuned the parameters of the generalized model using a Robust Control Toolbox™ command such as systune or looptune.
Create a Generalized Model
Represent the transfer function
$$F=\frac{a}{s+a}$$
containing a real, tunable parameter, a, which is initialized to 10.
a = realp('a',10);
F = tf(a,[1 a]);
F is a genss model parameterized by a.
Tune the Model
Typically, once of you have a generalized model, you tune the parameters of the model using a tuning command such as systune or looptune. For this example, instead of tuning the model, manually change the value of the tunable component of F.
F.Blocks.a.Value = 5;
Get the current value of the generalized model.
Get the current value of the generalized model by converting it to a numeric model.
F_cur_val = tf(F)
F_cur_val = 5 ----- s + 5 Continuous-time transfer function.
tf(F) converts the generalized model, F, to a numeric transfer function, F_cur_val.
To view the state-space representation of the current value of F, type ss(F).
To examine the current values of the individual tunable components in a generalized model, use showBlockValue.