LCS Lab 5
LCS Lab 5
Page 1
LAB 5: State space, response of systems to various inputs, and
interconnections of systems
1. Objectives
• Learn how to create state space models in MATLAB, Simulink and LabVIEW.
• Learn how to find time response of a system for various inputs in MATLAB, Simulink and
LabVIEW.
• Interconnection of systems in MATLAB
In MATLAB, the function ss() is used for creating state space models. We will use the
example of RLC circuit to illustrate how a state space model is created in MATLAB. Follow
the steps given below:
Once we have the state space model we can convert it to the transfer function model by using
the function tf()
rlc_tf = tf(rlc_ss)
We can also convert a transfer function to state space model using the function ss()
rlc_ss2 = ss(rlc_tf)
EE-379: Control Systems, Lab 5 Page 2
Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
Exercise
Use the transfer functions of motor speed, motor position and pendulum arm angle to find
their state space representation.
iii. From the Simulink library browser go to Simulink>> Continuous and drag “State space
model” into your Simulink file.
i. Open New VI
iv. In the block diagram Right click >> function palette >> Control Design and Simulation
>> Simulation >> Continuous Linear System >> drag “state space” into your block
diagram.
vi. Enter the values for matrices A, B, C and D to complete the state space modeling. In MATLAB
and SImulink we can enter values of these matrices in terms of parameters (i.e. R, L and C). In
LabVIEW we will enter numeric values.
In MATLAB the step response can be calculated by using the function step(). For
example the step response of the RLC circuit, we can use either of the following
commands
step(rlc_ss); step(rlc_tf);
you can also you the zpk representation
rlc_zpk = zpk(rlc_tf);
step(rlc_zpk);
Using the models of motor and pendulum find the unit step response for motor speed,
motor position and pendulum arm angle. You can use any model representation you like.
Comment on the response that you get for all the systems.
3.1.2. Step response in Simulink
You can find the step response in Simulink using any representation (transfer function
block, state space block or model block). Open one of the model files you have created in
the earlier labs for the motor or pendulum. In the Simulink Library browser go to Simulink
library >> Source >> drag the Step block into your model. Connect the output of the Step
block to the input of the model. In the Simulink Library browser go to Simulink >> Sink >>
drag the Scope block into your model.
In the menu, go to Simulation>>Start to start the simulation. Double click the Scope block
to see the step response.
If instead of the Step block you place another source, you can see the response for that
iput.
Using the models of motor speed, find the response to the following inputs in Simulink
• Unit step
• Square wave (Pulse Generator block)
• Sine wave (Sine Wave block)
You can adjust the source signal parameter by double clicking on the source signal block
e.g. the pulse generator block. Try to change some of the parameters for the pulse
generator block and see the effect on the response.
subplot(3,1,2);
impulse(G_position);
title('Impulse Response of Motor Position');
subplot(3,1,3);
impulse(G_angle);
title('Impulse Response of Pendulum Arm Angle');
% Ramp input
u_ramp = t;
figure;
lsim(G_speed, u_ramp, t);
title('Response of Motor Speed to Ramp Input');
Code:
syms s t;
% Step response
step_input = 1/s; % Laplace transform of step input
step_response = ilaplace(G_speed_sym * step_input);
disp('Step Response:');
Step Response:
pretty(step_response);
exp(-2 t) exp(-3 t) 2 1
--------- - ----------- + -
2 3 6
% Ramp response
ramp_input = 1/s^2; % Laplace transform of ramp input
ramp_response = ilaplace(G_speed_sym * ramp_input);
disp('Ramp Response:');
Ramp Response:
pretty(ramp_response);
t exp(-2 t) exp(-3 t) 2 1
- - --------- + ----------- + --
6 4 9 36
% Impulse response
impulse_input = 1; % Laplace transform of impulse input
impulse_response = ilaplace(G_speed_sym * impulse_input);
disp('Impulse Response:');
Impulse Response:
pretty(impulse_response);
exp(-3 t) 2 - exp(-2 t)
Code:
% Define the transfer functions
num1 = [1 2];
den1 = [1 5 6];
Gs1 = tf(num1, den1);
num2 = [1 4];
den2 = [5 3 4];
Gs2 = tf(num2, den2);
% Series connection
sys_series = series(Gs1, Gs2);
disp('Series Connection:');
Series Connection:
sys_series
sys_series =
s^2 + 6 s + 8
-----------------------------------
5 s^4 + 28 s^3 + 49 s^2 + 38 s + 24
Code:
% Parallel connection
sys_parallel = parallel(Gs1, Gs2);
disp('Parallel Connection:');
Parallel Connection:
sys_parallel
sys_parallel =
sys_parallel_neg
sys_parallel_neg =
4 s^3 + 4 s^2 - 16 s - 16
-----------------------------------
5 s^4 + 28 s^3 + 49 s^2 + 38 s + 24
Code:
% Feedback connection (negative feedback)
sys_feedback_neg = feedback(Gs1, Gs2);
disp('Negative Feedback Connection:');
sys_feedback_neg
sys_feedback_neg =
5 s^3 + 13 s^2 + 10 s + 8
-----------------------------------
5 s^4 + 28 s^3 + 50 s^2 + 44 s + 32
sys_feedback_pos
sys_feedback_pos =
5 s^3 + 13 s^2 + 10 s + 8
-----------------------------------
5 s^4 + 28 s^3 + 48 s^2 + 32 s + 16
Code:
% Define the simple gain system
K = 5;
G_gain = tf(K, 1);
sys_feedback
sys_feedback =
1
-------------
s^2 + 2 s + 6
This lab employed MATLAB, Simulink, and LabVIEW to investigate the state-space
representation of systems, study the time response of systems to different inputs, and
examine the interconnectivity of systems. The lab's main goals were accomplished
through practical exercises and simulations that deepened understanding of control
systems and how they behave.
Key Takeaways:
1. State-Space Representation:
We gained knowledge of how to create state-space models using LabVIEW, Simulink, and
MATLAB. For multi-input, multi-output (MIMO) systems, the state-space representation
offers a thorough method of modeling systems with matrices.
- State-space models were created in MATLAB using the `ss()` function, and we utilized
`tf()` and `ss()` to convert transfer functions to state-space models and vice versa.
- To represent systems in Simulink, we defined the state matrices using the "State-
Space" block.
3. Interconnection of Systems:
We used MATLAB methods like `series()`, `parallel()`, and `feedback()` to connect systems
in series, parallel, and feedback configurations.
- Because of these links, we were able to examine the collective behavior of the
systems, which is crucial when creating intricate control systems.
Conclusion:
State-space modeling, temporal response analysis, and system interconnections were all
thoroughly understood thanks to this lab. We obtained useful knowledge about control
system design and analysis by modeling and examining how systems react to different
inputs. Designing and optimizing control systems in practical applications requires the
skills learned in this lab, such as modeling and simulating systems using MATLAB,
Simulink, and LabVIEW. Complex control system design benefits greatly from the capacity
to connect systems and examine how they behave as a whole. All things considered, the
lab met its goals and improved our comprehension of linear control systems.