MATLAB lab manual-1
MATLAB lab manual-1
6. Locating Zeroes and poles and plotting the pole-zero maps in S plane
and for the given TF
7. Simulation of DC circuits
MISSION
QUALITY POLICY
PROGRAMME EDUCATIONAL
OBJECTIVES
All students must observe the Dress Code while in the laboratory.
All students are liable for any damage to the accessories due to their own negligence.
All interfacing kits connecting cables must be RETURNED if you taken from
the labsupervisor.
Students are strictly PROHIBITED from taking out any items from the laboratory.
Students are NOT allowed to work alone in the laboratory without the Lab Supervisor
USB Ports have been disabled if you want to use USB drive consult lab supervisor.
AIM: Generate a matrix and perform basic operation on matrices using MATLAB software.
Software Required: MATLAB software
Theory:
MATLAB treats all variables as matrices. Vectors are special forms of matrices and contain
only one row or one column. Whereas scalars are special forms of matrices and contain only
one row and one column. A matrix with one row is called row vector and a matrix with single
column is called column vector.
The first one consists of convenient matrix building functions, some of which are given
below.
1. eye - identity matrix
2. zeros - matrix of zeros
3. ones - matrix of ones
4. diag - extract diagonal of a matrix or create diagonal matrices
5. triu - upper triangular part of a matrix
6. tril - lower triangular part of a matrix
7. rand - ran
commands in the second sub-category of matrix functions are
1. size- size of a matrix
2. det -determinant of a square matrix
3. inv- inverse of a matrix
4. rank- rank of a matrix
5. rref- reduced row echelon form
6. eig- eigenvalues and eigenvectors
7. poly- characteristic polynomialdomly generated matrix
Program:
% Creating a column vector
>> a=[1;2;3]
a=
1
2
3
% Creating a row vector
>> b=[1 2 3]
b=
123
% Creating a matrix
>> m=[1 2 3;4 6 9;2 6 9]
m=
123
469
269
% Extracting sub matrix from matrix
>> sub_m=m(2:3,2:3)
sub_m =
69
69
% extracting column vector from matrix
>> c=m (:,2)
c=
2
6
6
% extracting row vector from matrix
>> d=m (3,:)
d =
269
% creation of two matrices a and b
>> a=[2 4 -1;-2 1 9;-1 -1 0]
a=
2 4 -1
-2 1 9
-1 -1 0
>> b=[0 2 3;1 0 2;1 4 6]
b =
023
102
146
% matrix multiplication
>>
x1=a
*bx1
=
308
10 32 50
-1 -2 -5
% element to element multiplication
>>
x2=a.
*bx2
=
0 8 -3
-2 0 18
-1 -4 0
% matrix addition
>>
x3=a
+bx3
=
262
-1 1 11
036
% matrix subtraction
>> x4=a-b
x4 =
2 2 -4
-3 1 7
-2 -5 -6
% matrix division
>> x5=a/b
x5 =
-9.0000 -3.5000 5.5000
12.0000 3.7500 -5.7500
3.0000 0.7500 -1.7500
% element to element division
>> x6=a./b
Warning: Divide by zero.
x6 =
Inf 2.0000 -0.3333
-2.0000 Inf 4.5000
-1.0000 -0.2500 0
% inverse of matrix a
>> x7=inv(a)
x7 =
-0.4286 -0.0476 -1.7619
0.4286 0.0476 0.7619
-0.1429 0.0952 -0.4762
% transpose of matrix a
>> x8=a'
x8 =
2 -2 -1
4 1 -1
-1 9 0
RESULT: Matrix operations are performed using MATLAB software.
EXPERIMENT NO-2
Theory: If the amplitude of the signal is defined at every instant of time then it is called
continuous time signal. If the amplitude of the signal is defined at only at some instants of
time then it is called discrete time signal. If the signal repeats itself at regular intervals then it
is called periodic signal. Otherwise they are called aperiodic signals.
EX: ramp,Impulse,unit step, sinc- Aperiodic signals
square,sawtooth,triangular sinusoidal – periodic signals.
Ramp sinal: The ramp function is a unitary real function, easily computable as the mean of
the independent variable and its absolute value.This function is applied in engineering. The
name ramp function is derived from the appearance of its graph.
r(t)= t when
0 else
Unit impulse signal: One of the more useful functions in the study of linear systems is the
"unit impulse function."An ideal impulse function is a function that is zero everywhere but at
the origin, where it isinfinitely high. However, the area of the impulse is finite
Y(t)= 1 when t=0
=0 other wise
Unit step signal: The unit step function and the impulse function are considered to be
fundamental functions in engineering, and it is strongly recommended that the reader
becomes very familiar with both of these functions.
0 if t < 0
u(t)= 1 if t > 0If
t=0
PROGRAM:
Theory:
Signal Addition
Multiplication :
Multiplication of two signals can be obtained by multiplying their values at every instants . z
z(t) = x (t) y (t)
Time reversal/Folding:
Time reversal of a signal x(t) can be obtained by folding the signal about t=0.
Y(t)=y(-t)
a >1 amplification
Time shifting: The time shifting of x(n) obtained by delay or advance the signal in time by
using y(n)=x(n+k)
If k is a positive number, y(n) shifted to the right i e the shifting delays the signal
If k is a negative number, y(n ) it gets shifted left. Signal Shifting advances the signal
Energy:
Average power
Program:
clc;
clear all;
close all;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% addition of signals
y1=x1+x2;
subplot(2,2,3);
plot(t,y1);
xlabel('time');
ylabel('amplitude');
title('addition of two signals');
% multiplication of signals
y2=x1.*x2;
subplot(2,2,4);
plot(t,y2);
xlabel('time');
ylabel('amplitude');
title('multiplication of two signals');
% scaling of a signal1
A=2;
y3=A*x1;
figure;
subplot(2,2,1);
plot(t,x1);
xlabel('time');
ylabel('amplitude');
title('input signal')
subplot(2,2,2);
plot(t,y3);
xlabel('time');
ylabel('amplitude');
title('amplified input signal');
% folding of a signal1
h=length(x1);
nx=0:h-1;
subplot(2,2,3);
plot(nx,x1);
xlabel('nx');
ylabel('amplitude');
title('input signal')
y4=fliplr(x1);
nf=-fliplr(nx);
subplot(2,2,4);
plot(nf,y4);
xlabel('nf');
ylabel('amplitude');
title('folded signal');
%shifting of a signal 1
figure;
subplot(3,1,1);
plot(t,x1);
xlabel('time t');
ylabel('amplitude');
title('input signal');
subplot(3,1,2);
plot(t+2,x1);
xlabel('t+2');
ylabel('amplitude');
title('right shifted signal');
subplot(3,1,3);
plot(t-2,x1);
xlabel('t-2');
ylabel('amplitude');
title('left shifted signal');
%~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~%operations on
sequences n1=1:1:9;
s1=[1 2 3 0 5 8 0 2 4];
figure;
subplot(2,2,1);
stem(n1,s1);
xlabel('n1');
ylabel('amplitude');
title('input sequence1');
s2=[1 1 2 4 6 0 5 3 6];
subplot(2,2,2);
stem(n1,s2);
xlabel('n2');
ylabel('amplitude');
title('input sequence2');
% addition of sequences
s3=s1+s2;
subplot(2,2,3);
stem(n1,s3);
xlabel('n1');
ylabel('amplitude');
title('sum of two sequences');
% multiplication of sequences
s4=s1.*s2;
subplot(2,2,4);
stem(n1,s4);
xlabel('n1');
ylabel('amplitude');
title('product of two sequences');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OUTPUT:
e1 = 31
e2 = 4.0388
p1 = 6.2000
p2 = 0.3672
we will find current which is flowing through resistor RB and the power supplied by the
voltage source of 10V.
First, let’s assign currents for each loop as I1, I2 and I3 and the power supplied by the
source is 10*I1 as we can see from the circuit.
Now, let’s write the loop equations for each loop:
Loop 1:
10(I1−I2)+30(I1−I3)−10=0
-10I1−10I2−30I3=10⋯(1)
Loop 2:
10(I2−I1)+15I2+5(I2−I3)=0
−10I1+30I2−5I3=0⋯(2)
Loop 3:
30(I3−I1)+5(I3−I2)+30I3=0
−30I1−5I2+65I3=0⋯(3)
MATLAB CODING-
clear all;close all;clc
% Loop Analysis using Matlab
R_Mat = [40 -10 -30;
-10 30 -5; % Impedance (or Resistance) Matrix obtain from Loop equations
-30 -5 65];
V_vec = [10 0 0]'; % Voltage Vector (again from Loop equations)
%% % Loop Currents Calculations
I_Loop = inv(R_Mat)*V_vec;
% Calculate current flowing through Resistor R_B
I_RB = I_Loop(3) - I_Loop(2); % (I=I3-I2)
fprintf('The current flowing through Resistor R_B is %8.3f A \n',I_RB)
% Calculate the total power supplied by 10V source
P_Source = I_Loop(1)*10; % (P=10*I_1)
fprintf('The power supplied by voltage source of 10V is %8.4f watts
\n',P_Source)
Results:
The current flowing through Resistor R_B is 0.037 A
The power supplied by voltage source of 10V is 4.7531 watts
*we will find node voltages for a very simple resistive circuit using Nodal Analysis.
While applying KCL, we will assume that currents leaving the node are positive and entering
the node are negative. Keeping that fact in mind, let’s write node voltages for each node in the
circuit.
Node 1
(V1−V2 )10+(V1−V3)10−5=0
0.15V1−0.1V2−0.05V3=5⋯(1)
Node 2:
(V2−V1)10+V250+(V2−V3)40=0
−0.10V1+0.145V2−0.025V3=0⋯(2)
Node 3:
(V3−V1)20+(V3−V2)40−2=0
−0.05V1−0.025V2+0.075V3=2⋯(3)
Matlab coding
clear all;close all;clc
% Nodal Analysis using Matlab
Y_Mat = [ 0.15 -0.1 -0.05;
-0.1 0.145 -0.025; % Admittance Matrix (YV=I) obtain from Node equations
-0.05 -0.025 0.075];
I_vec = [5;
0; % Current Vector (again from Node equations)
2];
%% Node Voltages Calculation
fprintf('Nodal voltages V1, V2 and V3 are \n')
V_Node = inv(Y_Mat)*I_vec
Results:
Nodal voltages V1, V2, and V3 are
V_Node =
404.2857
350.0000
412.8571
EXPERIMENT NO: 5
AIM: To verify Superposition theorem, Thevenin‟s theorem, Norton‟s theorem and Maximum power
Transfer theorem.
SOFTWARE USED : MULTISIM / MATLAB Simulink
SUPERPOSITION THEOREM:
“In a linear network with several independent sources which include equivalent sources due to initial
conditions, and linear dependent sources, the overall response in any part of the network is equal to
the sum of individual responses due to each independent source, considered separately, with all other
independent sources reduced to zero”.
Procedure:
Step 1:
1. Make the connections as shown in the circuit diagram by using MULTISIM/MATLAB
Simulink.
2. Measure the response „I‟ in the load resistor by considering all the sources 10V, 15V and 8V
in the network.
Step 2:
1. Replace the sources 15V and 8V with their internal impedances (short circuited).
2. Measure the response „I1‟ in the load resistor by considering 10V source in the network.
Step 3:
1. Replace the sources 10V and 8V with their internal impedances (short circuited).
2. Measure the response „I2‟ in the load resistor by considering 15V source in the network.
Step 4:
1. Replace the sources 10V and 15V with their internal impedances (short circuited).
2. Measure the response „I3‟ in the load resistor by considering 8V source in the network.
The responses obtained in step 1 should be equal to the sum of the responses obtained in step 2, 3 and
4.
I=I1+I2+I3
Hence Superposition Theorem is verified.
1
Continuous
powergui Step 1 : By Considering All Sources In The Network Step 2 : By Considering 10 V Sources In The Network
R1=10 Ohms V2=15V R2=12 Ohms R3=1 Ohm R1=10 Ohms V2=0V R2=12 Ohms R3=1 Ohm
- +
+
-
i
i
0.11 0.2667
11
RL=15 Ohms
RL=15
Ohms V3=8V
V3=0 V1=0V
V1=0V
V
- +
+
i
0.1778
-
i
-
0.333
3
Considerning 10V Source I1: 0.2667A With all the sources in the network I = 0.1111A
Considering 15V Source I2 : - 0.3333A I=I1+I2+I3
Considering 8V Source I3 : 0.1778A
Hence SuperPosition Theorem is Verified.
Total Current : I1+I2+I3=0.2667-0.3333+0.1778
=0.1112A
7
THEVENIN’S THEOREM:
“Any two terminal network consisting of linear impedances and generators may be replaced at the two
terminals by a single voltage source acting in series with an impedance. The voltage of the equivalent
source is the open circuit voltage measured at the terminals of the network and the impedance, known
as Thevenin‟s equivalent impedance, ZTH, is the impedance measured at the terminals with all the
independent sources in the network reduced to zero ”.
Procedure:
Step 1:
2. Measure the response „I‟ in the load resistor by considering all the sources in the network.
1. Open the load terminals and replace all the sources with their internal impedances.
2. Measure the impedance across the open circuited terminal which is known as Thevenin‟s
Resistance.
1. Open the load terminals and measure the voltage across the open circuited terminals.
VTH
2. Measure the current through the load resistor IL = .
RTH+RL
Current measured from Thevenin‟s Equivalent Circuit should be same as current obtained from the
actual circuit.
I = IL.
R1=10 Ohms V2=15V R2=12 Ohms R3=1 Ohm R1=10 Ohms V2=0V R2=12 Ohms R3=1 Ohm
RL=15 Ohms
V3=8V
V1=10V Z V3=0V
V1=0V
- +
i
0.1111
Rth=5.4545 Ohms
R1=10 Ohms V2=15V R2=12 Ohms R3=1 Ohms
- +
i
0.1111
Open Circuit Voltage Vth = 2.273V With all the sources in the network Current through Load Resistor 15 Ohms : I=0.1111A
Thevenin's Resistance = 5.4545Ohms
Current through Load Resistor 15 Ohms IL = 0.1111A I=IL
9
NORTON’S THEOREM:
“Any two terminal network consisting of linear impedances and generators may be replaced at its two
terminals, by an equivalent network consisting of a single current source in parallel with an
impedance. The equivalent current source is the short circuit current measured at the terminals and the
equivalent impedance is same as the Thevenin‟s equivalent impedance”.
Procedure:
Step 1:
2. Measure the response „I‟ in the load resistor by considering all the sources in the network.
1. Open the load terminals and replace all the sources with their internal impedances.
2. Measure the impedance across the open circuited terminal which is known as Norton‟s
Resistance.
1. Short the load terminals and measure the current through the short circuited terminals.
INRN
2. Measure the current through the load resistor IL = .
RN+RL
Current measured from Norton‟s Equivalent Circuit should be same as current obtained from the
actual circuit.
I = IL.
powe rgui Step 1 : By Considering All Sources In The Network Step 2: Finding Norton's Resistance
R1=10 Ohms V2=15V R2=12 Ohms R3=1 Ohm R1=10 Ohms V2=0V R2=12 Ohms R3=1 Ohm
RL=15 Ohms
V1=10V
V3=8V
V1=0V Z V3=0V
- +
i
0.1111
V3=8V Converter
i
V1=10V
0.4167
0.1111 S PS
+
Current Sensor
f(x)=0
-
I
Solver
Configuration
Electrical Reference
Norton's Current = 0.4167 A With all the sources in the network Current through Load Resistor 15 Ohms : 0.1111A
Norton's Resistance = 5.4545Ohms
Current through Load Resistor 15 Ohms = 0.1111A
Hence Norton's Theorem is Verified.
MAXIMUM POWER TRANSFER THEOREM:
“In any circuit the maximum power is transferred to the load when the load resistance is equal to the
source resistance. The source resistance is equal to the Thevenin‟s equal resistance ”.
Procedure:
Step 1:
1. Make the connections as shown in the circuit diagram by using Multisim/MATLAB Simulink.
2. Measure the Power across the load resistor by considering all the sources in the network.
1. Open the load terminals and replace all the sources with their internal impedances.
2. Measure the impedance across the open circuited terminal which is known as Thevenin‟s
Resistance.
1. Open the load terminals and measure the voltage across the open circuited terminals.
V2
3. Measure power by using P = TH .
4RL
4. Verify the power for different values of load resistors(i.e. RL>RTH and RL<RTH)
Power measured from the above steps results in maximum power dissipation when RL=RTH.
R1=10 Ohms V2=15V R2=12 Ohms R3=1 Ohm R1=10 Ohms V2=0V R2=12 Ohms R3=1 Ohm
V3=8V
V1=10V RL=5.4545 Ohms Z V3=0V
V1=0V
Vth=2.273V
Vth=2.273V Vth=2.273V
Open circuited RL RL=6 Ohms
V1=10V RL=5.4545 Ohm s RL=5 Ohms
V3=8V
+
v -
clc;
close all;
clear all;
Maximum Power
0.24
0.22
Power Dissipation in watts ------->
0.2
0.18
0.16
0.14
0.12
0 5 10 15 20 25
Load Resistance in Ohms ------ >
Results and Discussions: Super Position Theorem, Thevenin‟s Theorem, Norton‟s Theorem and
Maximum Power Transfer Theorem are verified by using MATLAB Simulink /MULTISIM.
The various circuit components are identified and circuits are formed in simulation
environment.
Use of network theorem in analysis can be demonstrated in this simulation exercise
EXPERIMENT NO-6
Locating Poles and Zeros in s-plane & z-plane
AIM: Write the program for locating poles and zeros and plotting pole-zero maps in s-plane
and z-plane for the given transfer function.
Theory:
Z-transforms
The Z-transform, like many other integral transforms, can be defined as either a one-sided or
two-sided transform.
Bilateral Z-transform
The bilateral or two-sided Z-transform of a discrete-time signal x[n] is the function X(z)
defined as
Unilateral Z-transform
Alternatively, in cases where x[n] is defined only for n ≥ 0, the single-sided or unilateral Z-
transform is defined as
Example:
Program:
clc;
clear all;
close all;
%enter the numerator and denamenator cofficients in square brackets
num=input('enter numerator co-efficients');
Result: Pole-zero maps are plotted in s-plane and z-plane for the given transfer function.
Output:
enter numerator co-efficients[1 -1 4 3.5]
poles =
-2.4874
0.4937 + 0.9810i
0.4937 - 0.9810i
zeros =
0.8402 + 2.1065i
0.8402 - 2.1065i
-0.6805