0% found this document useful (0 votes)
10 views24 pages

LCS Lab 5

This document outlines Lab 5 for the EE-371 Linear Control Systems course, focusing on state space modeling and system responses using MATLAB, Simulink, and LabVIEW. It includes objectives, step-by-step instructions for constructing state space models, and exercises for analyzing system responses to various inputs. The lab emphasizes practical applications through simulations and interconnections of systems.

Uploaded by

Saad Kashif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views24 pages

LCS Lab 5

This document outlines Lab 5 for the EE-371 Linear Control Systems course, focusing on state space modeling and system responses using MATLAB, Simulink, and LabVIEW. It includes objectives, step-by-step instructions for constructing state space models, and exercises for analyzing system responses to various inputs. The lab emphasizes practical applications through simulations and interconnections of systems.

Uploaded by

Saad Kashif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Department of Electrical Engineering

Faculty Member: Mr. Yasir Rizwan Dated: 26-2-2025

Semester: 6th Section: BEE-14-A

EE-371: Linear Control Systems

LAB 5: State space, response of systems to various


inputs, and interconnections of systems
PLO4/ PLO4/ PLO5/ PLO8/ PLO9/
CLO5 CLO5 CLO6 CLO7 CLO8

Name Reg. No Viva / Analysis Modern Ethics and Individual


Quiz / of data in Tool Safety and Team
Lab Lab Usage Work
Perfor Report
mance
5 Marks 5 Marks 5 Marks 5 Marks 5 Marks
Muhammad Saad
Kashif
403474
(Prepared &
submitted)
Rayyan Naeem
414044
Muzaffar

Abdullah Munir 413132

Sudais Akbar Khan 403965

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

2. State space representation in MATLAB

2.1. Constructing a state space model 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:

i. Define the model parameters of the RLC network


R= 1;
L= 1e-3;
C = 1e-6;

ii. Define the matrixes


A = [-R/L -1/L; 1/C 0];
B = [1/L; 0];
C = [-R -1];
D = [1];
iii. Construct the state-space representation
rlc_ss = ss(A,B,C,D)

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.

EE-379: Control Systems, Lab 5 Page 3


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
EE-379: Control Systems, Lab 5 Page 4
Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
EE-379: Control Systems, Lab 5 Page 5
Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
2.2. Constructing a state space model in Simulink

i. Open Simulink ii. Create a new

Simulink model or file

iii. From the Simulink library browser go to Simulink>> Continuous and drag “State space
model” into your Simulink file.

EE-379: Control Systems, Lab 5 Page 6


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
iv. Double click the state space model to open the block properties

EE-379: Control Systems, Lab 5 Page 7


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
v. Enter the values for matrices A, B, C and D. You can enter the values of matrices in terms
of parameters R,L and C and define these parameters in the model properties, as we did
in earlier lab handouts.

vi. Simulink state space modeling of the RLC network is complete.

State Space Representation (Simulink)

EE-379: Control Systems, Lab 5 Page 8


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
2.3. Constructing a state space model in LabVIEW

i. Open New VI

ii. Switch to Block diagram using shortcut key Ctrl+E


iii. In Block diagram Right click >> function palette >> Control Design and Simulation >>
Simulation >> drag “Control and Simulation loop” into your block diagram.

iv. In the block diagram Right click >> function palette >> Control Design and Simulation
>> Simulation >> Continuous Linear System >> drag “state space” into your block
diagram.

EE-379: Control Systems, Lab 5 Page 9


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
v. Double click the state, a window will appear just like in figure

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.

EE-379: Control Systems, Lab 5 Page 10


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
State Space Representation (LabView)

EE-379: Control Systems, Lab 5 Page 11


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
3. Time Response
We have learned different representations of systems: differential equations, transfer
functions, state space, and Simulink models. Now we will simulate these models to get
the response of the systems for various inputs. We can use any of the system
representations to get the response. In this handout we will show some of the ways to
get the response.
3.1. Step Response
A step input represents a sudden and constant change in the input signal. For example, if
the speed of a motor is 0 rpm and we want it to change to 100 rpm, then our input signal
will change from zero to a constant value. This type of input signal is very common in
control systems, because we often want systems output to change from one point to
another.
The response to a step input is called the step response. The step response indicates that
how quickly a system output will reach the desired value i.e. the settling time. The step
response can also be used to find the steady state error.
3.1.1. Step Response in MATALB

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);

Step Response (MATLAB)

EE-379: Control Systems, Lab 5 Page 12


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
Exercise

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.

EE-379: Control Systems, Lab 5 Page 13


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
Exercise

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.

EE-379: Control Systems, Lab 5 Page 14


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
EE-379: Control Systems, Lab 5 Page 15
Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
3.2 Impulse Response in MATLAB
Code:
% Define the transfer functions
num_speed = [1]; % Example numerator for motor speed
den_speed = [1 2 1]; % Example denominator for motor speed
G_speed = tf(num_speed, den_speed);

num_position = [1]; % Example numerator for motor position


den_position = [1 3 3 1]; % Example denominator for motor position
G_position = tf(num_position, den_position);

