Familiarization of Matlab - Part2 - lsdcRNyfAH
Familiarization of Matlab - Part2 - lsdcRNyfAH
DATE: 08-02-2011
EXPERIMENT NO.1
FAMILIARISATION OF MATLAB
AIM
To familiarize with MATLAB and its functions.
THEORY
MATLAB is an ideal software tool for studying digital signal processing. The plotting capacity
of MATLAB makes it possible to view the result of processing and gain understanding into
complicated operations. The tool box support a wide range of signal processing from waveform
generation to filter design and implementation, parametric modelling and spectral analysis. There are
two categories of tools Signal processing functions Graphical interaction tools. The first category of
tools is made of functions that we can call from the common line or from your own application. Many
of the functions are MATLAB statements that implement specialized signal processing algorithm.
pi=3.1416
Eg: y=2*(1+4*j)yields y=2.000+8.000y
These are also a number of predefined functions that can be used when defining a variable.
Some common functions that are used in this text are Abs- magnitude of a number Angle- angle of a
complex numberCos- cosine function, assume arguments in radian.
Exp-exponential functions
For example with y defined as aboveE= abs(y), yields e=8.2462, c=angle(y) yields c=1.3258
with a=3 as defined previously c=cos(a)yields, c= -0.9900c = exp(a), yields c=20.0855.Note that exp
can be used on complex numbers example with y = 2 + 8i as defined above
c = -1.0751 + 7.3104i which can be verified by using Euler‟s formula
c = c2cos(8) + jc2sin(8).
MATLAB is based on matrix and vector algebra. Even scalars are treated 1x1 matrix.
Therefore, vector and matrix operation are simple as common calculator operations. Vectors can be
defined in two ways. The first method is used for arbitrary elements, v=[1 3 5 7] creates 1x4 vector
elements with elements 1 3 5 &7. Note that commas would have been used in the place of spaces to
separate the elements. Additional elements can be added to the vector v(5)=8 yields the vector v =
[1357]. Previously defined vectors can be used to define a new vectors. For example with we defined
above a= [910]; b = [v a]; creates the vector b = [1357910]. The second method is used for creating
vector with equally spaced elements t=0:0.1:10; creates 1x101 vector with elements0,0.1,0.2. . . . . 10.
Note that the middle number defines the increments is set to a default of 1k=0,10 creates 1x11 vector
with the elements 0,1,2. . . .10. Matrices are defined by entering the element row by row. M = [124;
368] creates the matrix M= 1 2 43 6 8 There are number of special matrices that can be defined Null
matrix: [ ];
Nxm matrixes of zero: M=zeros (m,m);
Nxm matrix of ones: M= ones (n,m);
Nxn matrix of identity: M=eye (n)
A particular elements of matrix can e assigned M(1,2)=5 place the number 5 in the first
row,2nd column. Operations and functions that were defined for scalars in the previous section can be
used on vectors and matrices. For example a=[1 2 3]; b=[4 5 6]; c=a+b yield c=579. Functions are
applied element by element. For example t=0:„0; x=cos(2*t) creates a vector „x‟ with elements equal
to cos(2t) for t=0,1,2. . . ..10
(c) GENERAL INFORMATION
MATLAB is case sensitive. So „a‟ and „A‟ are two different names. Comment statements are
preceded by a %.
1) M-files M-files are macros of MATLAB commands that are stored as ordinary text file
with the extension „in‟ that is „filename.m‟. An m-file can be either a function with input and output
variables or a set of commands. MATLAB requires that the m-file must be stored either in the
working directory or in a directory that is specified in the MATLAB path list. The following
commands typed from within MATLAB demonstrate how this m-file is used. X=2,y=3,z=y plusx(y,x)
MATLAB m-files are most efficient when written in a way that utilizes matrix or vector operations,
loops and if statements are available, but should be used sparingly since they are computationally
inefficient. An examples is For k=1:10 x(k)=cos(k) end; This creates a 1x10vector „x‟ containing the
cosine of the positive integers from 1 to 10. This operation is performed more efficiently with the
commands k=1:10 x=cos(k) which utilizes a function of a vector instead of a for loop. An if statement
can be used to define combinational statement.
RESULT