Pages

MATLAB Simulation Experiment from Basics to Process Dynamic Simulation Using Simulink


Open-loop simulation:

(1) open Simulink by double-clicking Simulink from the menu of the matlab command window.
(2) This opens the Simulink window and from the menu bar select a new file.
(3) A new file of Simulink is opened and it is named (default) as untitled.mdl. All Simulink files have mdl extension.
(4) From the Simulink library open ‘continuous’ icon. The transfer function is given in the continuous library as 1/(s+1) and transport delay is also given in continuous library. Drag the transfer function and drop in the new Simulink file. Similarly, drag and drop transport delay also.
(5) Now open Simulink library icon ‘sources’. Drag step function from it and drop in a new file.
(6) Now open Simulink library icon ‘sinks’. From ‘sinks’ drag and drop ‘scope’ and ‘untitled mat’ into the Simulink file.
(7) Now connect all these blocks by using a left click of the mouse.. If the existing line between two blocks is to be joined to another block, then use right click of the mouse.
(8) Once the block diagram is over, change the output file name from untitled mat to your pet name by double-clicking it. The default output variable is an in that file and you can change it according to your problem. Set the sample time as 0.01 which means the data is stored for every 0.01 sec. press ok.
(9) Double click the transfer function. Numerator and denominator are to be given according to your problem in the decreasing order of s. click ok
(10) Double click steps icon and give the time at which the step change is to be given to the process and initial and final value for the step is to be given and sample time is same as 0.01.
(11) Double click the transport delay and set the delay of the process as per the problem at hand and press ok
(12) Save this file with a name.mdl
(13) To simulate this block diagram, open simulation in the menu bar and select simulation parameters in it. Give the stop according to your problem and press ok.
(14) To simulate the block diagram press solid forward arrow symbol in the menu bar.
(15) Once the simulation is over, open Matlab command window and load the output file using the command load.
(16) Example: >>load out.mat
(17) To plot the step response use the command >>plot(y(1,:),y(2,:))[y is the output variable name which is used instead of default ans). This means the first row of y which is a time vector is plotted against the response vector (2 row of y). Then label the axis using xlabel and ylabel commands.


The open-loop block diagram is given below
matlab and simulink diagram of open loop system in process control system
Open loop
Closed loop simulation:

For closed loop simulation, additional blocks of PID controller and a summation block are required. The additional step function is required for regulatory or load problem,

PID controller is available in Simulink extras of the simulink library. Double-clicking Simulink extras, select additional linear. PID controller is available in that. Drag and drop PID into an untitled Simulink file along with transfer function, step, to file, scope.

Drag and drop sum block from Math of Simulink library and we need two of them for the simulation of the servo (setpoint change) and the regulatory problem (load change).

Connect the blocks as shown in the figure given below.
process control  closed loop system diagram in simulink of matlab simulator
Closed loop
To give PID values, double-click PID block. In Proportional give kc value, integral give kc/I and derivative give kc*I value. Click ok.

For example, consider a transfer function model of a process as. Conduct closed-loop simulation for servo and a regulatory problem for a unit set to change in setpoint at time=0 and a unit step change in load at time=100.
(a) P controller with kc=1.9
(b) PI controller with kc=1.7 and I=14.3s
(c) PID controller with kc=1.6, I=12.5s,D=0.5s

To simulate for both servo and regulatory simultaneously, double-click step (setpoint input) and time are set equal to zero and the initial value is zero and the final value is 1. sample time is 0.01. Now double click step (load input) and time are set equal to 100 (it is the time at which servo response reaches to 1) and initial value zero and final value 1. The sample time is 0.01. i.e. Load is initiated after 100s.
Simulation time is fixed by selecting simulation parameters in the menu bar. The simulation time should be around 200 to stabilize the regulatory response as the load step is initiated at 100.

Once the simulation is over, load the result file in the Matlab command window.
>> load result.mat
>> figure,plot(y(1,:),y(2,:),'k')
>> xlabel 'time'
>> ylabel 'response'
Here the output file name is result.mat and the variable name is y. The first row of y stores time and second row of y stores response. The figures generated are

P controller

In PID block substitute P parameters as kc, 0I and 0 for proportional, integral and derivative time locations.
Simulate and then load the file in matlab command window and plot as shown below.
>> load result.mat
>> figure,plot(y(1,:),y(2,:))
>> xlabel 'time'
>> ylabel 'response'
matlab simulink diagram of P control response
P controller response

PI controller

In PID block substitute PI parameters as kc, kc/I and 0 for proportional, integral and derivative time locations.
Simulate and then load the file in matlab command window and plot as shown below.
>> load result.mat
>> figure,plot(y(1,:),y(2,:),'k')
>> xlabel 'time'
>> ylabel 'response'
matlab simulink diagram of PI control response
PI controller response

PID controller

In PID block substitute PID parameters as kc, kc/I and kc*D for proportional, integral and derivative time locations.

Simulate and then load the file in matlab command window and plot as shown below.
>> load result.mat
>> figure,plot(y(1,:),y(2,:),'k')
>> xlabel 'time'
>> ylabel 'response'
matlab simulink diagram of PID control response
PID controller response