num_angle = [1]; % Example numerator for pendulum arm angle


den_angle = [1 4 6 4 1]; % Example denominator for pendulum arm angle
G_angle = tf(num_angle, den_angle);

% Find the impulse response


figure;
subplot(3,1,1);
impulse(G_speed);
title('Impulse Response of Motor Speed');

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');

EE-379: Control Systems, Lab 5 Page 16


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
3.3 Response of Arbitrary Inputs in MATLAB

% Define the time vector


t = 0:0.1:5; % Time vector from 0 to 5 seconds with 0.1-second steps

% Ramp input
u_ramp = t;
figure;
lsim(G_speed, u_ramp, t);
title('Response of Motor Speed to Ramp Input');

% Square wave input


[u_square, t_square] = gensig('square', 2, 5, 0.1); % 2-second period
square wave
figure;
lsim(G_speed, u_square, t_square);
title('Response of Motor Speed to Square Wave Input');

EE-379: Control Systems, Lab 5 Page 17


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
% Sine wave input
[u_sine, t_sine] = gensig('sin', 2, 5, 0.1); % 2-second period sine wave
figure;
lsim(G_speed, u_sine, t_sine);
title('Response of Motor Speed to Sine Wave Input');

EE-379: Control Systems, Lab 5 Page 18


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
3.4 Time Response Using Inverse Laplace Transforms

Code:
syms s t;

% Define the transfer function for motor speed


G_speed_sym = (s + 1) / (s^2 + 5*s + 6);

% 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)

EE-379: Control Systems, Lab 5 Page 19


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
4. Interconnection of Systems in MATLAB

4.1 Series Connection

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

Continuous-time transfer function.


Model Properties

4.2 Parallel Connection

Code:
% Parallel connection
sys_parallel = parallel(Gs1, Gs2);
disp('Parallel Connection:');

Parallel Connection:

sys_parallel

sys_parallel =

EE-379: Control Systems, Lab 5 Page 20


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
6 s^3 + 22 s^2 + 36 s + 32
-----------------------------------
5 s^4 + 28 s^3 + 49 s^2 + 38 s + 24

Continuous-time transfer function.


Model Properties

% Parallel connection with negative feedback


sys_parallel_neg = parallel(Gs1, -Gs2);
disp('Parallel Connection with Negative Feedback:');

Parallel Connection with Negative Feedback:

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

Continuous-time transfer function.


Model Properties
4.3 Feedback Connection

Code:
% Feedback connection (negative feedback)
sys_feedback_neg = feedback(Gs1, Gs2);
disp('Negative Feedback Connection:');

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

Continuous-time transfer function.


Model Properties

% Feedback connection (positive feedback)


sys_feedback_pos = feedback(Gs1, Gs2, +1);
disp('Positive Feedback Connection:');

EE-379: Control Systems, Lab 5 Page 21


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
Positive Feedback Connection:

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

Continuous-time transfer function.


Model Properties
Exercise: Connect a Simple Gain System in Negative Feedback with DC
Motor Speed Model

Code:
% Define the simple gain system
K = 5;
G_gain = tf(K, 1);

% Define the DC motor speed model


num_motor = [1];
den_motor = [1 2 1];
G_motor = tf(num_motor, den_motor);

% Negative feedback connection


sys_feedback = feedback(G_motor, G_gain);
disp('Negative Feedback Connection with Simple Gain:');

Negative Feedback Connection with Simple Gain:

sys_feedback

sys_feedback =

1
-------------
s^2 + 2 s + 6

Continuous-time transfer function.


Model Properties

EE-379: Control Systems, Lab 5 Page 22


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
Conclusion for Lab 5: State Space, Response of Systems to Various Inputs, and
Interconnection of Systems

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.

- In LabVIEW, we utilized the "State-Space" VI to implement state-space models


numerically.

2. Time Response Analysis:


Using MATLAB and Simulink, we examined the step response, impulse response, and
reaction to arbitrary inputs (square wave, sine wave, and ramp).
- The system reactions were simulated and shown using MATLAB's `step()`, `impulse()`,
and `lsim()` functions.
- We simulated reactions to various inputs using Simulink's Step, Pulse Generator, and
Sine Wave blocks, then used the Scope block to view the results.

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.

4. Inverse Laplace Transforms:


- We used the `ilaplace()` function in MATLAB to derive mathematical expressions for
the step, ramp, and impulse responses of systems. This provided a theoretical
understanding of the system behavior, which was then compared with the simulated
responses.

EE-379: Control Systems, Lab 5 Page 23


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir
Observations:
- The step response of the motor speed, motor position, and pendulum arm angle systems
revealed differences in their dynamic behavior, such as overshoot, settling time, and
steady-state values.
- The impulse response provided information about the system's natural frequency and
damping characteristics.
- The response to arbitrary inputs (ramp, square wave, and sine wave) highlighted how
systems react to different types of signals, which is crucial for designing controllers that
can handle varying operating conditions.

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.

EE-379: Control Systems, Lab 5 Page 24


Prepared By: Dr Ammar Hasan, Engr. Tawakal Hasnain & Engr. Saqib Nazir

You might also like