%% Convert Model Rate
% 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.
% Create a continuous-time transfer-function model.

G = tf([1 -50 300],[1 3 200 350]);

%
% Use the Convert Model Rate task to discretize this model. Experiment with different options and compare the responses of the original and converted model using the response plots. The task automatically generates and executes code for the conversion parameters you specify. Click  at the bottom of the task parameter area to display the generated code.
%

% Convert model from continuous to discrete time
sys_d = c2d(G,0.15);

% Visualize the results
bodeplot(G,sys_d);
legend('Original Model','Converted Model');
grid on;

%
% The creates a new converted model 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)

%
%
% Copyright 2019 The MathWorks, Inc.