Basic Electrical Engineering

Basic Electrical Engineering

Instructor: Engr. Mariam Shafqat

Signals And Systems
Lab Manual
Name: ______
Reg. No:______Section: ______Group: ______
University of Engineering Technology, Taxila
Prepared by:
Checked by:
Date:

Software Requirements

S.No. / Software Title / Description
1 / Matlab / Computing mathematics laboratory
Table of Contents
Lab No. / Lab Title / Page
Lab # 1 / Understanding of some basic Matlab Commands / 1
Lab # 2
Lab # 3
Lab # 4
Lab # 5
Lab # 6
Lab # 7
Lab # 8
Lab # 9
Lab # 10
Lab # 11
Lab # 12
Lab # 13
Lab # 14
Lab # 15
Project

Experiment # 1

Lab Title: / Basic Matlab Tutorial
Learning Objectives: / Familiarize with the Matlab environment and running some basic Matlab commnds on Matlab
Equipment Required: / Matlab

Variables and Arrays

The functional unit of data in any Matlab program is array. An Array is a collection of data values organized into rows and columns and known by a single name.

Arrays can be classified as either vectors or matrices. The term VECTOR is usually used to describe an array with only one dimension. While the term MATRIX is usually used to describe an array with two or more dimensions.

Size of array is specified by the number of rows and the number of columns in the array, with the number of rows mentioned first. The total number of elements in the array will be the product of the number of rows and the number of columns.

Try using these values:

[3.4]

[1.0 2.0 3.0]

[1.0; 2.0; 3.0]

[1, 2, 3; 4, 5, 6]

[1, 2, 3, 4, 5, 6]

[]

Not all the elements of an array need to be defined when it is created. If a specific array element is defined and onwe or more of the elements before it are not, then the earlier elements are automatically created and initialized to zero. For example, if c is not previously defined, the statement

C(2,3)=5

Will produce matrix 0 0 0

0 0 5

Similarly the array d=[1 2]. Then the statement

d(4)=4

will produce d=[1 2 0 4].

Initializing with shortcut expressions

Matlab provides a special shortcut notation for these circumstances using the COLON operator. The colon operator specifies a whole series of values by specifying the first vales in the series, the stepping increment and then the last value in the series. The general form of a colon operator is

First: increment: last

For example

x=1:2:10

will generate x= 1 3 5 7 9

Try using angles=(0.01:0.01:1.00)*pi;

Transpose Operator(‘):

This operator swaps the rows and columns of any array that it is applied to.

For example try using:

F=[1:4]

And F=[1:4]’

Initializing with Built-in functions:

Try using these:

A=zeros(2)

B=zeros(2,3)

C=[1 2; 3 4]

D=zeros(size(C))

E=ones(3)

Ones(3,1)

Eye(3)

Eye(3,2)

Length(C) //Generate the longest dimension of the array.

Zeros can be used to create an all zero array of any desired size. If function has a single square array; it will generate a square array using the single argument as both the number of rows and columns. size function returns two values containing the number of rows and columns in an array.

Initializing variables with keyboard input:

Input function displays a prompt string in the command window and then waits for the user to type in a response. For example , consider the following statement:

My_val=input(‘enter an input value’);

Multidimensioanl Array

Matlab allows us to create arrays as many dimensions as necessary for any given problem. These arrays have one subscript for each dimension and an individual element in the array will be the product of the maximum value of each subscript. For example the following two statements create a 2X2X3 array C:

C(:,:,1)=[1 2 3; 4 5 6];

C(:,:,2)=[7 8 9; 10 11 12];

Whos C

SubArrays

It is possible to select and use subsets of arrays as though they were separate arrays. To select a portion of array, just include a list of all of the elements to be selected in the parenthesis after the rray name. For example:

Arr1=[1.1 2.2 3.3 4.4 5.5]

Try using Arr1(3)

And Arr1([1 4])

And also Arr1(1:2:5)

End Function:

It is very useful for creating array subscripts. When used in an array subscript; end returns the highest value taken on by that subscript. For example. Suppose that array arr3 is defined as follows:

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

Then Arr1(5:end) would be the array [5 6 7 8] and array(end) would generate 8.

The value returned by end is always the highest value of a given subscript. Is end appears in different subscripts, it can return different values within the same expression. For example, suppose that the 3X4 array Arr4 is defined as follows:

Arr4=[1 2 3 4; 5 6 7 8; 9 10 11 12];

Then the expression

Arr4(2:end, 2:end)

would return the array.(Try this one).

TASKS

Task # 01:

This M-file calculates and plot the function sin(x) for 0<=x<=6

X=0:0.1:6;

Y=sin(X);

plot(X,Y);

plot(X,Y)

Task # 02:

The following Matlab statement plot the function y(x)=2e-0.2x for the range 0<=x<=10

X=0:0.1:10;

Y=2*exp(0.2*X);

Plot(X,Y);

Task # 02:

suppose that u=1 and v=3. Evaluate the following expressions using Matlab.

(a)4u/3v

(b)2v-2/(u+v)2

(c)v3/v3-u3

(d)4/3 pi.v2

Task # 04:

(a)Generate a 6X6 Matrix.

(b)Generate a 6X1 Matrix

(c)Generate a 3X4 Matrix

Task # 05

Answer the following questions for the array shown below.

1.10.0 2.1 -3.5 6.0

0.0 1.1 -6.6 2.8 3.4

1.10.1 0.3 -0.4 1.3

-1.4 5.1 0.0 1.1 0.0

(a)what is the size of the array?

(b)What is the value of the array(4,1)?

(c)What is the size and value of array( : , 1 : 2 )?

(d)What is the size and Value of the (array[1 3],end)?

Task # 06

Are the following Matlab variable names legal or illegal? Why?

(a)dog1

(b)1dog

(c)Do_you_know_the_way__to_lahore

(d)_help

Task # 07

Determine the size and contents of the follwings arrays. Note that the later arrays may depend on the definition of arrays defined earlier in this exercise

(a)a=1:2:5

(b)b=[a’ a’ a’]

(c)c=b(1:2:3,1:2:3);

(d)d=a+b(2,:);

(e)w=[zeros(1,3) ones(3,1)’ 3:5’]

(f)b([1 3],2 )=b([3 1],2);

Task # 08

Assume that the array is defined as follows; determine the contents of the following subarrays

1.1 0.0 2.1 3.5 6.0

0.0 1.1 6.6 2.8 3.4

2.1 0.1 0.3 0.4 1.3

1.4 5.1 0.0 1.1 0.0

(a)array(3,:)

(b)array(:,3)

(c)array(1:2:3,[3 3 4])

(d)array([1 1],:)

Signals And Systems