Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

SE&ST Lab - Linear Systems in MATLAB

This lab activity sheet provides hands-on experience in modeling and analyzing linear dynamical systems using MATLAB, focusing on transfer functions, system responses, and performance metrics. Students will learn to derive transfer functions from ordinary differential equations, simulate system behavior, and explore practical applications like mass-spring-damper systems. The lab emphasizes the importance of understanding system dynamics in control engineering and related fields.

Uploaded by

Wasaya khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

SE&ST Lab - Linear Systems in MATLAB

This lab activity sheet provides hands-on experience in modeling and analyzing linear dynamical systems using MATLAB, focusing on transfer functions, system responses, and performance metrics. Students will learn to derive transfer functions from ordinary differential equations, simulate system behavior, and explore practical applications like mass-spring-damper systems. The lab emphasizes the importance of understanding system dynamics in control engineering and related fields.

Uploaded by

Wasaya khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Systems Engineering and System Thinking

Modeling and Simulating Linear Systems in MATLAB

Lab Activity Sheet

Author: Dr. Mostapha Kalami Heris

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:

1. Understand the fundamentals of transfer functions – Learn how to represent


linear time-invariant (LTI) systems in transfer function form.

2. Gain proficiency in MATLAB’s control system functions – Use essential MATLAB


commands such as tf, step, stepinfo, zero, and pole to analyze system behav-
ior.

3. Derive transfer functions from ordinary differential equations (ODEs) – Convert


first- and second-order differential equations into their Laplace-domain repre-
sentations.

4. Simulate system responses – Investigate system behavior using step response


plots, stability analysis, and performance metrics.

5. Explore practical applications – Model a mass-spring-damper system, a funda-


mental mechanical system, and analyze its dynamics.

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:

• Define and construct transfer functions in MATLAB.

• Simulate system responses and interpret the results.

• Extract key system performance metrics such as rise time, settling time, and
steady-state gain.

• Analyze the stability of a system by determining its poles and zeros.

• Relate mathematical models to real-world physical systems.

1.3 Why is this Important?


Understanding system modeling and response analysis is crucial in control engineer-
ing, robotics, and signal processing. The ability to simulate and predict system be-
havior is fundamental in designing stable and efficient control systems for practical
applications, including autonomous robotics, aerospace engineering, and industrial
automation.

2 Preliminaries

2.1 Understanding Transfer Functions in MATLAB


A transfer function represents the relationship between an input and an output of a
linear time-invariant (LTI) system in the Laplace domain. It is commonly expressed
as:

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.2 Key MATLAB Functions


The table below summarizes important MATLAB functions used in this lab:

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

Table 1: Key MATLAB functions for transfer function analysis.

2.3 Additional Notes on MATLAB Functions


• Step Response Analysis: The function step(sys) helps visualize how the sys-
tem reacts to a sudden input. A well-damped system settles quickly without
oscillations, whereas an underdamped system oscillates before settling.

• 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).

• Performance Metrics with stepinfo:

– 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

3.1 Example 1: Simple First-Order Transfer Function


3.1.1 Objective

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.

3.1.2 Step 1: Define the Transfer Function

A first-order system can be represented by the transfer function:

1
G(s) =
s+2
In MATLAB, we define this transfer function using the tf function:

num = 1; % Numerator coefficients: 1 (constant term)


den = [1 2]; % Denominator coefficients: [sˆ1 coefficient, constant term]
sys = tf(num, den); % Create transfer function

Explanation:

• num = 1; assigns the numerator coefficient as 1. This corresponds to the nu-


merator of G(s) = 1.

• den = [1 2]; specifies the denominator coefficients for s + 2. The array [1 2]


represents s1 + 2.

• sys = tf(num, den); creates the transfer function G(s) = 1


s+2
.

3.1.3 Step 2: Simulate the Step Response

step(sys); % Plot step response


title('Step Response of G(s) = 1/(s+2)');
xlabel('Time (s)'); ylabel('Amplitude');
grid on;

4 of 11
Explanation:

• step(sys); generates the step response of the system, simulating how the sys-
tem reacts to a unit step input.

• title(...); adds a title to the plot to indicate what is being displayed.

• 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.

3.1.4 Step 3: Analyze Performance Metrics

info = stepinfo(sys); % Compute metrics


disp('Step Response Metrics:');
disp(info);

Explanation:

• info = stepinfo(sys); computes important time-domain characteristics of


the step response, including rise time, settling time, peak time, and overshoot.

• disp('Step Response Metrics:'); prints a message in the MATLAB command


window to indicate that performance metrics are being displayed.

• disp(info); prints the structure info, which contains various response met-
rics.

3.1.5 Step 4: Find Zeros and Poles

zeros_G = zero(sys); % Returns empty (no zeros)


poles_G = pole(sys); % Returns pole at s = -2
disp('Zeros:'); disp(zeros_G);
disp('Poles:'); disp(poles_G);

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

• disp('Poles:'); disp(poles G); prints the pole at s = −2.

3.2 Discussion Questions


• What happens if we change the denominator to s + 5? The system will respond
faster because the pole shifts to s = −5, reducing the settling time. Try modi-
fying the MATLAB code as follows:

sys_new = tf(1, [1 5]);


step(sys_new);

Explanation:

– The denominator [1 5] corresponds to s + 5, meaning the pole is now at


