Professional Documents
Culture Documents
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.
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
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
Scope1
tf([1],[1000 1 0])
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])
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.
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.
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
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).
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