Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

Lab Report NO# 01

Introduction to MATLAB Environment

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.

Matlab features a family of add-on application-specific solutions called toolboxes. Very


important to most users of Matlab, toolboxes allow you to learn and apply specialized technology.
Toolboxes are comprehensive collections of Matlab functions (M-files) that extend the Matlab
environment to solve particular classes of problems. Areas in which toolboxes are available
include signal processing, control systems, neural networks, fuzzy logic, communication, Filter
design, and many others.

Dealing with Matrices:

Once you have a matrix, you can refer to specific elements in it. Matlab indexes matrices by row
and column.

c (3, 1) is the element in the third row, 1st column, which is 4.


c(2:3,1:2) gives you the elements in rows 2-3, and columns 1-2, so you get
o 27
o 43
c (1:3,2) gives you the elements in rows 1-3, and the second column, that is, the entire
second column. You can shortcut this to: c(:,2)
You can get a whole row of a matrix with c (1, :) -This literally tells Matlab to take the
first row, all columns.
You can also refer to any matrix with only one index. It will use that index to count down
the columns. c (5) will give you 7, for example.
To multiply, divide, or raise to a power when you have a matrix or vector that is
acting as a set of data points, you need to use.*, ./ or .^, so that Matlab will multiply each
element in the matrix instead of trying to do matrix multiplication or division.
o e.g. generate vector a & perform element to element multiplication with vector v.
Note that dimension of both vectors/ matrices should be equal otherwise it will
give error
o a = [2 3 1 4];
o d = a.*v
o this will result: [4 12 7 20].
It can also treat matrices as actual matrices, so you can solve actual matrices
multiplications, but for that matrices multiplication condition must be satisfied.
o e.g. a*v will give: 43

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:

MATLAB basic functions :

clear % Clear variables and functions from memory.

clc % Clear command window.

zeros(N) % N by N matrix containing zero entries

zeros(N,M) % N by M matrix containing zero entries

ones(N) % N by N unity matrix

ones(N,M) % N by M unity matrix

sin(a) % Trigonometric Function

cos(a) % Trigonometric Function

tan(a) % Trigonometric Function

exp(a) % Exponential Function

log(a) % Logarithmic Function

sqrt(a) % Square root

abs(a) % Absolute value

sign(a) % Sign of scalar

round(a) % Rounding off value

inv(a) % inverse of the square matrix a

eye(n) % n-by-n identity matrix.

eye(m,n) % m-by-n matrix with 1's on the diagonal and zeros


elsewhere.
eye % with no arguments is the scalar 1.

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.

Basic plotting command in MATLAB:

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.

The below command demonstrate the basic idea of plotting a signal.

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.

Block Diagram models

Series Function:

Using series function we can cascade two Transfer, Functions.


For example:

6 Hamza Ahmad
1 1 Then
1

MATLAB Code:

[num,den]= series (num1,den1,num2,den2)

Parallel Function:

MATLAB Code:

[num,den] = parallel (num1, den1, num2, den2)

Closed Loop Function:

The cloop function calculates the closed loop transfer function with unity feedback.

7 Hamza Ahmad

1 1 1 1

MATLAB Code:

[num,den] = cloop (num1, den1, sign)

Feedback Function:

The feedback function calculates the closed loop transfer function with feedback path

8 Hamza Ahmad

1 1 1

1 CS

MATLAB Code:

[num,den] = feedback (num1, den1, num2, den2, sign)

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.

Example 1: Simplifying an expression.

Simplify
- In Matlab command window, we will first need to define alpha as a symbolic expression.

>> alpha = sym('alpha') or >> syms alpha


- Next, we will enter the expression of z:

>> z = sin(alpha)^2 + cos(alpha)^2;


. >> simplify(z)
Matlab will yield "1", as expected: ans = 1
You may also specify the format of the output in symbolic calculation by adding the option as
shown in the example below.
>> syms rho
>> rho=0.25
>> sym(rho,'r')

Where 'r' stands for rational form. Similarly, you may use 'e', 'd' format. Matlab returns:
ans = 1/4

10 Hamza Ahmad
Example 2: Derivative.

We wish to take the derivative of function f(x): :


Matlab command entries:
>> syms x
>> f=x^3-cos(x);
>> g=diff(f)
Matlab returns: g = 3*x^2+sin(x)
Note that the command "diff" was used to obtain the derivative of function f.
Since function f has only one independent variable, the diff command performed the calculation
based on x. If there are more than one independent variable in a function, you should include the
"intended" variable in the following format:
diff(f, x) where x is the "intended" variable.
For example,
We wish to obtain the derivative of the following function:
Matlab command entries:
>> syms x y
>> f=x^2+(y+5)^3;
>> diff(f,y)
Matlab returns: ans = 3*(y+5)^2

Note that in this case, the command diff(f,y) is equivalent to:

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:

