Main Content

Convert Model Rate

Convert models between continuous time and discrete time and resample models in the Live Editor

Since R2019b

Description

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.

Related Functions

Convert Model Rate generates code using the following functions.

Convert Model Rate task in Live Editor

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, rate, or c2d. Select Convert Model Rate from the suggested command completions.

Examples

expand all

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 step or impulse.

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 Show code 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, which is the converted model. To specify a different output-variable name, enter the new name in the summary line at the top of the task. For instance, change the name to sys_d.

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)

Parameters

expand all

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 tf, ss, or zpk models.

  • Identified LTI models such as idss and 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 such as genss or uss, frequency-response data models such as frd, or process models (idproc).

Specify the sample time of the converted model in units of 1/TimeUnit, where 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.

Choose a rate conversion method. Available methods are:

  • Zero-order hold

  • First-order hold

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

When you convert the rate of a model that has a time delay, the Bilinear (Tustin) approximation or Zero-pole 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 thiran.

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.

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.

  • Bode

  • Step

  • Impulse

  • Pole-Zero

The code generated by the task includes code to create the selected response plot. To omit the response plot, select None.

Version History

Introduced in R2019b