s = −5.
– A larger negative pole results in a faster system response, reducing the
settling time.

• What happens if the denominator is changed to s−2? This results in an unstable


system because the pole moves to s = 2, which is in the right half of the complex
plane. Run:

sys_unstable = tf(1, [1 -2]);


step(sys_unstable);

Explanation:

– The denominator [1 -2] corresponds to s − 2, meaning the pole is now at


s = 2.
– A positive pole (s = 2) makes the system unstable, causing the output to
grow unbounded over time.
– The step response will show an exponential increase rather than a stable
response.

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.

3.3.2 Step 1: Derive the Transfer Function

We are given the first-order ODE:

dy
0.5 + y(t) = 2u(t)
dt
Taking the Laplace transform:

0.5sY (s) + Y (s) = 2U (s)

Rearranging:

Y (s) 2
G(s) = =
U (s) 0.5s + 1

3.3.3 Step 2: Implement the Transfer Function in MATLAB

tau = 0.5; % Define time constant


K = 2; % Define system gain
s = tf('s'); % Define Laplace variable 's'
G = K / (tau*s + 1); % Define the transfer function

Explanation of the Code:

• 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.

• s = tf('s'); defines s as a Laplace variable, enabling symbolic manipulation


of transfer functions.

• G = K / (tau*s + 1); constructs the transfer function G(s) = 2


0.5s+1
using the
defined parameters.

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;

Explanation of the Code:

• step(G); simulates and plots the step response of the system.

• 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.

• grid on; adds a grid to the plot, improving visualization.

3.3.5 Step 4: Extract Performance Metrics

info = stepinfo(G);
disp('Step Response Metrics:');
disp(info);

Explanation of the Code:

• info = stepinfo(G); calculates various performance metrics for the system,


including rise time, settling time, overshoot, and steady-state value.

• disp('Step Response Metrics:'); prints a label before displaying the com-


puted metrics.

• disp(info); prints the step response metrics in the MATLAB command window.

3.3.6 Optional Challenge: Introduce a Time Delay

sys_delayed = G * exp(-1 * s);


step(sys_delayed);
title('Step Response with 1s Delay');
grid on;

Explanation of the Code:

• exp(-1 * s); represents a time delay of 1 second in the Laplace domain.

8 of 11
• sys delayed = G * exp(-1 * s); modifies the original system to include the
time delay.

• step(sys delayed); simulates the step response of the delayed system.

• title(...); labels the plot to indicate that a time delay has been introduced.

• grid on; ensures the graph is readable.

3.4 Example 3: Mass-Spring-Damper System


3.4.1 Objective

In this example, we model a second-order mechanical system, derive its transfer


function, and analyze its response. The mass-spring-damper system is a fundamental
example in control systems and mechanical engineering, demonstrating how damp-
ing and stiffness affect system dynamics.

3.4.2 Step 1: Derive the ODE

A mass-spring-damper system follows the equation of motion:

mẍ + cẋ + kx = F (t)

where:

• m is the mass (kg),

• c is the damping coefficient (Ns/m),

• k is the stiffness (N/m),

• x(t) is the displacement,

• F (t) is the applied force.

For given values:


m = 1, c = 2, k=5

the equation simplifies to:

ẍ + 2ẋ + 5x = F (t)

9 of 11
3.4.3 Step 2: Find the Transfer Function

Taking the Laplace transform (assuming zero initial conditions):

s2 X(s) + 2sX(s) + 5X(s) = F (s)

Solving for G(s) = X(s)


F (s)
:

1
G(s) =
s2 + 2s + 5

3.4.4 Step 3: Implement the Transfer Function in MATLAB

m = 1; c = 2; k = 5; % Define system parameters


num = 1; % Numerator = 1 (unit impulse response)
den = [m c k]; % Denominator coefficients: [sˆ2, s, constant]
sys_mech = tf(num, den); % Create the transfer function

Explanation of the Code:

• m = 1; c = 2; k = 5; defines the mass, damping, and stiffness values.

• num = 1; sets the numerator of the transfer function.

• den = [m c k]; defines the denominator as s2 + 2s + 5, corresponding to the


system equation.

• sys mech = tf(num, den); creates the transfer function G(s).

3.4.5 Step 4: Simulate and Analyze the Step Response

step(sys_mech);
title('Step Response of Mass-Spring-Damper System');
grid on;

Expected Observations:

• The system has complex conjugate poles at s = −1 ± 2i, meaning it exhibits


underdamped oscillations.

• The response oscillates before settling.

• Settling time: Approximately 4 seconds.

Explanation of the Code:

10 of 11
• step(sys mech); simulates the unit step response, showing how the system
responds to a sudden force input.

• title(...); adds a descriptive title to the plot.

• grid on; enables the grid to improve visualization.

3.4.6 Optional Challenges

1. Stability Analysis: Increase damping to c = 10 and analyze whether the system


becomes overdamped.

sys_damped = tf(1, [1 10 5]); % Increase damping coefficient


step(sys_damped);
title('Step Response with Increased Damping');
grid on;

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)

2. Custom Input Simulation: Instead of a step input, simulate a sinusoidal force


input F (t) = sin(3t):

t = 0:0.01:10; % Define time vector from 0 to 10 sec


u = sin(3*t); % Define sinusoidal input
lsim(sys_mech, u, t); % Simulate system response
title('Response to Sinusoidal Input');
grid on;

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

You might also like