0% found this document useful (0 votes)
78 views15 pages

Electrical Network Analysis (EL 228) : Laboratory Manual Fall 2021

This document provides an introduction to MATLAB for students in an Electrical Network Analysis course. It outlines the objectives of the lab, which are to familiarize students with MATLAB's environment and basic commands. It then describes MATLAB's uses, how to enter commands and view results, and how to work with m-files, scripts, and functions. The document explains several important graphical and plotting commands in MATLAB. It provides examples of generating and customizing simple plots. It concludes with exercises for students to generate specific plots of signals.

Uploaded by

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

Electrical Network Analysis (EL 228) : Laboratory Manual Fall 2021

This document provides an introduction to MATLAB for students in an Electrical Network Analysis course. It outlines the objectives of the lab, which are to familiarize students with MATLAB's environment and basic commands. It then describes MATLAB's uses, how to enter commands and view results, and how to work with m-files, scripts, and functions. The document explains several important graphical and plotting commands in MATLAB. It provides examples of generating and customizing simple plots. It concludes with exercises for students to generate specific plots of signals.

Uploaded by

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

Electrical Network Analysis

(EL 228)
LABORATORY MANUAL
Fall 2021

LAB 01
Introduction to MATLAB
Engr. Rukhsar Ali

________________________________________ __________ ___


STUDENT NAME ROLL NO SEC

______________________________________
LAB ENGINEER'S SIGNATURE & DATE

MARKS AWARDED: /35


________________________________________________________________
NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES (FAST-NUCES), KARACHI
[Introduction to MATLAB] [Fall 2021- ENA- Lab] LAB: 01

Lab Session 01: INTRODUCTION TO MATLAB


Objective

The objective of this Laboratory is:


 To familiarize with the MATLAB environment and its basic features.
 To introduce basic commands which are most frequently used in MATLAB.

Introduction

MATLAB stands for Matrix Laboratory, is numeric computation software for engineering and scientific
calculations. MATLAB is primarily a tool for matrix computations.The graphics are integrated in MATLAB.
Since MATLAB is also a programming environment, a user canextend the functional capabilities of
MATLAB by writing new modules.

MATLAB has a large collection of toolboxes in a variety of domains. Someexamples of MATLAB toolboxes
are Control System, Signal Processing, Neural Network, Image Processing and Communications System.
The toolboxes consistof functions that can be used to perform computations in a specific domain.In
laboratory we will use MATLAB as a toolfor graphical visualization and numericalsolution of basic
electrical circuits included in Circuit Network Analysis course.

When MATLAB is invoked, the Command Window will display the prompt >>. MATLAB is then ready for
entering data or executing commands. To quit MATLAB, type the command exit or quitor directly close
it. MATLAB also provides on-line help. MATLAB statements are normally of the form: variable =
expression.

Expressions typed by the user are interpreted and immediately evaluated by theMATLAB system. If a
MATLAB statement ends with a semicolon, MATLABevaluates the statement but suppresses the display
of the result.To immediately display the results enter the statement and press enter. MATLAB allows
operations involving complex numbers. Complex numbersare entered using function i or j.

Example 1.1

>> a=2+4
a=
6

Example 1.2

>> a=5;
>> b=7;
>> c=a*b
c=
35

National University of Computer & Emerging Sciences, Karachi Page 1 of 13


LAB: 01 [Fall 2021- ENA-Lab] [Introduction to MATLAB]

M Files

Normally, when single line commands are entered, MATLAB processes the commands immediately and
displays the results. MATLAB is also capable of processing a sequence of commands that are stored in
files with extension ‘m’. MATLAB files with extension m are called m-files. M-files can either be script
files or function files. Both script and function files contain a sequence of commands. Script files are
especially useful for analysis and design problems that require long sequences of MATLAB commands.

Basic Commands

a) clear all

It clears all the variables or functions from Workspace. This frees up system memory.

b) close all

It closes all the current Figures.

c) clc (clear command window)

It clears the Command Window.

d) %

It is used to write Comments.

Graphical Commands

MATLAB also allows one to give titles to graphs, label the x- and y-axes, and add a grid to graphs. In
addition, there are commands for controlling the screen and scaling.

a) plot

It generates 2-D line Plot. There are two important variations of the plot command. plot(x)produces a
plot of the elements in the vector X as a function of the index of the elements in X. MATLAB will connect
the points by small line.

Example 1.3

>> x=[0 3.7 6.1 6.4 5.8 3.9];


>> plot(x)

Then the graph shown in Fig - 4.1 will appear.

Page 2 of 13 National University of Computer & Emerging Sciences, Karachi


[Introduction to MATLAB] [Fall 2021- ENA- Lab] LAB: 01

Fig - 1.1

