SE&ST Lab - Linear Systems in MATLAB
SE&ST Lab - Linear Systems in MATLAB
1 Overview
1.1 Objective
This lab provides hands-on experience in modeling and analyzing linear dynamical
systems using MATLAB. Students will develop a deeper understanding of how differ-
ential equations translate into transfer functions and how system dynamics can be
simulated using MATLAB’s built-in tools. By the end of this lab, students will:
6. Develop intuition for system design – Observe how system parameters (e.g.,
damping, stiffness, and time constants) affect stability and transient response.
1 of 11
1.2 Learning Outcomes
Upon completion of this lab, students will be able to:
• Extract key system performance metrics such as rise time, settling time, and
steady-state gain.
2 Preliminaries
N (s)
G(s) =
D(s)
where N (s) and D(s) are polynomials in s. MATLAB provides built-in functions to
define, analyze, and visualize transfer functions.
Before performing simulations, students should be familiar with the following MAT-
LAB functions essential for modeling and analyzing system behavior.
2 of 11
Function Purpose Example Usage Expected Output
tf(num, den) Creates a trans- G = tf([1], [1 Defines G(s) = s+2
1
.
fer function from 2]);
numerator and
denominator coeffi-
cients.
tf('s') Defines the Laplace s = tf('s'); G = Alternative method
variable s for sym- 1/(s+2); to define G(s).
bolic manipulation
of transfer functions.
step(sys) Plots the step re- step(G); Generates a time re-
sponse of the sys- sponse plot for a unit
tem. step input.
stepinfo(sys) Computes key time- info = Returns rise time,
domain performance stepinfo(G); settling time, over-
metrics. shoot, and steady-
state value.
zero(sys) Determines the sys- zeros G = zero(G); Returns an empty ar-
tem’s zeros (roots of ray for G(s) = s+2
1
(no
the numerator poly- zeros).
nomial).
pole(sys) Determines the sys- poles G = pole(G); Returns s = −2 for
tem’s poles (roots 1
G(s) = s+2 .
of the denominator
polynomial).
• System Stability: The location of system poles determines its stability. A system
is stable if all poles have negative real parts (i.e., they lie in the left half of the
complex plane).
– Rise Time: Time taken for the response to rise from 10% to 90% of its final
value.
– Settling Time: Time taken for the response to remain within a specified
percentage (typically 2% or 5%) of its final value.
– Overshoot: The amount by which the response exceeds its final steady-
state value.
3 of 11
This section serves as a foundation for the lab activities, ensuring that students can
confidently implement and interpret MATLAB simulations.
3 Lab Tasks
In this example, we will model a first-order system and analyze its step response
using MATLAB. The goal is to understand how the system behaves in response to a
unit step input and extract key performance metrics such as rise time, settling time,
and steady-state value.
1
G(s) =
s+2
In MATLAB, we define this transfer function using the tf function:
Explanation:
4 of 11
Explanation:
• step(sys); generates the step response of the system, simulating how the sys-
tem reacts to a unit step input.
• xlabel(...); and ylabel(...); label the time axis and amplitude axis, respec-
tively, to improve readability.
• grid on; enables grid lines to make it easier to interpret the graph.
Explanation:
• disp(info); prints the structure info, which contains various response met-
rics.
Explanation:
• zeros G = zero(sys); computes the zeros of the transfer function, which are
the roots of the numerator polynomial. Since G(s) = s+2
1
has no zeros, this
returns an empty array.
• poles G = pole(sys); computes the poles of the transfer function, which are
the roots of the denominator polynomial. In this case, the only pole is at s = −2.
5 of 11
• disp('Zeros:'); disp(zeros G); prints the zeros (which is an empty array in
this case).
Explanation:
Explanation:
6 of 11
3.3 Example 2: First-Order ODE to Transfer Function
3.3.1 Objective
This example demonstrates how to derive a transfer function from a first-order ordi-
nary differential equation (ODE) and simulate its response in MATLAB. The goal is to
understand how system dynamics are represented in the Laplace domain and how
MATLAB can be used to analyze system behavior.
dy
0.5 + y(t) = 2u(t)
dt
Taking the Laplace transform:
Rearranging:
Y (s) 2
G(s) = =
U (s) 0.5s + 1
• tau = 0.5; defines the time constant of the system as 0.5 seconds.
• K = 2; sets the system gain to 2, meaning the system amplifies the input by a
factor of 2.
7 of 11
3.3.4 Step 3: Simulate and Analyze the System Response
step(G);
title('Step Response of G(s) = 2 / (0.5s + 1)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
• title(...); sets the title of the plot to describe the system being analyzed.
• xlabel(...); and ylabel(...); label the x-axis (time) and y-axis (amplitude)
for clarity.
info = stepinfo(G);
disp('Step Response Metrics:');
disp(info);
• disp(info); prints the step response metrics in the MATLAB command window.
8 of 11
• sys delayed = G * exp(-1 * s); modifies the original system to include the
time delay.
• title(...); labels the plot to indicate that a time delay has been introduced.
where:
ẍ + 2ẋ + 5x = F (t)
9 of 11
3.4.3 Step 2: Find the Transfer Function
1
G(s) =
s2 + 2s + 5
step(sys_mech);
title('Step Response of Mass-Spring-Damper System');
grid on;
Expected Observations:
10 of 11
• step(sys mech); simulates the unit step response, showing how the system
responds to a sudden force input.
Expected Outcome: - The system response should become slower, with no os-
cillations, indicating an overdamped response. - Verify this by checking the
system poles:
pole(sys_damped)
Expected Outcome: - The output x(t) will exhibit a steady-state oscillatory be-
havior matching the input frequency, but with a phase shift and possible am-
plitude changes due to the system dynamics.
11 of 11