Convert Model Rate
Convert models between continuous time and discrete time and resample models in the Live Editor
Convert Model Rate lets you interactively convert an LTI model between continuous time and discrete time. You can also use it to resample a discrete-time model. The task automatically generates MATLAB® code for your live script.
To get started with the Convert Model Rate task, select the model you want to convert. You can also specify the target sample time, conversion method, and other parameters. The task generates the converted model in the MATLAB workspace, and can generate a response plot to let you monitor the match between the original and converted models as you experiment with conversion parameters.
Open the Task
To add the Convert Model Rate task to a live script in the MATLAB Editor:
On the Live Editor tab, select Task > Convert Model Rate.
In a code block in your script, type a relevant keyword, such as
Convert Model Ratefrom the suggested command completions.
Discretize Model in the Live Editor
Use the Convert Model Rate task in the Live Editor to interactively convert a model from continuous time to discrete time. Experiment with different methods, options, and response plots. The task automatically generates code reflecting your selections. Open this example to see a preconfigured script containing the Convert Model Rate task.
Create a continuous-time transfer-function model.
G = tf([1 -50 300],[1 3 200 350]);
To discretize this model, open the Convert Model Rate task in the Live Editor. On the Live Editor tab, select Task > Convert Model Rate. In the task, select
G as the model to convert.
The task automatically discretizes the model using the default sample time, 0.2 s, and the default conversion method,
Zero-order hold. It also creates a Bode plot, allowing you to compare the responses of the original and converted models.
The vertical line on the plot shows the Nyquist frequency associated with the default sample time. Suppose you want to use a sample time of 0.15 seconds. Change the sample time by entering the new value in the Sample Time field. The response plot automatically updates to reflect the new sample time.
If the precise dynamics of the resonance are important for your application, you can improve the frequency-domain match using a different conversion method. In the task, try experimenting with different methods and observe their effect on the response plot.
The Tustin method can yield a better match in the frequency domain than the default zero-order hold method. (See Continuous-Discrete Conversion Methods.) In Select Conversion Method, select
Bilinear (Tustin) approximation. Initially, the resulting frequency-domain match is poorer than with the zero-order hold method.
You can improve the match using a prewarp frequency. This option forces the discrete-time response to match at the frequency you specify. The resonance of
G peaks at about 14 rad/s. Enter that value for the prewarp frequency. The match does improve around the resonance. However, the resonance is very close to the Nyquist frequency for the sample time of 0.15 s, which limits how close the match can be.
The Convert Model Rate task can generate other types of response plots. For instance, to compare the time-domain responses of the original and converted model, in Output Plot, select
The task generates code in your live script. The generated code reflects the parameters and options you select, and includes code to generate the response plot you specify. To see the generated code, click at the bottom of the task parameter area. The task expands to display the generated code.
By default, the generated code uses
sysConverted as the name of the output variable. The converted model in the MATLAB® workspace using this name. To specify a different output variable name, enter a new name in the summary line at the top of the task. For instance, change the name to
The task updates the generated code to reflect the new variable name, and the new converted model
sys_d appears in the MATLAB workspace. You can use the model for further analysis or control design as you would any other model object. For instance, simulate the converted system's response to a square-wave input. Use the sample time you specified in the task.
[u,t] = gensig('square',4,10,0.15); lsim(sys_d,u,t)
Model — Model to convert
Select an LTI model. The list contains all suitable continuous-time or discrete-time dynamic system models in the MATLAB workspace, including:
Numeric LTI models such as
Identified LTI models such as
idtf. (Using identified models requires a System Identification Toolbox™ license.)
You can convert SISO models or MIMO models, with or without time delays, although
some conversion methods are only available for SISO models (see the
Method parameter description). You cannot use
Convert Model Rate to convert generalized LTI models
uss, frequency-response data
models such as
frd, or process models
Sample Time — Target sample time
0.2 (default) | 0 | positive scalar
Specify the sample time of the converted model in units of
TimeUnit is the
TimeUnit property of the input model.
To discretize a continuous-time model or resample a discrete-time model, enter the target sample time.
To convert a discrete-time model to continuous time, enter 0.
Method — Rate conversion method
Zero-order hold (default) |
First-order hold |
Bilinear (Tustin) approximation | ...
Choose a rate conversion method. Available methods are:
Impulse-invariant discretization(continuous-to-discrete conversion of SISO models only)
Bilinear (Tustin) approximation
Zero-pole matching method
Least-squares method(continuous-to-discrete conversion of SISO models only)
For information about choosing a conversion method, see Continuous-Discrete Conversion Methods.
Delay Order — Approximate order for estimating time delay
0 (default) | positive integer
When you convert the rate of a model that has a time delay, the
Bilinear (Tustin) approximation or
matching method methods round the time delay to the nearest integer
multiple of the sample time. This rounding can degrade the accuracy of dynamics,
especially near the Nyquist frequency.
Set Delay Order to a nonzero integer to make
Convert Model Rate approximate the fractional portion
of the delay using a Thiran filter, instead of rounding. Use the smallest value that
yields sufficiently accurate rate-converted dynamics for your application. For more
information about Thiran filters, see
Prewarp Freq. (rad/s) — Prewarp frequency for bilinear (Tustin) method
0 (default) | positive scalar
When you discretize a continuous-time model, if your system has important dynamics
at a particular frequency that you want the rate conversion to preserve, you can use the
Bilinear (Tustin) approximation method with frequency
prewarping. This method ensures a match between the original and converted responses at
the prewarp frequency you specify. See Continuous-Discrete Conversion Methods.
Output Plot — Type of response plot
Bode (default) |
Impulse | ...
Convert Model Rate automatically generates a response plot to help you check that the dynamics important to your application are preserved. Specify one of the following response plot types to compare the responses of the original and converted models while you experiment with conversion parameters.
The code generated by the task includes code to create the selected response plot.
To omit the response plot, select