If x and y are vectors of the same length, then the command plot(x, y) plots the elements of x (x-axis)
versus the elements of y (y-axis).

Plotting functions accept string specifiers as arguments and modify the graph generated accordingly.
Three components can be specified in the string specifiers along with the plotting command. They are:
Line style, Marker symbol and Color. Details are in the following tables:

Table 1.1 - Line Style Specifier

Table 1.2 - Marker Specifier

National University of Computer & Emerging Sciences, Karachi Page 3 of 13


LAB: 01 [Fall 2021- ENA-Lab] [Introduction to MATLAB]

Table 1.3 - Color Specifier

Example 1.4

>> x=[1 2 3 4 5 6 7 8 9 10];


>> y=[1 4 9 16 25 36 49 64 81 100];
>> plot(x,y,'-.or')

Then the graph shown in Fig - 1.2 will appear.

Fig - 1.2

Page 4 of 13 National University of Computer & Emerging Sciences, Karachi


[Introduction to MATLAB] [Fall 2021- ENA- Lab] LAB: 01

plot(x,y,'-.or') plots y versus x using a dash-dot line (-.), places circular markers (o) at the data points, and
colors both line and marker red (r). Specify the components (in any order) as a quoted string after the
data arguments.

b) axis

It freezes the axis limits.axis([xminxmaxyminymax]) sets the limits for the x- and y-axis of the current
axes.

c) title

It adds title to current figure.title(‘string’) adds the title consisting of a string at the top and in the
center of the current axes.

d) xlabel

Itlabels x-axis.xlabel(‘string’) labels the x-axis of the current axes with the string.

e) ylabel

It labels y-axis.ylabel(‘string’) labels the y-axis of the current axes with the string.

f) hold

hold function retains the current graph and adds another graph to it.

g) grid

grid function adds major grid lines to the current axes.

h) legend

It places a legend on graph.legend('string1','string2',...) displays a legend in the current axes using the
specified strings to label each set of data.

Example 1.5

Capacitor voltage ‘Vc’ in series RC circuit is given by 6*(1-exp(-2*t)). Plot Vc versus time ’t’. Take t from 0
to 4 seconds.

Matlab Code

t=0:0.5:4;% Defining time


Vc=6*(1-exp(-2*t));% Capacitor Voltage
plot(t,Vc)% Plotting Vc Vs t
title('Capacitor Voltage in Series RC Circuit')
xlabel('time(sec)')
ylabel('Voltage(V)')

National University of Computer & Emerging Sciences, Karachi Page 5 of 13


LAB: 01 [Fall 2021- ENA-Lab] [Introduction to MATLAB]

grid

Result

Example 1.6

Generate Sine wave of frequency 50 Hz.

Matlab Code

clear all
close all
clc
f=50; % Frequency definition
t=0:0.00005:0.02;% Continuous time from 0 to 0.02 with 0.000005 step
x=sin(2*pi*f*t); % Evaluating sine wave
plot(t,x)% Plotting x with respect to t
title('Sine Wave of frequency 50 Hz')
xlabel('time(sec)')
ylabel('Sine values')
grid

Result

Page 6 of 13 National University of Computer & Emerging Sciences, Karachi


[Introduction to MATLAB] [Fall 2021- ENA- Lab] LAB: 01

Example 1.7

Generate two Sine waves of frequency 50 Hz and 25 Hz.

Matlab Code

clear all
close all
clc
f1=50; % Defining first frequency
f2=25;% Defining Second frequency
t=0:0.000005:0.04;% Continuous time from 0 to 0.04 with 0.000005 step
x1=sin(2*pi*f1*t); % Evaluating sine wave 1
x2=sin(2*pi*f2*t);% Evaluating sine wave 2
plot(t,x1,t,x2)% Plotting x with respect to t
title('Sine Waves of Frequency 50 Hz and 25 Hz')
xlabel('time(sec)')
ylabel('Sine values')
legend('x1(t) - 50 Hz','x2(t) - 25 Hz')
grid

Result

National University of Computer & Emerging Sciences, Karachi Page 7 of 13


LAB: 01 [Fall 2021- ENA-Lab] [Introduction to MATLAB]

Example 1.8

Plot the following four functions for time 0 to 10 seconds.

x1(t)=5cos(2t+45o)
x2(t)=2exp(-t/2)
x3(t)=0.1t
x4(t)=5sin(2t)

Matlab Code

clear all
close all
clc
t=0:0.1:10; % Defining time
x1=5*cos(2*t+0.7854);% Evaluating x1(t). Note: Enter angle in radians.
x2=2*exp(-t/2);% Evaluating x2(t)
x3=0.1*t;% Evaluating x3(t)
x4=5*sin(2*t);% Evaluating x4(t)
plot(t,x1,'b',t,x2,'y')% Plotting x1 Vs t and x2 Vs t
hold % Holding the current plot
plot(t,x3,'r')% Plotting x3 Vs t
plot(t,x4,'g')% Plotting x4 Vs t
xlabel('t(s)')

