0% found this document useful (0 votes)
13 views38 pages

Control Ssytem Lab Manual

The document provides a series of MATLAB programming experiments focused on matrix operations, waveform generation, and pole-zero mapping. It includes syntax explanations, procedures for running the programs, and sample outputs for each experiment. The aim is to familiarize students with MATLAB functions and programming concepts in the context of electronics and communication engineering.

Uploaded by

Saloni Parihar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views38 pages

Control Ssytem Lab Manual

The document provides a series of MATLAB programming experiments focused on matrix operations, waveform generation, and pole-zero mapping. It includes syntax explanations, procedures for running the programs, and sample outputs for each experiment. The aim is to familiarize students with MATLAB functions and programming concepts in the context of electronics and communication engineering.

Uploaded by

Saloni Parihar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 38

INDORE INSTITUTE OF SCIENCE & TECHNOLOGY

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING


Experiment No: - 01

Syntax used in programs:

 clc Clear command window.


clc clears the command window and homes the cursor.

 clear Clear variables and functions from memory.


 clear removes all variables from the workspace. clear VARIABLES does the same thing.
 clear GLOBAL removes all global variables.
 clear FUNCTIONS removes all compiled M- and MEX-functions.
 clear ALL removes all variables, globals, functions and MEX links.
 clear ALL at the command prompt also removes the Java packages import list.
 clear IMPORT removes the Java packages import list at the command prompt. It cannot be
used in a function.

 close Close figure.


 close(H) closes the window with handle H.
 CLOSE, by itself, closes the current figure window.
 close('name') closes the named window.
 close ALL closes all the open figure windows.
 close ALL HIDDEN closes hidden windows as well.
 STATUS = close(...) returns 1 if the specified windows were closed and 0 otherwise.

 subplot Create axes in tiled positions.

H = subplot(m,n,p) or subplot(mnp), breaks the Figure window into an m-by-n matrix of


small axes, selects the p-th axes for the current plot, and returns the axis handle. The axes are
counted along the top row of the Figure window, then the second row, etc. For example,
subplot(2,1,1), PLOT(income)
subplot(2,1,2), PLOT(outgo)
Plots income on the top half of the window and outgo on the bottom half.

 stem Discrete sequence or "stem" plot.


stem(Y) plots the data sequence Y as stems from the x axis terminated with circles for the data
value.
stem(X,Y) plots the data sequence Y at the values specified in X.
H = stem(...) returns a vector of line handles.

 xlabel X-axis label.


xlabel('text') adds text beside the X-axis on the current axis.
xlabel('text','Property1',PropertyValue1,'Property2',PropertyValue2,...) sets the values of the
specified properties of the xlabel.
H = xlabel(...) returns the handle to the text object used as the label.

 ylabel Y-axis label.


ylabel('text') adds text beside the Y-axis on the current axis.

1
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
ylabel('text','Property1',PropertyValue1,'Property2',PropertyValue2,...) sets the values of the
specified properties of the ylabel.
H = ylabel(...) returns the handle to the text object used as the label.

 zeros Zeros array.


zeros(N) is an N-by-N matrix of zeros. zeros(M,N) or zeros([M,N]) is an M-by-N matrix of zeros.
zeros(M,N,P,...) or zeros([M N P ...]) is an M-by-N-by-P-by-... array of zeros.

 ones Ones array.


ones(N) is an N-by-N matrix of ones. ones(M,N) or ones([M,N]) is an M-by-N matrix of
ones.ones(M,N,P,...) or ones([M N P ...]) is an M-by-N-by-P-by-... array of ones.

 input Prompt for user input.


R = input('How many apples') gives the user the prompt in the text string and then waits for
input from the keyboard. The input can be any MATLAB expression, which is evaluated, using
the variables in the current workspace, and the result returned in R. If the user presses the
return key without entering anything, input returns an empty matrix.

 exp Exponential.
exp(X) is the exponential of the elements of X, e to the X. For complex Z=X+i*Y, exp(Z) =
exp(X)*(COS(Y)+i*SIN(Y)).

 cos Cosine.
cos(X) is the cosine of the elements of X.

 sin Sine.
sin(X) is the sine of the elements of X.

 plot Linear plot.