Matlab command entry:


>> int(f,y,0,10) Matlab returns: ans = 12500+10*x^2
Laplace Transform:

Laplace transform of a function f(t) is defined as:


where,
Laplace transform of a function f(t) can be obtained with Matlab's function laplace.
Syntax: L =laplace(f)
The usage is demonstrated in the following examples.

11 Hamza Ahmad
Example 1.

Find the Laplace transform of: f(t)=5e-2t


Matlab performs Laplace transform symbolically. Thus, you need to first define the variable t as a
"symbol".
>> syms t
Next, enter the function f(t):
>> f=5*exp(-2*t);
Finally, enter the following command:
>> L=laplace(f)
Matlab yields the following answer: L = 5/(s+2)
You may want to carry out the transformation by hand (or using Laplace transform table) to verify
this result.

Example 2.

Find the Laplace transform of:


In Matlab Command Window:
>> laplace(12*diff(sym('y(t)'),2))
Note that the function y(t) is defined as symbol with the imbedded command "sym". The number 2
means we wish to take the second derivative of the function y(t).
Matlab result: ans = 12*s*(s*laplace(y (t), t,s)-y(0))-12*D(y)(0)
where y(0) is the initial condition.

Example 3.

Find the inverse Laplace transform of:


In Matlab Command window:
>> ilaplace(1/s-2/(s+4)+1/(s+5))
Matlab result: ans = 1-2*exp(-4*t)+exp(-5*t) or
which is the solution of the differential equation

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:

Poles, Zeros and Performance of First Order System.

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

the figure as 63% of the final value are same.

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

Use MATLAB to find the poles and zeros of:

Generate the pzmap as well.

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:

To Study and understand the transient response characteristics of a system.

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:

In this experiment we erudite about the transient response characteristics of a


system.

22 Hamza Ahmad
Lab Report No# 06
Objective:

Time Response of Second order System.

Apparatus:

Personal computer
MATLAB ( version R2011a)

Task # 1

Effect of damping ratio on performance measures. For a single loop second order system given

below.

Find the step response of the system for values of 1 1

Rise
Peak time % Overshoot Settling time(s) Steady state value
time(s)

0.1 1.13 3.14 72.9 38.4 1

0.4 1.88 3.41 25.4 8.41 1

0.7 2.54 4.42 4.6 5.98 1

23
1.0 3.36 7 0 5.83 1

2.0 8.23 24 0 14.9 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:

NV3000-Control System Lab

2. 2 mm patch cords (5)

Circuit diagram:

Procedure:

Make the connections according to the Fig.3.

Connect the NV3000-Control System Lab to AC mains

Switch ON the trainer by Power switch.

Slowly tune the potentiometer and observe the change in intensity of the Lamp-1.

Switch OFF the power switch.

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:

To Study and understand characteristics of DC Motor using NV3000 CSL.

Apparatus:

NV3000-Control System Lab


Oscilloscope
2mm patch cords (3)

Circuit Diagram:

Procedure:

Make the connections according to the above Fig


Connect the NV3000-Control System Lab to AC mains
Switch ON the trainer by Power switch.
Slowly move the pot and set the motor at particular speed.
Connect tp22 (Direction in) to tp6 (De-Bounce switch)
30 Hamza Ahmad
Observation:

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 :

Make the connections according to the figure.


Connect the NV3000-Control System Lab to AC mains.
Switch ON the trainer by Power switch.
Turn voltage POT slowly until the motor begins to rotate. And note down the corresponding Reference
voltage.
Increase the input voltage by slowly turning the Reference voltage POT. For every one volt increment of
the reference voltage (1v, 2v, 3v.), record the corresponding change in voltage on the socket 5
with the help of Digital Voltmeter.
Note down all the readings in table given below
Switch Off the power switch.
Plot a graph on input voltage vs motor speed.

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

Necessary stability conditions


Conditions that must hold for a polynomial to be Hurwitz.If any of them fails - the polynomial is not
stable. However, they may all hold without implying stability.

Sufficient stability conditions


Conditions that if met imply that the polynomial is stable. However, a polynomial may be stable
without implying some or any of them. The Routh criteria provides condition that are both
necessary and sufficient for a polynomial to be Hurwitz.

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

The Routh Array:


The Routh array is formed by taking all the coefficients ai of D(s), and staggering them in array
form. The final columns for each row should contain zeros:

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:

k is the left-most element two rows above the current row.

l is 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:

Figure. Completed Routh Table


The number of roots of the polynomial that are in the right half-plane is equal to the number of
sign changes in the first column of Routh table.
If routh table has a row of zeros then it means it has imaginary poles lying on imaginary axis.

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:

First, find the closed-loop transfer function as:

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:

1. Find the range of K for stability.


2. Find the frequency of oscillation when the system is marginally stable.

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

You might also like