# Matrices and Arrays

Document Sample

					                                   Sixth SEMESTER
LINEAR CONTROL SYSTEMS

COMPUTER SIMULATION LAB
DEPARTMENT OF ELECTRICAL ENGINEERING

Prepared By:                 Checked By:                        Approved By:
Engr. Yasir Naeem            Engr. Waqar Saeed                  Dr.Noman Jafri
Lecturer (Lab) Electrical,   Senior Lect Engineer Electrical,   Dean,

1
Name:___________________________________________

Registration No:__________________________________

Roll No: _________________________________________

Semester: _______________________________________

Batch: __________________________________________

2
Experiment List Linear Control System
S.No               Experiment Name                  O. Marks
1
Introduction to Matlab (Software)
2
LTI Models (Software)
3     Closed Loop Motor Speed Control (Hardware)
(DC Servo Motor)
4     Operation on LTI models, Discreatization
& delay (Software)
5     Closed Loop Position Controller (Hardware)
(DC Servo Motor)
6     Transient Response of Position Controller
(Hardware) (DC Servo Motor)
7     Steady State and Performance Analysis &
8     Transient Response & Gain Effect
(Software)
9     Damping      factor   in   second    order
differential     equation      (Hardware)
(ACM349)
10    Frequency response of Second-Order
system (Hardware) (ACM349)
11    Introduction     to    Roboro    Software
(Software)
12    To Drive Motor Using Time Delay and
Limiting Switch (Hardware) (Robo Pro)
13    To Pick a Job From One Place To Another
(Hardware) (Robo Pro)
14    Time Domain Interpretation of PD, PI,
PID Controller (Software)
15    Root Locus Analysis and frequency
Domain Analysis (Software)
16    Intro PLC Software and Water Level Control
(Software+Hardware) (PLC-T100MD2424)

3
Experiment # 1
Introduction to Matlab
Objective:
To learn the basics of matrix operation and Graph plotting in the matlab.

1. Matlab Operators:
-                       Subtraction
*                       Multiplication
/                       Division
\                       Left division
^                       Power
'                       Complex conjugate transpose
()                      Specify evaluation order
pi                      3.14159265...
i                       Imaginary unit
The list of operators includes
.*                      Element-by-element multiplication
./                      Element-by-element division
.\                      Element-by-element left division
.^                      Element-by-element power

2. Matrices and Arrays:
Start by entering Dürer’s matrix as a list of its elements.
You only have to follow a few basic conventions:

   Separate the elements of a row with blanks or commas.
   Use a semicolon, ; , to indicate the end of each row.
   Surround the entire list of elements with square brackets, [ ].

To enter Dürer’s matrix, simply type in the Command Window

A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]

Now enter the following commands and Compute the results.
>>A
>>sum (A)
>>A’
>>sum (A’)’
>>diag (A)
>>sum (diag (A))

