You are on page 1of 6

Islamic University of Technology

Department of Electrical and Electronic Engineering


EEE 4706: Control System Engineering Lab.
Experiment 1: Modelling using MATLAB and Simulink

In this study, we will analyze a simple system and generate its output for simple step input using
mathematical and simulation techniques.

We are going to analyze a cruise-control system (a simple car). It is important to note that the model used
here is highly simplified. In a cruise-control system, the input is the force exerted by the engine. This force
has to account for the reaction force due to acceleration and friction force associated with wheels.

Let, F = force exerted by the engine (a function of time) in Newton (N)


m = mass of the system in Kg
a = acceleration of the system (a function of time) in m/sec2
b = frictional constant in sec/m
v = velocity of the system (a function of time) in m/sec

Applying laws of mechanics,

𝐹(𝑡) = 𝑚𝑎(𝑡) + 𝑏𝑣(𝑡)


𝑑𝑣(𝑡)
𝐹(𝑡) = 𝑚 + 𝑏𝑣(𝑡)
𝑑𝑡
Taking Laplace Transform and assuming zero-initial state,

𝐹(𝑠) = 𝑚𝑠𝑉(𝑠) + 𝑏𝑉(𝑠)


𝑉(𝑠) 1
𝐻(𝑠) = =
𝐹(𝑠) 𝑚𝑠 + 𝑏
Here, H(s) is the transfer function of the system and is the mathematical description of the system. Using
H(s) we can find the response (output) of the system for any given input. In this study, we will deal with
step inputs only. When input is a step function, the output of the system is called a “step response”.
For, this system we assume that m = 1000 Kg and b = 1 sec/m.

Analytically, the step response of the system is given by


1 𝑏
𝑣(𝑡) = (1 − 𝑒 −𝑚𝑡 )
𝑏
Since, practical systems are extremely difficult to solve analytically, it is useful to learn simulation
techniques for computing responses of LTI systems.

MATLAB Technique for solving step responses:


(Each code segment in this lab note is independent of others)
m = 1000;
b = 1;
num = 1;
den = [m b];
h = tf(num,den);
step(h);

The step function computes and automatically plots the step response. If you want to plot using regular
MATLAB commands, then use the following code:
m = 1000;
b = 1;
num = 1;
den = [m b];
h = tf(num,den);
step(h);
[y time] = step(h);
plot(time,y)

You can verify the simulation by comparing the result with analytic solution using the following code:
m = 1000;
b = 1;
num = 1;
den = [m b];
h = tf(num,den);
[y time] = step(h);
plot(time,y,'k'); % this one plots the simulation result
hold on

math_function = @(t) (1/b)*(1-exp(-b*t/m));


math_solution = math_function(time);
plot(time,math_solution,'r') % this one plots the analytic result

Classroom task:
In this problem, we have assumed that the velocity is the ouput. Now, assume that displacement of the
car (a function of time) is our desired output. Plot the step response for this new description.
Useful MATLAB Techniques (will be discussed by teacher – Please take notes):
1. Using final time in step command
2. Using s = tf(‘s’) option
3. A brief discussion about function_handle and MATLAB class
4. Discussion about structure data type in relation to Simulink

Simulink based computation of step response:


1. Form a Simulink based model for the cruise control system and simulate the step response.

Scope1

tf([1],[1000 1 0])

Step LTI System Scope

2. Tweak the parameters of each block for better understanding of the process.
3. For manipulation of data (e.g.: plotting etc) from MATLAB command window, you can export
data to command window using simout block.

Scope1

tf([1],[1000 1 0])

Step LTI System Scope

simout

To Workspace
4. “To Workspace” block will put the output data at the workspace. It does this job in two formats
based on your choice.
I) Array format: variable tout contains time-series information, and variable simout
contains dependent variable data. You can plot this data from command window using
following code.
plot(tout,simout)
You can also change the name of the variables by double-clicking on “To Workspace”
block.
II) Structure format:
If you choose the option “structure with time” option, then the data will be put at the
workspace as a structure called simout.

simout will have three fields


time: this one contains the time series data
signals: this one is another structure which contains two important fields.
values: this one is the dependent variable data
dimensions: dimension of the data
blockName: name of the block from which data is generated

If you use structure format, you can use following code to plot the data.
t = simout.time;
y = simout.signals.values;
plot(t,y)

Classroom task:
In the previous Simulink model, we have used one “To Workspace” block at the output. Use another
block right next to the input source. Use structure data type in both cases to send data to workspace.
Now, from workspace, plot input and output data on a single figure using “hold on” command.

Useful MATLAB Functions (will be discussed by teacher):


Discussion about laplace and ilaplace.
Simulink model in time domain:
Control systems can also be simulated in time-domain if their governing equations are known. Let us
consider a first order RC circuit with an input source Vi. The output voltage Vo of this circuit is taken across
the capacitor. The governing equation of this circuit can be written as:
𝑑𝑣𝑜 (𝑡) 1
= (𝑣 (𝑡) − 𝑣𝑜 (𝑡))
𝑑𝑡 𝑅𝐶 𝑖
We can break down the task of simulation of into several steps:

1. We first formulate the 𝑣𝑖 (𝑡) − 𝑣𝑜 (𝑡) part.


Vinput

Step2
Subtract2

Voutput

2. Now, multiply the output with 1/RC using a ‘gain’ block whose gain equals to 1/RC.

Vinput

-K-
Step2
Subtract2 Gain1

Voutput

3. Now, according to the equation, the output of this gain equals to the derivative of output
voltage. If we take integral of this value, we get output voltage.
Vinput
Voutput

1
-K-
s
Step2
Subtract2 Gain1 Integrator1

Voutput
4. Connect the output of the integrator to the input of integrator since they are same signals
(namely, output voltage).
Vinput
Voutput

1
-K-
s
Step2
Subtract2 Gain1 Integrator1

5. Place a scope at the output terminal to observe output.

Vinput
Voutput

1
-K-
s
Step2
Subtract2 Gain1 Integrator1 Scope1

Assignments:
Submit all of them in hard-copy format in next lab.

1. Consider a second order RLC circuit with a time-varying input voltage source. The output voltage
is observed across the capacitor. Use the following values
R = 40Ω, C = 0.25F, L = 4H.
Derive the transfer function of the system (you can send the photo/scan of your derivation).

2. Plot the step response of the circuit using following methods:


a) using MATLAB coding,
b) using Simulink LTI block and
c) using Simulink time-domain analysis.

3. MATLAB assignment - 1: In the third code segment of this lab note, two colors were used to
separate two different plots. But, only color was visible since one plot overlapped with the other
completely. A person viewing this plot would misinterpret this as a single plot. So, remove this
problem by inserting legends in this code segment. Google for the meaning of “plot legend”.

Rifat Ahmed
Lecturer, EEE

You might also like