plot(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the
rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, length(Y)
disconnected points are plotted.

 WHILE Repeat statements an indefinite number of times.


The general form of a WHILE statement is:

WHILE expression
statements
END

The statements are executed while the real part of the expression has all non-zero elements.
The expression is usually the result of expr rop expr where rop is ==, <, >, <=, >=, or ~=.

The BREAK statement can be used to terminate the loop prematurely.

2
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 01

AIM: - To write a MATLAB program for the Matrix Operation like Addition, Subtraction,
Multiplication and Division using If Else Statement.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-

clear all
% Matrix operation Using ifelse
function[]=exp1()
a= input('Enter the first Matrix Like [a b c; d e f; g h i] \n a = ')
b=input ('Enter the Second Matrix Like [a b c; d e f; g h i] \n b = ')
i='y';
while(i=='y')
c= input('Press \n 1. Addition \n 2. Multiplication \n 3. Subtarction \n 4. Exit \n Enter your
choice......... ');
if (c==1)
d=a+b;
elseif(c==2)
d=a*b;
elseif(c==3)
d=a-b;
elseif (c==4)
break;
else
display('Wrong choice')
end
display('Answer will be \n')
d
i=input('Do you want to cont......? \n Press (y/n)', 's');
end

OUTPUT:
>> exp1

Enter the first Matrix Like [a b c; d e f; g h i]


a = [1 2 3;4 5 6; 7 8 9]
a=

3
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
1 2 3
4 5 6
7 8 9

Enter the Second Matrix Like [a b c; d e f; g h i]


b = [1 3 5 ; 2 4 6 ; 7 9 11]

b=
1 3 5
2 4 6
7 9 11

Press
1. Addition
2. Multiplication
3. Subtraction
4. Exit

Enter your choice......... 1

Answer will be

d=

2 5 8
6 9 12
14 17 20

Do you want to continue......?

Press (y/n)

Experiment No: - 02

4
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Syntax used in program:

 xcorr Cross-correlation function estimates.


C = xcorr(A,B), where A and B are length M vectors (M>1), returns the length 2*M-1 cross-
correlation sequence C. If A and B are of different length, the shortest one is zero-padded. C will
be a row vector if A is a row vector, and a column vector if A is a column vector.
xcorr produces an estimate of the correlation between two random (jointly stationary)
sequences:
C(m) = E[A(n+m)*conj(B(n))] = E[A(n)*conj(B(n-m))]

It is also the deterministic correlation between two deterministic signals.


xcorr(A), when A is a vector, is the auto-correlation sequence. xcorr(A), when A is an M-by-N
matrix, is a large matrix with 2*M-1 rows whose N^2 columns contain the cross-correlation
sequences for all combinations of the columns of A. The zeroth lag of the output correlation is in
the middle of the sequence, at element or row M.

 disp Display array.

disp(X) displays the array, without printing the array name. In all other ways it's the same as
leaving the semicolon off an expression except that empty arrays don't display. If X is a string,
the text is displayed.

 fliplr Flip matrix in left/right direction.

fliplr(X) returns X with row preserved and columns flipped in the left/right direction.
X = 1 2 3 becomes 3 2 1
456 654

 SWITCH Switch among several cases based on expression.


The general form of the SWITCH statement is:

SWITCH switch_expr
CASE case_expr,
statement, ..., statement
CASE {case_expr1, case_expr2, case_expr3,...}
statement, ..., statement
...
OTHERWISE,
statement, ..., statement
END

Experiment No: - 02
5
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

AIM: - To write a MATLAB program for Generating different type of waveform using Switch
Statement.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window
PROGRAM:-

clear all

% Different type of Waveform generation

function[]=exp2()
a=input('Enter the range of the cycle or Enter X-Axis Range for the Waveform \n a = ');
i='y';
while(i=='y')
b=input('Press ....\n 1.Sine Waveform \n 2.Cosine Waveform \n 3.Exp. Waveform \n 4.Unit Step
Signal \n 5.Ramp Signal \n 6.Exit \n Enter Your Choice.......');
t=-a*pi:0.1:a*pi;
t1=0:1:a-1;

switch(b)

case 1
f=sin(t);
a1=plot(t,f)
xlabel('Time')
ylabel('sin(t)')
grid
title('Sine Waveform')

case 2
f=cos(t);
a2=plot(t,f)
xlabel('Time')
ylabel('cos(t)')
grid
title('Cosine Waveform')

case 3
b=input('enter the value of b for e^bt \n b = ');
f=exp(b*t);

6
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
a3=plot(t,f)
xlabel('Time')
ylabel('exp(b*t)')
grid
title('Exp. Waveform')

case 4
f=ones(1,a);
a4=plot(t1,f)
xlabel('Time')
ylabel('u(t)')
grid
title('Unit step signal')

case 5
a5=plot(t1,t1)
xlabel('Time')
ylabel('r(t)')
grid
title('Ramp Signal')

case 6
break;

otherwise
display('Wrong Choice')
end
i=input('Do you want to cont...... ? \n Press (y/n)', 's');
end

OUTPUT:

>> exp2
Enter the range of the cycle or Enter X-Axis Range for the Waveform
a= 2

Press....

1. Sine Waveform
2. Cosine Waveform
3. Exp. Waveform
4. Unit step Signal
5. Ramp Signal
6. Exit

Enter Your Choice.......2

7
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

Do you want to Cont......?

Press (y/n)

8
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 03

Syntax used in programs:

 INPUT Prompt for user input.


R = INPUT('How many apples') gives the user the prompt in the text string and then waits
for input from the keyboard.
The input can be any MATLAB expression, which is evaluated, using the variables in the
current workspace, and the result returned in R. If the user presses the return key without
entering anything, INPUT returns an empty matrix.

R = INPUT('What is your name','s') gives the prompt in the text string and waits for
character string input. The typed input is not evaluated; the characters are simply
returned as a MATLAB string.

The text string for the prompt may contain one or more '\n'. The '\n' means skip to the
beginning of the next line. This allows the prompt string to span several lines. To output
just a '\' use '\\'.

 PZMAP Pole-zero map of LTI models.

PZMAP(SYS) computes the poles and (transmission) zeros of the LTI model
SYS and plots them in the complex plane. The poles are plotted as x's and the zeros
are plotted as o's.

PZMAP(SYS1,SYS2,...) shows the poles and zeros of multiple LTI models


SYS1,SYS2,... on a single plot. You can specify distinctive colors for each model, as in
pzmap(sys1,'r',sys2,'y',sys3,'g')

[P,Z] = PZMAP(SYS) returns the poles and zeros of the system in two
column vectors P and Z. No plot is drawn on the screen.

The functions SGRID or ZGRID can be used to plot lines of constant damping
ratio and natural frequency in the s or z plane.

 DISP Display array.


DISP(X) displays the array, without printing the array name. In all other ways it's
the same as leaving the semicolon off an expression except that empty arrays don't
display. If X is a string, the text is displayed.

9
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

Experiment No: - 03

AIM: - To write a MATLAB program for different find pole zero and draw pole zero graph for the
given function?.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-
clc
clear all
n=input('Enter the coefficient of numerator as^2 + bs + c like [a b c] = ');
d=input('Enter the coefficient of numerator as^2 + bs + c like [a b c] = ');
display(' Transfer Function will be : ')
sys=tf(n,d)
sgrid
[p z] = pzmap(sys)
pzmap(sys)

OUTPUT
Enter the coefficient of numerator as^2 + bs + c like [a b c] = [ 2 4 6 8]
Enter the coefficient of numerator as^2 + bs + c like [a b c] = [ 1 2 3]
Transfer Function will be :

Transfer function:
2 s^3 + 4 s^2 + 6 s + 8
-----------------------
s^2 + 2 s + 3

p=

-1.0000 + 1.4142i
-1.0000 - 1.4142i

z=

-1.6506
-0.1747 + 1.5469i
-0.1747 - 1.5469i

10
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

>>

11
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 04

Syntax used in programs:

 SERIES Series interconnection of the two LTI models.

SYS = SERIES(SYS1,SYS2,OUTPUTS1,INPUTS2) connects two LTI models SYS1 and SYS2 in


series such that the outputs of SYS1 specified by OUTPUTS1 are connected to the inputs of
SYS2 specified by INPUTS2.The vectors OUTPUTS1 and INPUTS2 contain indices into the
outputs and inputs of SYS1 and SYS2, respectively. The resulting LTI model SYS maps u1 to
y2.
If OUTPUTS1 and INPUTS2 are omitted, SERIES connects SYS1 and SYS2 in cascade and
returns SYS = SYS2 * SYS1 .

SYS = SERIES(SYS1,SYS2,'name') connects SYS1 and SYS2 by matching I/O names. The
output names of SYS1 and input names of SYS2 should be fully specified.

If SYS1 and SYS2 are arrays of LTI models, SERIES returns an LTI array SYS of the same size
where SYS(:,:,k) = SERIES(SYS1(:,:,k),SYS2(:,:,k),OUTPUTS1,INPUTS2) .

 PARALLEL Parallel interconnection of two LTI models.

SYS = PARALLEL(SYS1,SYS2,IN1,IN2,OUT1,OUT2) connects the two LTI


models SYS1 and SYS2 in parallel such that the inputs specified by IN1 and IN2 are
connected and the outputs specified by OUT1 and OUT2 are summed. The resulting
LTI model SYS maps [v1;u;v2] to [z1;y;z2]. The vectors IN1 and IN2 contain indexes
into the input vectors of SYS1 and SYS2, respectively, and define the input channels
u1 and u2 in the diagram. Similarly, the vectors OUT1 and OUT2 contain indexes
into the outputs of these two systems.

If IN1,IN2,OUT1,OUT2 are jointly omitted, PARALLEL forms the standard


parallel interconnection of SYS1 and SYS2 and returns
SYS = SYS2 + SYS1 .

SYS = PARALLEL(SYS1,SYS2,'name') connects SYS1 and SYS2 by matching


I/O names. The I/O name of SYS1 and SYS2 should be fully specified.

 FEEDBACK Feedback connection of two LTI models.

SYS = FEEDBACK(SYS1,SYS2) computes an LTI model SYS for the closed-loop


feedback system. Negative feedback is assumed and the resulting system SYS maps
u to y. To apply positive feedback, use the syntax
SYS = FEEDBACK(SYS1,SYS2,+1).

SYS = FEEDBACK(SYS1,SYS2,FEEDIN,FEEDOUT,SIGN) builds the more general


feedback interconnection.

12
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 04

AIM: - To write a MATLAB program for reduction of block diagram using block diagram reduction
techniques.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-

clc
clear all
n=input('Enter the coefficient of numerator as^2 + bs + c like [a b c] = ');
d=input('Enter the coefficient of denominator as^2 + bs + c like [a b c] =');
sys1=tf(n,d)
n1=input('Enter the coefficient of numerator as^2 + bs + c like [a b c] = ');
d1=input('Enter the coefficient of denominator as^2 + bs + c like [a b c]=');
sys2=tf(n1,d1)
n2=input('Enter the coefficient of numerator as^2 + bs + c like [a b c] =');
d2=input('Enter the coefficient of denominator as^2 + bs + c like [a b c]=');
sys3=tf(n2,d2)
n3=input('Enter the coefficient of numerator as^2 + bs + c like [a b c] =');
d3=input('Enter the coefficient of denominator as^2 + bs + c like [a b c]=');
sys4=tf(n3,d3)
display(' Transfer Function will be : ')
ans1=series(sys1,sys2);
ans2=parallel(ans1,sys3);
ans3=feedback(ans2, sys4,-1)

OUTPUT

Enter the coefficient of numerator as^2 + bs + c like [a b c] = [1 2]


Enter the coefficient of numerator as^2 + bs + c like [a b c] = [1 2 3]

Transfer function:
s+2
-------------
s^2 + 2 s + 3

Enter the coefficient of numerator as^2 + bs + c like [a b c] = [1]


Enter the coefficient of numerator as^2 + bs + c like [a b c] = [1 2 3]

13
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

Transfer function:
1
-------------
s^2 + 2 s + 3

Enter the coefficient of numerator as^2 + bs + c like [a b c] = [1]


Enter the coefficient of numerator as^2 + bs + c like [a b c] = [1 2 3]

Transfer function:
1
-------------
s^2 + 2 s + 3

Enter the coefficient of numerator as^2 + bs + c like [a b c] = [1]


Enter the coefficient of numerator as^2 + bs + c like [a b c] = [1 2 3]

Transfer function:
1
-------------
s^2 + 2 s + 3

Transfer Function will be :

Transfer function:
s^6 + 7 s^5 + 27 s^4 + 62 s^3 + 95 s^2 + 87 s + 45
-------------------------------------------------------------------------
s^8 + 8 s^7 + 36 s^6 + 104 s^5 + 215 s^4 + 317 s^3 + 338 s^2 + 235 s + 96

>>

14
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 05

Syntax used in programs:

 BODE Bode frequency response of LTI models.

BODE(SYS) draws the Bode plot of the LTI model SYS (created with either TF, ZPK, SS, or
FRD). The frequency range and number of points are chosen automatically.

BODE(SYS,{WMIN,WMAX}) draws the Bode plot for frequencies between WMIN and
WMAX (in radians/second).

BODE(SYS,W) uses the user-supplied vector W of frequencies, in radian/second, at which


the Bode response is to be evaluated. See LOGSPACE to generate logarithmically spaced
frequency vectors.

BODE(SYS1,SYS2,...,W) graphs the Bode response of multiple LTI models SYS1,SYS2,... on a


single plot. The frequency vector W is optional. You can specify a color, line style, and
marker for each model, as in bode(sys1,'r',sys2,'y--',sys3,'gx').

[MAG,PHASE] = BODE(SYS,W) and [MAG,PHASE,W] = BODE(SYS) return the response


magnitudes and phases in degrees (along with the frequency vector W if unspecified). No
plot is drawn on the screen.

If SYS has NY outputs and NU inputs, MAG and PHASE are arrays of size [NY NU
LENGTH(W)] where MAG(:,:,k) and PHASE(:,:,k) determine the response at the frequency
W(k). To get the magnitudes in dB, type MAGDB = 20*log10(MAG).

For discrete-time models with sample time Ts, BODE uses the transformation Z =
exp(j*W*Ts) to map the unit circle to the real frequency axis. The frequency response is
only plotted for frequencies smaller than the Nyquist frequency pi/Ts, and the default value
1 (second) is assumed when Ts is unspecified.

15
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 05

AIM: - To write a MATLAB program for draw a bode plot and show effect of addition of poles and
Zeros?.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-
clc
clear all
n=input('Enter the coefficient of numerator as^2 + bs + c like [a b c] = ');
d=input('Enter the coefficient of denominator as^2 + bs + c like [a b c] = ');
display(' Transfer Function will be : ')
sys=tf(n,d)
b=1;
while b==1
a=input('Press 1. Bode plot \n 2. add pole \n 3. add zero \n 4. Exit \n Enter your choices') ;

switch a
case 1
display('Bode Plot will be: ')

bode(sys)
case 2
d1=input('Enter the coefficient of denominator as^2 + bs + c like [a b c] = ');
sys=tf(n,d1)
display('Bode Plot will be: ')

bode(sys)
case 3
n1=input('Enter the coefficient of numerator as^2 + bs + c like [a b c] = ');
sys=tf(n1,d)
display('Bode Plot will be: ')

bode(sys)
otherwise
break

end
b= input(' Do you want to continuous press 1 otherwise press 2 =');
end

16
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

OUTPUT

Enter the coefficient of numerator as^2 + bs + c like [a b c] = 1


Enter the coefficient of denominator as^2 + bs + c like [a b c] = [1 2 3]
Transfer Function will be :

Transfer function:
1
-------------
s^2 + 2 s + 3

Press 1. Bode plot


2. add pole
3. add zero
4. Exit
Enter your choices1
Bode Plot will be:
Do you want to continuous press 1 otherwise press 2 =

Do you want to continuous press 1 otherwise press 2 =1


Press 1. Bode plot
2. add pole
17
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
3. add zero
4. Exit
Enter your choices2
Enter the coefficient of denominator as^2 + bs + c like [a b c] = [ 2 4 6 8]

Transfer function:
1
-----------------------
2 s^3 + 4 s^2 + 6 s + 8

Bode Plot will be:


Do you want to continuous press 1 otherwise press 2 =2

>>

18
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 06

Syntax used in programs:

 NYQUIST Nyquist frequency response of LTI models.

NYQUIST(SYS) draws the Nyquist plot of the LTI model SYS (created with either TF, ZPK, SS,
or FRD). The frequency range and number of points are chosen automatically. See BODE
for details on the notion of frequency in discrete-time.

NYQUIST(SYS,{WMIN,WMAX}) draws the Nyquist plot for frequencies between WMIN and
WMAX (in radians/second).

NYQUIST(SYS,W) uses the user-supplied vector W of frequencies (in radian/second) at


which the Nyquist response is to be evaluated. See LOGSPACE to generate logarithmically
spaced frequency vectors.

NYQUIST(SYS1,SYS2,...,W) plots the Nyquist response of multiple LTI models SYS1,SYS2,...


on a single plot. The frequency vector W is optional. You can also specify a color, line style,
and marker for each system, as in nyquist(sys1,'r',sys2,'y--',sys3,'gx').

[RE,IM] = NYQUIST(SYS,W) and [RE,IM,W] = NYQUIST(SYS) return the real parts RE and
imaginary parts IM of the frequency response (along with the frequency vector W if
unspecified). No plot is drawn on the screen. If SYS has NY outputs and NU inputs, RE and
IM are arrays of size [NY NU LENGTH(W)] and the response at the frequency W(k) is given
by RE(:,:,k)+j*IM(:,:,k).

19
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 06

AIM: - To write a MATLAB program for draw a Nyquist plot and show effect of addition of poles and
Zeros?.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-

clc
clear all
n=input('Enter the coefficient of numerator as^2 + bs + c like [a b c] = ');
d=input('Enter the coefficient of denominator as^2 + bs + c like [a b c]= ');
display(' Transfer Function will be : ')
sys=tf(n,d)
b=1;
while b==1
a=input('Press 1. Nyquist plot \n 2. add pole \n 3. add zero \n 4. Exit \n Enter your choices') ;

switch a
case 1
display('Nyquist Plot will be: ')

nyquist(sys)
case 2
d1=input('Enter the coefficient of denominator as^2 + bs + c like [a b c] = ');
sys=tf(n,d1)
display('Nyquist Plot will be: ')

nyquist(sys)
case 3
n1=input('Enter the coefficient of numerator as^2 + bs + c like [a b c] = ');
sys=tf(n1,d)
display('Nyquist Plot will be: ')

nyquist(sys)

otherwise
break

end

20
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
b= input (' Do you want to continuous press 1 otherwise press 2 =');
end

OUTPUT

Enter the coefficient of numerator as^2 + bs + c like [a b c] = 1


Enter the coefficient of denominator as^2 + bs + c like [a b c] = [1 2]
Transfer Function will be :

Transfer function:
1
-----
s+2

Press 1. Nyquist plot


2. add pole
3. add zero
4. Exit
Enter your choices1
Nyquist Plot will be:
Do you want to continuous press 1 otherwise press 2 =

Do you want to continuous press 1 otherwise press 2 =1


Press 1. Nyquist plot
21
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
2. add pole
3. add zero
4. Exit
Enter your choices2
Enter the coefficient of denominator as^2 + bs + c like [a b c] = [1 3 2]

Transfer function:
1
-------------
s^2 + 3 s + 2

Nyquist Plot will be:


Do you want to continuous press 1 otherwise press 2 =

22
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 07

Syntax used in programs:

 RLOCUS Evans root locus.

RLOCUS(SYS) computes and plots the root locus of the single-input, single-output LTI
model SYS. The root locus plot is used to analyze the negative feedback loop and shows
the trajectories of the closed-loop poles when the feedback gain K varies from 0 to Inf.
RLOCUS automatically generates a set of positive gain values that produce a smooth plot.

RLOCUS(SYS,K) uses a user-specified vector K of gain values.

RLOCUS(SYS1,SYS2,...) draws the root loci of multiple LTI models SYS1, SYS2,... on a
single plot. You can specify a color, line style, and marker for each model, as in
rlocus(sys1,'r',sys2,'y:',sys3,'gx').

[R,K] = RLOCUS(SYS) or R = RLOCUS(SYS,K) returns the matrix R of complex root


locations for the gains K. R has LENGTH(K) columns and its j-th column lists the closed-
loop roots for the gain K(j).

23
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 07

AIM: - To write a MATLAB program for draw a Root Locus and show effect of addition of poles and
Zeros?.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-

clc
clear all
n=input('Enter the coefficient of numerator as^2 + bs + c like [a b c] = ');
d=input('Enter the coefficient of denominator as^2 + bs + c like [a b c = ');
display(' Transfer Function will be : ')
sys=tf(n,d)
b=1;
while b==1
a=input('Press 1. Root Locus \n 2. add pole \n 3. add zero \n 4. Exit \n Enter your choices') ;

switch a
case 1
display('Root Locus will be: ')

rlocus(sys)
case 2
d1=input('Enter the coefficient of denominator as^2 + bs + c like [a b c] = ');
sys=tf(n,d1)
display('Root Locus will be: ')

rlocus(sys)
case 3
n1=input('Enter the coefficient of numerator as^2 + bs + c like [a b c] = ');
sys=tf(n1,d)
display('Root Locus will be: ')
rlocus(sys)
otherwise
break

end
b= input(' Do you want to continuous press 1 otherwise press 2 =');
end

24
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
OUTPUT

Enter the coefficient of numerator as^2 + bs + c like [a b c] = [1 2]


Enter the coefficient of denominator as^2 + bs + c like [a b c] = [1 2 3 4]
Transfer Function will be :

Transfer function:
s+2
---------------------
s^3 + 2 s^2 + 3 s + 4

Press 1. Root Locus


2. add pole
3. add zero
4. Exit
Enter your choices1
Root Locus will be:
Do you want to continuous press 1 otherwise press 2 =

Do you want to continuous press 1 otherwise press 2 =1


Press 1. Root Locus
2. add pole
3. add zero
4. Exit
25
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Enter your choices2
Enter the coefficient of denominator as^2 + bs + c like [a b c] = [1 2 3 2 1]

Transfer function:
s+2
-----------------------------
s^4 + 2 s^3 + 3 s^2 + 2 s + 1

Root Locus will be:


Do you want to continuous press 1 otherwise press 2 =2

>>

26
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 08

Syntax used in programs:

 LTIVIEW Opens the LTI Viewer GUI.

LTIVIEW opens an empty LTI Viewer. The LTI Viewer is an interactive graphical user
interface (GUI) for analyzing the time and frequency responses of linear systems and
comparing such systems. See LTIMODELS for details on how to model linear systems in the
Control System Toolbox.

LTIVIEW(SYS1,SYS2,...,SYSN) opens an LTI Viewer containing the step response of the LTI
models SYS1,SYS2,...,SYSN. You can specify a distinctive color, line style, and marker for
each system, as in
sys1 = rss(3,2,2);
sys2 = rss(4,2,2);
ltiview(sys1,'r-*',sys2,'m--');

LTIVIEW(PLOTTYPE,SYS1,SYS2,...,SYSN) further specifies which responses to plot in the LTI


Viewer. PLOTTYPE may be any of the following strings (or a combination thereof):

1) 'step' Step response


2) 'impulse' Impulse response
3) 'lsim' Linear simulation plot
4) 'initial' Initial condition plot
5) 'bode' Bode diagram
6) 'bodemag' Bode Magnitude diagram
7) 'nyquist' Nyquist plot
8) 'nichols' Nichols plot
9) 'sigma' Singular value plot
10) 'pzmap' Pole/Zero map
11) 'iopzmap' I/O Pole/Zero map

