MATLAB Simulation Experiment from Basics to Process Dynamic Simulation Using Simulink


Openloop simulation:

(1) open simulink by double clicking simulink from the menu of matlab command window.
(2) This opens the simulink window and from the menu bar select new file.
(3) A new file of simulink is opend and it is named (default) as untitled.mdl. All simulink files have mdl extension.
(4) From the simulink library open ‘continuous’ icon. 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. Similary drag and drop transport delay also.
(5) Now open simulink library icon ‘sources’. Drag step function from it and drop in new file.
(6) Now open simulink library icon ‘sinks’. From ‘sinks’ drag and drop ‘scope’ and ‘untitled mat’ in to the simulink file.
(7) Now connect all these blocks by using 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 ans 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 step icon and give the time at which the stepchange is to be given to the process and initial and final value for the step are to be given and sample time is same as 0.01.
(11) Double click the transport delay and set the delay of the process a sper 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 problemand press ok.
(14) To simulate the block diagram press solid forward arrow symbol in the menu bar.
(15) Once the simulation is over 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 openloop 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. Additional step function is required for regulatory or load problem,

PID controller is available in simulink extras of simulink library. Double clicking simulink extras, select additional linear. PID controller is available in that. Drag and drop PID in to 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 servo (setpoint change) and 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 regulatory problem for unit set change in setpoint at time=0 and 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 is set equal to zero and initial value is zero and final value is 1. sample time is 0.01. Now double click step (load input) and time is 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. 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