Professional Documents
Culture Documents
Hamza 1 To 10 Lcs
Hamza 1 To 10 Lcs
Objectives:
The objectives of this lab are to give Brief general introduction to MATLAB Declaring
matrices/vectors in MATLAB command window.Performing various matrix operations, to
manipulate them.Familiarize you with the most commonly used functions. .Familiarize you with
basic plotting methods in MATLAB.
Equipments:
A compatible PC
MATLAB
Introduction to MATLAB:
The name MATLAB is short for Matrix Laboratory. MATLAB is a high-performance language
for technical computing. It integrates computation, visualization, and programming in an easy-to-
use environment where problems and solutions are expressed in familiar mathematical notation.
Typical uses include
Math and computation
Algorithm development
Data acquisition
Modeling, simulation, and prototyping
Data analysis, exploration, and visualization
Scientific and engineering graphics
Application development, including graphical user interface building
It is widely used in both industry and academic institutions. It possesses many of the features of a
high level, numerically oriented programming language, but in addition has a large collection of
built-in functions for performing matrix and vector operations in a way that is very simple for the
user.
Type demo at the Matlab prompt to get an idea of some of the numerous things you can do
with it.
1 Hamza Ahmad
Matlab commands can be entered one line at a time, or the user can write programs of MATLAB
code and define his/her or own functions. In this lab, we shall only use the one-line-at-a-time
interpretive mode for simplicity.
Once you have a matrix, you can refer to specific elements in it. Matlab indexes matrices by row
and column.
2 Hamza Ahmad
Built-in Functions:
In addition to standard arithmetic operators, such as + and *, There are many built in
functions. MATLAB has a very large number of built-in functions. Some of the important
functions are given bellow:
3 Hamza Ahmad
sum(x) % sum of the elements of the vector x. If x is a matrix,
then result is a row vector with the sum over each
column.
det(x) % determinant of the square matrix x.
MATLAB Help:
Typing "help" at the Matlab prompt gives you a list of all the possible directories Matlab
can find commands in (a list of the directories it is looking in for commands).
Typing "help directory name" gives you a list of the commands in that directory and a
short description of them. For example to information of commands in general directory
type help general.
Typing "help command name" gives you help on a specific command. For example to
get information of inv function type help inv.
Typing "lookfor keyword" gives you a list of commands that use that keyword. i.e.,
lookfor integral lists commands that deal with integrals. It's pretty slow; choose the word
wisely. You can use control-c to stop searching when you think you've found what you
need.
doc display HTML documentation in the Help browser. doc, by itself, displays the start
page for the online doc. doc function displays the HTML documentation for the Matlab
function. But in Matlab 7.0 version, there is offline documentation in the help browser,
which will open in separate window.
The help command is very useful. Most of the Matlab built-in functions have very descriptive
names and are easily remembered or guessed.
The basic command for plotting a signal in Matlab is plot(t,y), where t is an independent variable
and y is the function of t. There are other commands exists that are frequently use in plotting of
signals with plot command to make a better visualization of a signal, those commands will be
discussed in later experiments.
Example:
We will plot the graph of y = sin (t); for t going from 0 to 20 seconds. First we need to generate
a vector t containing the values of time that we want to use. Type:
t=linspace(0,20,100);
This makes t into a row vector of 100 values from 0 to 20 inclusive. Then type
ys = sin(t);
4 Hamza Ahmad
To plot the set of points type:
plot(t,ys)
The basic graph can be prettied up using the following self-explanatory sequence of commands:
xlabel(Time in seconds)
ylabel(sin(t))
title(your Roll No.)
grid
Roll No.
1
0.8
0.6
0.4
0.2
sin(t)
-0.2
-0.4
-0.6
-0.8
-1
0 2 4 6 8 10 12 14 16 18 20
Time in seconds
5 Hamza Ahmad
Lab Report NO#02
Implementation and Reduction of Block Diagrams on MATLAB
Objective:
The objective of this lab is to familiarize with the interconnection of components like plant G(s),
Controller Gc(S), sensors and activators to form a block diagram control system and reduction of
block diagrams in MATLAB.
Theory:
A bock diagram is a specialized, high-level type of flowchart. Its highly structured form presents
a quick overview of major process steps and key process participants, as well as the relationships
and interfaces involved. A block diagram is a useful tool both in designing new processes and in
improving existing processes. In both cases the block diagram provides a quick, high-level view
of the work and may rapidly lead to process points of interest. Because of its high-level
perspective, it may not offer the level of detail required for more comprehensive planning or
analysis.. Team members who construct a block diagram must. have a clear understanding of
how the process operates.
Transfer Function models of plant, Controller, sensors and actuators arc developed using their
mathematical models.
Series Function:
6 Hamza Ahmad
1 1 Then
1
MATLAB Code:
Parallel Function:
MATLAB Code:
The cloop function calculates the closed loop transfer function with unity feedback.
7 Hamza Ahmad
1 1 1 1
MATLAB Code:
Feedback Function:
The feedback function calculates the closed loop transfer function with feedback path
8 Hamza Ahmad
1 1 1
1 CS
MATLAB Code:
Result:
The following experiment shows us the reduction of block diagrams on MATLAB. The series
function(Cascade system) , parallel function and some control unity feedback systems shows us
the reduction of blocks to just simple one input and a output which indicates the transfer
function[F(s)] output/input.
9 Hamza Ahmad
Lab Report No#03
Laplace Transform and Visualizing RLC Step Response in MATLAB
Objective:
The objective of this lab is to familiarize students with commands to solve mathematical
calculations in MATLAB. Then Laplace transform and inverse Laplace transform is introduced,
which will be used to determine the transfer function. Then step response of a series RLC circuit
will be visualized in MATLAB as well as SIMULINK.
Theory:
SYMBOLIC CALCULATION:
Based on Maple kernel, symbolic Math Toolbox performs calculation symbolically in Matlab
environment. The following examples introduce some basic operations available in Basic
Symbolic Math toolbox version 2.1.3.
Simplify
- In Matlab command window, we will first need to define alpha as a symbolic expression.
Where 'r' stands for rational form. Similarly, you may use 'e', 'd' format. Matlab returns:
ans = 1/4
10 Hamza Ahmad
Example 2: Derivative.
Example 3: Integral
To integrate function f(x,y) as shown in Example 2, we will use the command "int" as shown below.
>> int(f,x)
Matlab returns: ans = 1/3*x^3+(y+5)^3*x
The syntax of the integral command can be viewed by typing >> help int in Matlab command.
window.
If we wish to perform the following definite integral:
11 Hamza Ahmad
Example 1.
Example 2.
Example 3.
12 Hamza Ahmad
Step Response of a series RLC Circuit MATLAB:
Result:
The following experiment shows us the Laplace transforms of different trigonometric
functions, Inverse Laplace transforms, Derivatives and Integration of Laplace transforms and
step responses of RLC Circuit and showing their Transfer functions.
13 Hamza Ahmad
Lab Report No# 04
Objective:
Apparatus:
Personal computer
MATLAB ( version R2011a)
Task # 1
Given the values of R and C, obtain the unit step response of the first order system.
R=2K and C=0.01F
Verify in each case that the calculated time constant = and the one measured from
Obtain the steady state value of the system. The steady state value is defined as the value
achieved by the system at five time constants
Program:
14 Hamza Ahmad
Output:
15 Hamza Ahmad
Task # 2
Program:
Output:
Task # 3
Find the transfer function and poles, zeros and pzmap of the system represented in state space
here:
16 Hamza Ahmad
Program:
Output:
Conclusion:
In this experiment we erudite about the script of poles, zeros and performance of
first order systems.
17 Hamza Ahmad
Lab Report No# 05
Objective:
Apparatus:
Personal computer
MATLAB ( version R2011a)
Task # 1
For the following systems represented by the transfer function G(s), plot the step response in
Matlab and find the Rise time, Peak time, % overshoot and settling time. (Use the step command
to plot the step response in Matlab).
18 Hamza Ahmad
1( ) = 9/ 2+2 +9
Program:
Output:
2( ) = 9/9 2+3 +9
19 Hamza Ahmad
Program:
Output:
3( ) = 6/ 2+5 +6
20 Hamza Ahmad
Program:
Output:
4. 4( ) = 9/ 3+ 2+3 +9
Program:
21 Hamza Ahmad
Output:
Conclusion:
22 Hamza Ahmad
Lab Report No# 06
Objective:
Apparatus:
Personal computer
MATLAB ( version R2011a)
Task # 1
Effect of damping ratio on performance measures. For a single loop second order system given
below.
Rise
Peak time % Overshoot Settling time(s) Steady state value
time(s)
23
1.0 3.36 7 0 5.83 1
Program:
Output:
24
Program:
Output:
Program:
25
Output:
Program:
Output:
26
Program:
Output:
Conclusion:
In this experiment we erudite about the time response of second order system.
27
Lab Report No# 07
Objective:
To Study and understand control of devices with PWM method using NV3000-CSL.
Apparatus:
Circuit diagram:
Procedure:
Slowly tune the potentiometer and observe the change in intensity of the Lamp-1.
28 Hamza Ahmad
Exercise Tasks
Task 1:
Study and observe the speed of dc motor by changing the values of PWM. The circuit diagram is as follows:
Circuit diagram:
Procedure:
Make the connections according to the Fig.7
Connect the NV3000-Control System Lab to AC mains
Switch ON the trainer Power supply.
On slowly varying the POT in CCW (counter clockwise) direction to increase the motor speed and CW
(clockwise) to decrease the motor speed.
Connect the socket with +5v and ground to rotate the fan in one direction and on interchanging the
terminals (+5v to Gnd & Gnd to +5v) the direction of rotation will be in reverse.
Conclusion:
In this experiment we concluded that with the help of PWM driver we can control the intensity of light. As we
increase the voltage value the intensity of light increases and as we decrease the voltage value the intensity of
light decreases.
29 Hamza Ahmad
Lab Report No# 08
Objective:
Apparatus:
Circuit Diagram:
Procedure:
Now when De-Bounce switch is pressed, motor will change its direction of rotation and when De-Bounce
switch is not pressed motor will rotation in its own direction.
Exercise Tasks
Task 1:
Study and observe the characteristics of DC Motor using F/V Converter. Write the observations in observation
table and plot a graph. The circuit diagram is as follows:
Procedure :
Conclusion:
In this experiment we concluded that with the help of PWM driver we can control the speed of motor as we
increase the voltage the speed of motor increases and in the same way as we decrease the voltage the speed of
motor decreases.
31 Hamza Ahmad
LAB REPORT NO#09
Objectives:
The Routh-Hurwitz stability criterion provides a simple algorithm to decide whether or not the zeros of a
polynomial are all in the left half of the complex plane (such a polynomial is called at times "Hurwitz"). A
Hurwitz polynomial is a key requirement for a linear continuous-time time invariant to be stable (all
bounded inputs produce bounded outputs).
Routh-Hurwitz Criteria
The Routh-Hurwitz criteria is comprised of three separate tests that must be satisfied. If any single test
fails, the system is not stable and further tests need not be performed. For this reason, the tests are
arranged in order from the easiest to determine to the hardest.
The Routh Hurwitz test is performed on the denominator of the transfer function, the characteristic
equation. For instance, in a closed-loop transfer function with G(s) in the forward path, and H(s) in the
feedback loop, we have:
T(s)=G(s)/1+G(s)H(s)
If we simplify this equation, we will have an equation with a numerator N(s), and a denominator D(s):
T(s)=N(s)/D(s)
Routh-Hurwitz Tests:
Here are the three tests of the Routh-Hurwitz Criteria. For convenience, we will use N as the
order of the polynomial (the value of the highest exponent of s in D(s)). The equation D(s) can
be represented generally as follows:
D(s)=a0+a1s+a2s2+.+aNsN-1
32
Rule 1
All the coefficients ai must be present (non-zero)
Rule 2
All the coefficients ai must be positive (equivalently all of them must be negative, with no sign
change).
Rule 3
If Rule 1 and Rule 2 are both satisfied, then form a Routh array from the coefficients ai. There
is one pole in the right-hand s-plane for every sign change of the members in the first column of
the Routh array (any sign changes, therefore, mean the system is unstable).
Therefore, if N is odd, the top row will be all the odd coefficients. If N is even, the top row will
be all the even coefficients. We can fill in the remainder of the Routh Array as follows:
Now, we can define all our b, c, and other coefficients, until we reach row s0. To fill them in, we
use the following formulae:
And
33
For each row that we are computing, we call the left-most element in the row directly above it
the pivot element. For instance, in row b, the pivot element is aN-1, and in row c, the pivot
element is bN-1 and so on and so forth until we reach the bottom of the array.
To obtain any element, we negate the determinant of the following matrix, and divide by the
pivot element:
m is the element two rows up, and one column to the right of the current element.
n is the element one row up, and one column to the right of the current element. In terms of k
l m n, our equation is:
34
Example 1:
Use the MATLAB m file Routh.m given to you in lab to generate the routh table of the
following TF. Find the number of poles in the left half-plane, the right half-plane, and on the jv-
axis for the system of Figure:
Routh.m
%In this program you must give your system coefficients and the Routh-
%Hurwitz table would be shown clc
clear
num=[0 0 0 0 200];
den=[1 6 11 6 200];
r=den; m=length(r); n=round(m/2); q=1;
k=0;
for p = 1:length(r) if rem(p,2)==0
even(k)=r(p);
else
odd(q)=r(p);
k=k+1;
q=q+1;
end
end
a=zeros(m,n);
if m/2 ~= round(m/2) even(n)=0;
end a(1,:)=odd;
a(2,:)=even; if a(2,1)==0
a(2,1)=0.01;
end
for i=3:m
for j=1:n-1
x=a(i-1,1);
if x==0
35
x=0.01;
end
a(i,j)=((a(i-1,1)*a(i-2,j+1))-(a(i-2,1)*a(i-1,j+1)))/x;
if a(i,:)==0
order=(m-i+1); c=0;
d=1;
for j=1:n-1
a(i,j)=(order-c)*(a(i-1,d)); d=d+1;
c=c+2;
end
end
if a(i,1)==0
a(i,1)=0.01;
end
end
Right_poles=0; for i=1:m-1
if sign(a(i,1))*sign(a(i+1,1))==-1 Right_poles=Right_poles+1;
end
end
fprintf('\n Routh-Hurwitz Table:\n') a
fprintf('\n Number Of Right Poles =%2.0f\n',Right_poles)
reply = input('Do You Need Roots of System? Y/N ', 's');
if reply=='y'||reply=='Y'
ROOTS=roots(r);
fprintf('\n Given Polynomials Coefficients Roots :\n') ROOTS
else end
Example 2:
Given the unity feedback system:
Where frequency of oscillation is determined by observing the imaginary parts of the poles. Its
units are rad/sec
Code:
K=[0:0.001:200];
for i=1:length(K);
deng=conv([1 -4 8],[1 3]);
36
numg=[0 K(i) 2*K(i) 0];
dent=numg+deng;
R=roots(dent);
A=real(R);
B=max(A); if B<0
R K=K(i)
break end end
Conclusion:
The following experiment concludes that the Routh-Hurwitz stability criterion provides a simple
algorithm to decide whether or not the zeros of a polynomial are all in the left half of the
complex plane (such a polynomial is called at times "Hurwitz"). A Hurwitz polynomial is a key
requirement for a linear continuous-time time invariant to be stable (all bounded inputs produce
bounded outputs).
37
Lab Report No#10
Objectives:
To Study and observe Voltage to Frequency converter.
Apparatus required:
NV3000-Control System Lab
Oscilloscope/ Frequency counter
Voltmeter
2mm patch cords (3)
Circuit diagram:
Procedure:
Make the connections according to the Fig.1
Connect the NV3000-Control System Lab to AC mains.
Switch ON the trainer by Power switch.
Set the potentiometer in such a way that it gives 0.5V output at tp2 and measure the
frequency at tp3 using oscilloscope/ frequency counter.
Set the potentiometer in such a way that it gives 1.0V output at tp2 and measure the
frequency at tp3 using oscilloscope/ frequency counter.
Now repeat the step 4 and 5 for 1.5V, 2.0V up to 5.0Vand measure the frequency at tp3 using
oscilloscope/ frequency counter.
Switch OFF the power switch.
38
Now make an observation table and plot a graph between voltage (Vin) and frequency (Fout).
Observation Table:
Summary:
The motor speed is proportional to the input voltage. And the motor current is not linearly
proportional to the input voltage. At saturation, the motor input current is no longer increases
even if the input voltage is increased. And there exist a dead band input voltage range in a
motor, below which a motor cant start. Motor input voltage is required to be greater then the
largest value of the dead band to initiate motion. The dead band is caused by various mechanical
frictions in the system.
Observation Table:
39
Conclusion:
The following experiment concludes that the motor speed is proportional to the input voltage and
there exist a dead band input voltage range in a motor, below which a motor cant start. Motor
input voltage is required to be greater than the largest value of the dead band to initiate motion.
40