27
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 08

AIM: - To write a MATLAB program to find time response (Step Response and Impulse Response)
of the system using LTIVIEW Command?

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-

clc
clear all
x=1;
e=input('Enter the value of damping= ' );
w=input('Enter the value of wn undamped Frequency= ');
k=input('Enter the gain of the system= ');
n=[w*w*k];
d=[1 2*e*w w*w];
a=tf(n,d)
while (x==1)
b=input(' Press 1. Step Response \n 2. Impulse Response \n 3. Bode Plot \n 4. Nyquist plot \n 5.
Pole Zero \n 6. Exit \n Enter your Choice’);
switch b
case 1
display('Step Response will be ')
ltiview ('step',a);
case 2
display('Impulse Response will be ')
ltiview ('impulse’, a);
case 3
display('Bode Plot will be ')
ltiview ('bode’, a);
case 4
display('Nyquist plot will be ')
ltiview ('nyquist',a);
case 5
display('Pole Zero graph will be ')
ltiview ('pzmap',a);
otherwise
break;
x= input(' Do you Want to Continuous Press 1 otherwise 2');
end

28
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
end

OUTPUT

Enter the value of damping= 0.6


Enter the value of wn undamped Frequency= 10
Enter the gain of the system= 1

Transfer function:
100
----------------
s^2 + 12 s + 100

Press 1. Step Response


2. Impulse Response
3. Bode Plot
4. Nyquist plot
5. Pole Zero
6. Exit
Enter your Choice1
Step Response will be
Press 1. Step Response
2. Impulse Response
3. Bode Plot
4. Nyquist plot
5. Pole Zero
6. Exit
Enter your Choice

Enter your Choice2


Impulse Response will be
Press 1. Step Response

29
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
2. Impulse Response
3. Bode Plot
4. Nyquist plot
5. Pole Zero
6. Exit
Enter your Choice6

30
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 09

Syntax used in programs:

 SS Creates state-space model or converts model to state space.

SYS = SS(A,B,C,D) creates a SS object SYS representing the continuous-time state-


space model
dx/dt = Ax(t) + Bu(t)
y(t) = Cx(t) + Du(t)
You can set D=0 to mean the zero matrix of appropriate dimensions. If one or
more of the matrices A,B,C,D have uncertainty, SS returns an uncertain state-space
(USS) model (Robust Control Toolbox only).

SYS = SS(A,B,C,D,Ts) creates a discrete-time state-space model with sample time Ts


(set Ts=-1 if the sample time is undetermined).

SYS = SS creates an empty SS object.

SYS = SS(D) specifies a static gain matrix D.

 ILAPLACE Inverse Laplace transform.

F = ILAPLACE(L) is the inverse Laplace transform of the scalar sym L with default
independent variable s. The default return is a function of t. If L = L(t), then
ILAPLACE returns a function of x:
F = F(x).
By definition, F(t) = int(L(s)*exp(s*t),s,c-i*inf,c+i*inf) where c is a real number
selected so that all singularities of L(s) are to the left of the line s = c, i = sqrt(-1), and
the integration is taken with respect to s.

F = ILAPLACE(L,y) makes F a function of y instead of the default t:


ILAPLACE(L,y) <=> F(y) = int(L(y)*exp(s*y),s,c-i*inf,c+i*inf).
Here y is a scalar sym.

F = ILAPLACE(L,y,x) makes F a function of x instead of the default t:


ILAPLACE(L,y,x) <=> F(y) = int(L(y)*exp(x*y),y,c-i*inf,c+i*inf),integration is taken
with respect to y.

31
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 09

AIM: - To write a MATLAB program to find State transition response , Zero input Response and
Zero State Response in State Space Analysis.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-

clc
clear all;
x=1
display(' Welcome to the world of state space analysis');
a= input(' Enter the Matrix A in Square Form Like 2*2 or 3*3 = ');
b= input(' Enter the Matrix B in n*1 where n will be Size of Matrix A = ');
c=input(' Enter the Matrix C in 1*n where n will be size of Matriz A = ');
d=[0];
x= input('Enter the Initial Value of X(0) in 1* n where n will be size of Matriz A = ');
sys=ss(a,b,c,d);
i=[1 0; 0 1];
syms s;
lti=(((s*i)-(a))^-1);
ans=[ilaplace(lti(1,1)) ilaplace(lti(1,2));ilaplace(lti(2,1)) ilaplace(lti(2,2))];
while (x==1)
b=input(' Press 1. State Transition Matrix \n 2. Zero Input Response \n 3. Zero State Response \n 4.
Total Response \n 5. Exit \n Enter your Choice' );
switch b
case 1
display(' State Transition Matrix will be :');
ans
case 2
display(' Zero Input Response will be :');
ans1=ans*x
case 3
display(' Zero State Response will be :');
w=lti*b*(1/s);
ans2=[ilaplace(w(1,1));ilaplace(w(2,1))]
case 4
w=lti*b*(1/s);
ans2=[ilaplace(w(1,1));ilaplace(w(2,1))];

32
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
ans1=ans*x;
display(' Total Response will be :');
ans3=ans1+ans2
otherwise
break;
end
end

OUTPUT

Welcome to the world of state space analysis


Enter the Matrix A in Square Form Like 2*2 or 3*3 = [1 2 ; 1 1 ]
Enter the Matrix B in n*1 where n will be Size of Matrix A = [1; 2]
Enter the Matrix C in 1*n where n will be size of Matriz A = [1 2 ]
Enter the Initial Value of X(0) in 1* n where n will be size of Matriz A = [1; 1]
Press 1. State Transition Matrix
2. Zero Input Response
3. Zero State Response
4. Total Response
5. Exit
Enter your Choice1
State Transition Matrix will be :

ans =

[ exp(t)*cosh(t*2^(1/2)), 2^(1/2)*exp(t)*sinh(t*2^(1/2))]
[ 1/2*2^(1/2)*exp(t)*sinh(t*2^(1/2)), exp(t)*cosh(t*2^(1/2))]

Press 1. State Transition Matrix


2. Zero Input Response
3. Zero State Response
4. Total Response
5. Exit
Enter your Choice2
Zero Input Response will be :

ans1 =

exp(t)*cosh(t*2^(1/2))+2^(1/2)*exp(t)*sinh(t*2^(1/2))
1/2*2^(1/2)*exp(t)*sinh(t*2^(1/2))+exp(t)*cosh(t*2^(1/2))

Press 1. State Transition Matrix


2. Zero Input Response
3. Zero State Response
4. Total Response

33
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
5. Exit
Enter your Choice3
Zero State Response will be :

ans2 =

3+3*exp(t)*(-cosh(t*2^(1/2))+2^(1/2)*sinh(t*2^(1/2)))
-3+3/2*(2*cosh(t*2^(1/2))-2^(1/2)*sinh(t*2^(1/2)))*exp(t)

Press 1. State Transition Matrix


2. Zero Input Response
3. Zero State Response
4. Total Response
5. Exit
Enter your Choice4
Total Response will be :

ans3 =

exp(t)*cosh(t*2^(1/2))+2^(1/2)*exp(t)*sinh(t*2^(1/2))+4+4*exp(t)*(-cosh(t*2^(1/2))
+2^(1/2)*sinh(t*2^(1/2)))
1/2*2^(1/2)*exp(t)*sinh(t*2^(1/2))+exp(t)*cosh(t*2^(1/2))-4+2*(2*cosh(t*2^(1/2))-
2^(1/2)*sinh(t*2^(1/2)))*exp(t)

Press 1. State Transition Matrix


2. Zero Input Response
3. Zero State Response
4. Total Response
5. Exit
Enter your Choice5
>>

34
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 10

Syntax used in programs:

 ATAN Inverse tangent, result in radians.


ATAN(X) is the arctangent of the elements of X.

 SQRT Square root.


SQRT(X) is the square root of the elements of X. Complex results are produced if X is
not positive.

 EXP Exponential.
EXP(X) is the exponential of the elements of X, e to the X.
For complex Z=X+i*Y, EXP(Z) = EXP(X)*(COS(Y)+i*SIN(Y)).

 PI 3.1415926535897....
PI = 4*atan(1) = imag(log(-1)) = 3.1415926535897....

 BREAK Terminate execution of WHILE or FOR loop.


BREAK terminates the execution of FOR and WHILE loops.
In nested loops, BREAK exits from the innermost loop only.

BREAK is not defined outside of a FOR or WHILE loop. Use RETURN in this context
instead.

35
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 10

AIM: - To write a MATLAB program to find Rise time, peak time , Settle time and Maximum Peak
overshoot for Second order Control System.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-

clc
Clear all;
x=1;
e=input('Enter the value of damping= ' );
w=input('Enter the value of wn undamped Frequency= ');
k=input('Enter the gain of the system= ');
n=[w*w*k];
d=[1 2*e*w w*w];
a=tf(n,d)
e1 = e*e;
e2= 1-e1;
wd=w*(sqrt(e2));
q= atan(sqrt(e2)/e);
while (x==1)
b=input(' Press 1. Rise Time \n 2. Peak Time \n 3. Settle Time \n 4. Maximum
Peak Overshoot \n 5.Exit \n Enter your Choice' );
switch b
case 1
display('Rise Time will be ')
ans= ((pi-q)/wd)
case 2
display('Peak time will be ')
ans= pi/wd
case 3
display('Settle time will be ')
ans = 4 / (e*w)
case 4
display('Maximum Peak Overshoot will be ')
ans = exp((-e*pi)/(sqrt(e2)))*100
otherwise
break;

end
end

36
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

OUTPUT

Enter the value of damping= 0.6


Enter the value of wn undamped Frequency= 4
Enter the gain of the system= 1

Transfer function:
16
----------------
s^2 + 4.8 s + 16

Press 1. Rise Time


2. Peak Time
3. Settle Time
4. Maximum Peak Overshoot
5.Exit
Enter your Choice1
Rise Time will be

ans =

0.6920

Press 1. Rise Time


2. Peak Time
3. Settle Time
4. Maximum Peak Overshoot
5.Exit
Enter your Choice2
Peak time will be

ans =

0.9817

Press 1. Rise Time


2. Peak Time
3. Settle Time
4. Maximum Peak Overshoot
5.Exit
Enter your Choice3
Settle time will be

ans =

1.6667

37
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

Press 1. Rise Time


2. Peak Time
3. Settle Time
4. Maximum Peak Overshoot
5.Exit
Enter your Choice4
Maximum Peak Overshoot will be

ans =

9.4780

Press 1. Rise Time


2. Peak Time
3. Settle Time
4. Maximum Peak Overshoot
5.Exit
Enter your Choice5
>>

38
Name of Student
Roll No.

You might also like