4
>>sum (diag (fliplr(A))

3. Subscripts:
The element in row i and column j of A is denoted by A (i, j). For
example, A(4,2) is the number in the fourth row and second column. For the magic
square, A(4,2) is 15. So to compute the sum of the elements in the fourth column of A,
type

>>A (1, 4) + A (2, 4) + A (3, 4) + A (4, 4)
>>X = A;
>>X (4, 5) = 17
>>1:10
>>A (1: k, j)
>>sum (A (1:4, 4))
>>sum (A (:, end))
>>magic (4)
>>A (:, [1 3 2 4])
>> Z = zeros (2, 4)
>>F = 5*ones (3,3)
>> rand (1, 10)
>> B = [A A+32; A+48 A+16]
>>X (:, 2) = []

4. Linear Algebra:
Symmetric Matrix      A=A’
Skew-Symmetric Matrix A=-A’
Orthogonal Matrix     A*A’=I
>>A+A’
>>eig (A)
>>v=ones (4, 1)
>>A’*A
>>det (A)
>>rref (A)
>>inv (A)
>>poly (A)
>>B (1:2,2:3) = 0

5. Plotting Process:
>>T=0:pi/20:2*pi;
>>Y= (sin (t))
>>Y1=sin (t-0.25)
>>Y2=sin (t-0.5)
>>Plot (t,Y,t,Y1,t,Y2)
>>Stem (t,Y,t,Y1,t,Y2)

5
>>xlabel (‘X axis’)
>>ylabel (‘Plot Y axis’)
>>title (‘Expo Sine Wave’)
>>t = 0:pi/10:2*pi;
>>axis equal

6. Specify Line Style and colour:

.

6
>>legend('sin(x)','sin(x-.25)','sin(x-.5)')
>>T=0:pi/20:2*pi;
>>Y=(sin(t))
>>Plot(t,Y, ’ks’)
>>plot(x,y,'r:+')

7. Displaying Multiple Plots in One Figure:
>>t = 0:pi/10:2*pi;
>>[X,Y,Z] = cylinder(4*cos(t));
>>subplot (2,2,1); mesh(X)
>>subplot (2,2,2); mesh(Y)
>>subplot (2,2,3); mesh(Z)
>>subplot (2,2,4); mesh(X,Y,Z)

8. Setting Axis Limits:
>>axis ([xmin xmax ymin ymax])
>>axis auto
>>axis square
>>axis equal
9. Setting Axis Visibility:
>>axis on
>>axis off
10. Adding Axis Labels and Titles:
>>t = -pi:pi/100:pi;
>>y = sin (t);
>>plot (t, y)
>>axis ([-pi pi -1 1])
>>xlabel ('-\pi \leq {\itt} \leq \pi')
>>ylabel (‘sin (t)')
>>title ('Graph of the sine function')

7
Exercise:

Q-1. Write a mat lab code to generate Durer matrix, sum of first column, sum of
second row, sum of diagonal, sum of anti-diagonal and transpose?

Q-2-a. Write matlab code to generate a 3*3 random matrix, find its determinant,
inverse, and reduce echelon form, rank of the matrix?

2-b. Find out either above matrix is singular or non-singular, symmetric or skew-
symmetric and orthogonal or not?

Q-3-a. To plot sin(x) and cos(x) where x=-Pi: pi/20: Pi writes matlab code to plot in time
domain and frequency domain and also labels, title and limit the axis?

3-b. Also write matlab code to plot above two functions using subplot technique?

8
Experiment # 2
LTI Models

Objective:
To know the Laplace, Inverse Laplace, LTI models and delays.

Laplace and inverse Laplace:
L = laplace(F) is the Laplace transform of the scalar
symbol F with default independent variable t. The default return is a function of s.
The Laplace transform is applied to a function of t and returns a function of s.

f (t) = t4

>>syms t;
>>f=t^4;
>>laplace(f)

F = ilaplace(L) is the inverse Laplace transform of the scalar symbolic object L with
default independent variable s. The default return is a function of t. The inverse
Laplace transform is applied to a function of s and returns a function of t.

h(s)=24/s^5
>>syms s;
>>h = 24/s^5;
>>ilaplace(h)

LTI models:
The Control System Toolbox software provides customized data
structures, known as LTI model objects, for each type of model: tf, zpk, ss, and frd.
These LTI model objects encapsulate the model data. They allow you to manipulate
LTI systems as single entities rather than collections of data vectors or matrices.
Depending on the type of model you use, the data for your model can include:
• One or more numerator/denominator pairs for transfer functions
• Zeros and poles for zero-pole-gain models

 Transfer function Models:
A    continuous-time   transfer   function   in
polynomial form is given by:

9
Create a transfer function model in polynomial form using:

>>G = tf(num,den)

For example, create the transfer function G(s) = s/(s2 + 2s + 1), using:

>>G = tf([1 0],[1 2 1]);

ZPK Model:
A continuous-time transfer function in factorized (zero-pole-gain) form is
given by:

Create transfer functions in factorized (zpk) form using:

>>G = zpk(z, p, k)

For example, the transfer function G(s) = s/(s2 + 2s + 1) in factorized form is given by:

>>G = zpk([0],[-1 -1],[1]);

To create the two-input, one-output MIMO transfer function.

>>g11 = tf([1 -1],[1 1]);
>>g21 = tf([1 2],[1 4 5]);
>>G = [g11; g21];
>>zpk(G)

Data Retrieval:
The output arguments num and den assigned to tfdata and z, p, k
assigned to zpkdata are cell arrays. These cell arrays have as many rows as outputs,
as many columns as inputs. The data can be retrieved from any of the LTI model.

10
>>h=tf([1 3],[1 2 5]);
>>g=zpk(h);
>>[num,den]=tfdata(sys);
>>[num,den]=tfdata(sys,’v’)
>>[z,p,k,Ts]=zpkdata(sys,’v’)

LTI Model Properties:
The various piece of information that can be attached to the
TF or ZPK objects.

>>sys=tf(1,[1 1]);
>>set(sys,’inputname’,’Energy’,’outputname’,’Temperat
ure’,’notes’,’A Simple Heater Model’)
>>get(sys,’notes’)
>>get(sys)

Model Conversion:
Model conversion from one tf model to zpk model or zpk model
to tf model can be done from following commands.
>> sys = tf(num, den) ;
>>sys = zpk(sys)

Delay:
Delay can be introduced on input or output side of the transfer function as
H(s)=( e-0.25s )(10/s2+3s+10)

>>num=[0 10];
>>den=[1 3 10];
>>y=tf(num,den,’inputdelay’,0.25);

11
Exercise:

Q-1. Write code for laplace and inverse laplace transform?
f(t) = e–at

Q-2-a. Write mat lab code to form TF model and covert it into ZPK model?

b. Set the LTI prosperities and retrieve data of TF model and ZPK model?

c. Set input delay of e-0.48s ?

12
Experiment # 3
Closed Loop Motor Speed Control
Objective:
To know the closed loop Motor speed control Technique.
Components:
DC Servo Trainer (ED-4400-B)
U-158          Potentiometer
U-151          Dual Attenuator
U-152          Summing Amplifier
U-153          Pre-Amplifier (20 db)
U-154          Motor Driver Amplifier (10 watts)
U-155          Tacho Am Unit
U-156          DC Power Supply
U-157          Potentiometer (Ref) (1KOhm to 10 KOhm)
U-158          Potentiometer (Motor Coupling) (1KOhm to 10 KOhm)
U-159          Techometer (FS 4000 RPM)
U-161          Servo Motor
U-162          Function Generator
U-163          Magnet Brake
Theory:
When a motor is used as a source of mechanical force, the motor is required to provide
constant speed regardless of the change in load. A closed loop speed control system is a self-
regulating system in which the measured speed of the motor is compared to the preset value to
produce an error output. The detected error voltage is then amplified and fed back to the control
circuit to compensate the difference between the actual and preset speed. The self correcting process
continues until the detected error voltage becomes zero. At this point the actual speed of the motor
is equal to the preset speed
The conceptual difference between an open loop and closed loop system is graphically
illustrated as

13
Procedure:

1. Referring to figure arrange the required modules and connect them together.
2. Set the selector switch of summing amplifier U-152 to ‘a’.
3. Set AAT-2 of the U-151 to ‘10’ to prevent Tacho output from entering the system. Set AAT-
1 to ‘5’.
4. Turn the power of U-156 on.
5. Adjust U-157 to obtain about one half of the maximum speed. This is same as setting for
2500 RPM on U-159 meter.
6. Attach an electronic brake U-163 with the brake’s setting increased by one notch at a time;
record the RPM reading at each setting.
7. Measure the error voltage at each brake setting. (There is no feedback at this point.
Therefore, the error voltage will vary only when the preset speed is changed to a different
value).
8. Set ATT-2 of U-151 to ‘5’. Adjust U-157 to obtain the same speed as in step 5 (around 2500
RPM).
9. Measure the Tacho output and error voltage at different brake points.
10. Compute the results between steps 3-7 and step 8-9. Notice that the loop was closed for
steps 8-9.

14
Experiment 04

Operation on LTI models, Discreatization & delay

Objective:
   To know operation on LTI models .
Operation on LTI models:
The operations that can be performed on the LTI
models are

•      Subtraction of LTI Models.
•       Multiplication of LTI Models.
•       Feedback and Other Interconnection Functions.
•      Continuous/Discrete Conversions of LTI Models.

Adding LTI models is equivalent to connecting them in
parallel. Specifically the LTI model
sys = sys1 + sys2
Represents the parallel interconnection shown below.

Where sys1 = 1/(s +2) and sys2 = 2/(s+3)
>>num1=[1 0];
>>den1=[1 2];
>>num2=[0 2];
>>den2=[1 3];
>>sys1=tf(num1,den1);
>>sys2=tf(num2,den2);
>>sys=sys1+sys2

15
SUBTRACTION OF LTI MODELS:
The subtraction of two LTI models
sys = sys1 - sys2
is depicted by the following block diagram.

MULTIPLCATION OF LTI MODELS:
Multiplication   of   two   LTI   models
connects them in series. Specifically,
sys = sys1*sys2
returns an LTI model for the series interconnection shown below;

FEEDBACK in LTI Models:
The closed-loop model sys has u as input vector
and y as output vector. The LTI models sys1 and sys2 must be both continuous or
both discrete with identical.

>>sys = feedback(sys1,sys2)
To apply positive feedback, use the syntax

16
sys = feedback(sys1,sys2,+1)
>>G = tf([2 5 1],[1 2 3])
>>H = zpk(-2,-10,5)
>>feedback(G,H)
Write the matlab code for Lti models given below

Model interconnection Function:
>>Sys=[sys1,sys2] Horizontal Concatenation
>>Sys=[sys1;sys2] Vertical concatenation
>>Sys=append (sys1,sys2) block diagonal append

Continous/Discreate Conversion Of LTI Models:
The syntax
>>sysd = c2d(sysc,Ts);
Where Ts is the sampling period in seconds
>>sysc=d2c(sysd);

Resampling of Discrete- Time Models
You can resample a discrete-time TF
>>sys2=d2d(sys1,Ts)
>>H = tf([1 0.4],[1 -0.7]);
>>H1=c2dis(H,0.1)
>>H2=d2d(H1,0.25);
Discretization of system with delays:
P = 10 (e-0.25)/ S2+3s+10

This transfer function can be defined as;
>>Num=10;
>>den=[1 3 10];
>>h=tf(num,den,’input delay’,0.25)
>>hd=c2d(h,0.1)

17
Exercise:

Q-1-a. Write code for addition, subtraction, right division, left division and
multiplication of two systems? Sys1 is (f (t) = t4) and sys2 is t0.5?

b. Give feedback to sys2 of sys1 and feedback to sys1 of sys2?

c. Convert the continuous time system into discrete time system?

d. Resample the Above discrete time signal?

e. Also introduce the input delay in discrete time resample system?

18
Experiment # 5
Closed Loop Position Controller

Objective:
To control the speed of close loop position controller.
Components:
DC Servo Trainer (ED-4400-B)
U-158          Potentiometer
U-151          Dual Attenuator
U-152          Summing Amplifier
U-153          Pre-Amplifier (20 db)
U-154          Motor Driver Amplifier (10 watts)
U-155          Tacho Am Unit
U-156          DC Power Supply
U-157          Potentiometer (Ref) (1KOhm to 10 KOhm)
U-158          Potentiometer (Motor Coupling) (1KOhm to 10 KOhm)
U-159          Techometer (FS 4000 RPM)
U-161          Servo Motor
U-162          Function Generator
U-163          Magnet Brake
Theory:
In a close loop position controller system, the positional information from an output
potentiometer (Po) which is mechanically coupled to a motor is fed back to a control amplifier.
Then the reference position input from the input potentiometer (Pi) is combined with the feedback
signal at the input of the amplifier which drives the motor in proportion to the difference between
two signals. When two positions are identical, the output of the amplifier becomes zero.
U-152 is an error signal generator, U-153 is an error signal amplifier and U-154 is the driver for the
motor. As Pi is turned away from Po, the difference between two potentiometer voltages becomes
an error signal which appears at the output of U-152. The error signal is further amplified by U-153
and U-154.

19
Procedure:
1. Referring to figure arrange the required modules and connect them together.
2. Set the selector switch of summing amplifier U-152 to ‘a’ and AAT-2 of the U- 151            to
‘10’. Turn the power of U-156 on. Set U-157 dial to 180 degree.
3. Turn the power of U-156 on.
4. Adjust U-153 to make the output of U-154 zero. Once the adjustment is done, do not alter
U-153 setting.
5. Set U-151 to ‘9’. Within 20 degree from the original 180 degree setting, turn U-157 either
clockwise or anti-clockwise, and see if U-158 follows the movement. U-158 motion should
lag U-157. In case U-158 leads U-157.
6. Turn clockwise from 0 degree position by 10 degree increment up to 150 degrees. Measure
the angle of U-158 at each position of U-157. Repeat the measurements with U-157 turned
counterclockwise. Calculate the error voltage at U-151 center verses angle difference
between U-157 and U-158 at each position.
7. Increase the system gain by setting U-151 to 7, 5, 3, 1. At each U-151 setting, repeat step 6.
Observe the change in error voltage as a function of the system gain.
8. Plot the results of step 6 and 7. Plot the relationships between system gain and error voltage.

20
Experiment # 6
Robotic Arm (Robo Pro)

Objective:
To know how to control the robot in open loop and close loop.

Introduction:
A robotic arm is basically a type of computer numerically controlled machine. We
can also say that robotic arm is a fully controlled Electro-mechanical system. In this robotic arm,
there are four DC motors being used. These motors are separately controlled.
In this module there is a 6 volt DC power supply used to activate this arm. This arm is controlled
with computer. To connect this arm with computer, we need a USB port or a serial port which one
port is available on computer, you can use that port. The serial connector being used is RS-232, for
serial port interface the robot will work on any of COM-1 to COM-4.
There is a power input jack on the back side of this module. There are also two female plug to apply
power and one plug for proper earthing of module. To connect this module with computer, there are
two options.
 USB
 Serial Port (RS-232)
Which ever you like, you can choose.
If you choose the USB port to connect the module with computer, then you have to set the USB
option from the Toolbar. If you want to use RS-232 connection, then same procedure is to be
followed. Just keep in mind to select accurate por from COM-1 to COM-4. When you will select the
connection option from Toolbar then make sure to select the option from module. There are
switches on the module.
 One is for port selection.
 One is for Program mode selection.
From Port selection switch, select the port which you are going to use, the dreen LED will glow and
will indicate the selected port.
 Motor M1:
This motor is used to rotate whole structure. The whole structure can be
rotated in 3600.
 Motor M2:
This motor is used for to and fro movement of the robotic arm If this motor is
driven in clock-wise direction then the arm will move outward and if it is driven in counter clock-
wise direction then the arm will move inwards.
 Motor M3:
This motor is used for up and down movement of robotic arm. If this motor is
driven in clock-wise direction, then arm will move in downward direction and if it is driven in
counter clock-wise direction then the arm will move upward.

21
 Motor M4:
This motor is used to open or close the jaw for job piece. If this motor is
driven clock-wise, then it will close the jaw and if it is driven in counter clock-wise direction then it
will open the jaw.

System Requirement:
   The minimum system requirement for this robot is a PC with Pentium processor with a clock
speed of at least 600MHZ, 32MB RAM and 20MB free disk space.
   A monitor and a graphics card with a resolution of al least 1024*768 pixcels.
   Microsoft Windows, Version 95, 98, NT4.0 or XP.

Procedure:
 To Drive Motor Using Time Delay
1. To drive motor using time delay, connect the robotic arm with computer and apply power supply.
2. Open the Robo pro from start menu.
3. Open a new blank program window.
4. Select the start element from element window and drag it in the work area. You can also just
click on the start element and again click on the desired position in the work area.
5. Select the motor element and place on the desired location in the work area.
6. Select the time delay element and place on the desired location in the work area.
7. Select the stop element and place in the desired location in the work area.
8. Now connect all elements.
9. Now right click on each element and set its properties.
10. Now click on the start button in the Toolbar.
 To Drive Motor Using Limiting Switch:
1. To drive motor using time limiting switch, connect the robotic arm with computer and apply
power supply.
2. Open the Robo pro from start menu.
3. Open a new blank program window.
4. Select the start element from element window and drag it in the work area. You can also just
click on the start element and again click on the desired position in the work area.
5. Select the motor element and place on the desired location in the work area.
6. Select the wait for input from the element window and place on the desired location in work area.
7. Select the stop element and place in the desired location in the work area.
8. Now connect all elements.
9. Now right click on each element and set its properties.
10. Now click on the start button in the Toolbar.

22
Exercise:
Write a programme to place a job piece from a place and put it exactly opposite side of current
position?

23


DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 62 posted: 4/29/2011 language: English pages: 23