Page 8 of 13 National University of Computer & Emerging Sciences, Karachi


[Introduction to MATLAB] [Fall 2021- ENA- Lab] LAB: 01

ylabel('x(t)')
legend('x1(t)','x2(t)','x3(t)','x4(t)')

Result

Lab Exercise

1. Write a program using MATLAB to plot inverted sine wave of frequency 1KHz.

2. Write a program using MATLAB to plot 2 cycles of sine wave of frequency 10KHz.

3. Write a program using MATLAB to plot three phase sine waveof frequency 50Hz by showing
each phase 120 degree apart.

National University of Computer & Emerging Sciences, Karachi Page 9 of 13


LAB: 01 [Fall 2021- ENA-Lab] [Introduction to MATLAB]

Lab Report:

Page 10 of 13 National University of Computer & Emerging Sciences, Karachi


[Introduction to MATLAB] [Fall 2021- ENA- Lab] LAB: 01

(It is recommended to write Lab Report in bullet Form)


Introduction:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Objective:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Task:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Observation:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

National University of Computer & Emerging Sciences, Karachi Page 11 of 13


LAB: 01 [Fall 2021- ENA-Lab] [Introduction to MATLAB]

______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Applications:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Page 12 of 13 National University of Computer & Emerging Sciences, Karachi


[Introduction to MATLAB] [Fall 2021- ENA- Lab] LAB: 01

StudentName(s): Roll # Section

Method: Lab reports and instructor observation during Lab sessions


Outcome Assessed:
a.Ability to conduct experiments, as well as to analyse and interpret data(P3/PLO 4).
b.Ability to function on multi-disciplinary teams(A/PLO 9).
c.Ability to use the techniques, skills, and modern engineering tools necessary for engineering
practice(P/PLO 5).
d.An ability to design a solution for an open-ended lab with appropriate considerations for public
health and safety, cultural, societal, and environmental factors. (C/PLO3)

Performance Exceeds expectation Meets expectation Does not meet expectation (1-0) Marks
(5-4) (3-2)
1. Realization of Selects relevant equipment to Needs guidance to select Incapable of selecting relevant
Experiment [a, c]
the experiment, develops setup relevantequipment to the equipment to conduct the
diagrams of equipment experiment and to develop experiment, equipment connection
connections or wiring. equipment connection or wiring or wiring diagrams.
diagrams.
2. Teamwork [b] Actively engages and Cooperates with other group Distracts or discourages other group
cooperates with other group members in a reasonable manner. members from conducting the
members in an effective experiment.
manner.
3. Conducting Does proper calibration of Calibrates equipment, examines Unable to calibrate appropriate
Experiment [a, c] equipment, carefully examines equipment moving parts, and equipment, and equipment operation
equipment moving parts, and operates the equipment with minor is substantially wrong.
ensures smoothoperation error.
andprocess.
4. Laboratory Safety Respectfully and carefully Observes safety rules and procedures Disregards safety rules and
Rules [a] observes safety rules and with minor deviation. procedures.
procedures
5. Data Collection [a] Plans data collection to achieve Plans data collection to achieve Does not know how to plan data
experimental objectives, and experimental objectives, and collects collection to achieve experimental
conducts an orderlyand a complete data with minor error. goals; data collected is incomplete and
complete datacollection. contain errors.
6. Data Analysis [a] Accurately conducts simple Conducts simple computations and Unable to conductsimple statistical
computations and statistical statistical analysis using collected data analysis on collected data; noattempt to
analysis using collected data; with minor error; reasonably correlate experimental results with
correlates experimental results to correlates experimental results to known theoretical values; incapable of
known theoreticalvalues; known theoretical values; attempts to explaining measurement errors or
accounts for measurement errors account for measurement errors and parameters that affect the
and parameters that affect parameters that affect experimental experimentalresults.
experimentalresults. results.
7. Design of Able to design and implement the Able to design and partially implement Unable to design the complete solution
Experiment [d] complete solution of open-ended the complete solution of open-ended of open-ended problem with safety,
problem with safety, health and problem with safety, health and health and environment related
environment related environment related considerations. considerations.
considerations.

Total
Lecturer / Faculty

Name: Rukhsar Ali

Signature: ___________

National University of Computer & Emerging Sciences, Karachi Page 13 of 13


LAB: 01 [Fall 2021- ENA-Lab] [Introduction to MATLAB]

Date: 10-09-21_

Page 14 of 13 National University of Computer & Emerging Sciences, Karachi

You might also like