0% found this document useful (0 votes)
2 views

Lab 4 slides

This document outlines Lab 4 of a Control Systems course, focusing on analyzing system response using SIMULINK. It introduces SIMULINK as a simulation tool for dynamic systems, detailing its functionalities and various block types for modeling and analysis. The lab tasks include studying the response of a first-order system to step input and implementing models using MATLAB functions and S-functions.

Uploaded by

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

Lab 4 slides

This document outlines Lab 4 of a Control Systems course, focusing on analyzing system response using SIMULINK. It introduces SIMULINK as a simulation tool for dynamic systems, detailing its functionalities and various block types for modeling and analysis. The lab tasks include studying the response of a first-order system to step input and implementing models using MATLAB functions and S-functions.

Uploaded by

NIGHT RANGER
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Control systems

Lab 4
Analysis of system response
using SIMULINK

Dr. Muhammad Wasim


Spring 2025
Lab objectives

❖ SIMULINK introduction
❖ Response of first order system to the step input
❖ Using Simulink Basic Blocks
❖ Using Simulink MATLAB function
❖ S-function based implementation.
❖ Using Laplace transforms
❖ Lab tasks
Simulink Introduction

• Simulink is a simulation and model-based design environment for dynamic and embedded systems, which
are integrated with MATLAB. Simulink is also developed by MathWorks. It is a data flow graphical programming
language tool for modelling, simulating and analyzing multi-domain dynamic systems. It is basically a graphical block
diagramming tool with a customizable set of block libraries. Furthermore, it allows you to incorporate MATLAB

algorithms into models as well as export the simulation results into MATLAB for further analysis. Simulink
supports the following:
• Simulation.
• Automatic code generation.
• Testing and verification of embedded systems
Example 1: Missile Guidance System
Example 2: Quadcopter Flight Simulation Model
Example 2: Quadcopter Flight Simulation Animation
Examples available in Simulink environment
• Aerospace Blockset
• Control system toolbox
• Reinforcement Learning toolbox
• Robotics toolbox
• Sensor fusion and tracking toolbox
• Robust control toolbox
• Many examples are available to start with
Examples available in Simulink environment
Simulink start button
Simulink Library Browser

Simulink Library Browser


Simulink Library Browser
Sr. No Block work
It adds or subtracts signals
1.
It multiply or divide signals
2.
It increases or decrease the magnitude of signals
3.
Mux combine multiple signal into a vector
4.
Demux separates individual signals of vector
5.
Selector, selects signals from a vector
6.
Scope displays the signals. The x-axis corresponds to time and
7.
y-axis corresponds to the amplitude of signals over the passage
of time.
Displays the numerical value of signal on each sampling instant
8.
Sr. No Block work
Output the data to the MATLAB workspace.
9.
Solves the derivative.
10.
Limits the output of signal
11.
Finds the derivative
12.
Implements the transfer function of system.
13.
Implements the state-space model of the system
14.
Implements the PID controller
15.
Finds the absolute value of the signal
16.
Sr. No Block work
Finds sin, cosine, tangent, sec, cot, cosec of input signal.
17.
Finds the dot product of vectors.
18.
Finds the square root of input signals
19.
Step input
20.
Ramp input
21.
Sine input
22.
Any type of signal curve can be manually generated using signal
23.
builder block
Constant input
24.
Sr. No Block work
Output the current simulation time
25.
You can write the differential equations directly into this block.
26.
Actually, all MATLAB code can be directly written into this block.
It interfaces MATLAB and Simulink.
You can write the differential equations directly into this block. It
27.
has built in integrators; you have to write initial conditions into it.
Response of first order system to the step input

𝑹 +
+
𝒖 𝑪 𝑽

1 1
𝑉ሶ = 𝑢 − 𝑉 (1)
𝑅𝐶 𝑅𝐶
Using basic blocks
Using Laplace transforms
Considering zero initial condition and taking the Laplace transform of a system we will
get:
1 1
𝑠𝑉 𝑠 − 𝑉(0) + 𝑉(𝑠) = 𝑈(𝑠) (2)
𝑅𝐶 𝑅𝐶

1 1
𝑠𝑉 𝑠 + 𝑉(𝑠) = 𝑈(𝑠) (3)
𝑅𝐶 𝑅𝐶

1
𝑉 𝑠 𝑅𝐶
= 1 (4)
𝑈 𝑠 𝑠+𝑅𝐶

Inserting the value of 𝑅 = 1, 𝐶 = 1 we will get:


𝑉 𝑠 1
= (5)
𝑈 𝑠 𝑠+1
Using Laplace transforms
Using Simulink MATLAB function
Using Simulink MATLAB function
•function dv = fcn(u,v)
•%% Definig parameters
•R=1;
•C=1;
•%% differential equation
•dv=(1/R*C)*u-(1/R*C)*v;
S-function based implementation
• function [sys,x0,str,ts] = Electricalsystem(t,x,u,flag)
• warning off MATLAB:divideByZero
• switch flag
• case 0
• [sys,x0,str,ts]=mdlInitializeSizes(); % Initialization
• case 1
• sys = mdlDerivatives(t,x,u); % Calculate derivatives
• case 3
• sys = mdlOutputs(t,x); % Calculate outputs
• case { 2, 4, 9 } % Unused flags
• sys = [];
• otherwise
• error(['Unhandled flag = ',num2str(flag)]); % Error handling
• end
• end % End of flyer2dynamics

• %=======================================================
• % mdlInitializeSizes
• % Return the sizes, initial conditions, and sample times for the S-function.
• %=======================================================%
• function [sys,x0,str,ts] = mdlInitializeSizes()
• % Call simsizes for a sizes structure, fill it in and convert it to a sizes array.
• sizes = simsizes;
• sizes.NumContStates = 1;
• sizes.NumDiscStates = 0;
• sizes.NumOutputs = 1;
• sizes.NumInputs = 1;
• sizes.DirFeedthrough = 0;
• sizes.NumSampleTimes = 1;
• sys = simsizes(sizes);
• % Initialize the initial conditions.
• x0 = 0;
• % str is an empty matrix.
• str = [];
• % Generic timesample
• ts = [0 0];
• end
• % End of mdlInitializeSizes.
• %======================================================%
• % mdlDerivatives
• % Calculate the state derivatives for the next timestep
• %======================================================%
• function sys = mdlDerivatives(t,x,u)
• %% Defining parameters
• R=1;
• C=1;
• %% differential equation
• dv=(1/R*C)*u-(1/R*C)*x;
• sys = dv; %This is the state derivative vector
• end % End of mdlDerivatives.
• %======================================================%
• % mdlOutputs
• % Calculate the output vector for this timestep
• %======================================================%
• function sys = mdlOutputs(t,x)
• sys = x;
• end % End of mdlOutputs.
Results

You might also like