Exp 1-Student Manual
Exp 1-Student Manual
Exp 1-Student Manual
Abstract:
MATLAB is a very useful and widely used tool in numerous divisions of engineering.
In Digital Signal Processing, MATLAB is an integral part.
It plays an important role in analyzing and performing various operations on signal processing.
Introduction:
The purpose of this experiment is to gain familiarity with MATLAB and build some basic skills in
MATLAB language. The very basics of MATLAB, i.e. writing codes, computing mathematical
calculations, the concept of arrays, plotting data, creating functions etc. are described in this
experiment.
Character Description
+ Addition
− Subtraction
* Multiplication (scalar and array)
/ Division (right)
ˆ Power or exponentiation
: Colon; creates vectors with equally spaced elements Semi-
; colon; suppresses display; ends row in array Comma;
, separates array subscripts
... Continuation of lines
% Percent; denotes a comment; specifies output format Single
quote; creates string; specifies matrix transpose Assignment
= operator
() Parentheses; encloses elements of arrays and input arguments
[] Brackets; encloses matrix elements and output arguments
Character Description
.* Array multiplication
./ Array (right) division
.ˆ Array power
.\ Array (left) division
.’ Array (nonconjugated) transpose
Character Description
Command Description
Variable Description
Variables
Variables are defined to store numerical values. A valid name for an OCTAVE variable is a
character string containing letters (upper or lower case), digits, and underscores where the first
character must be a letter.
For example, you can store the value 5 in the variable x by entering
> x = 5;
Note that nothing will be printed out because semicolons follow each command. If you want
everything printed out then type
>x=5
The output will be then
x=5
OCTAVE contains some predefined variables. Many of these are contained in the table
below.
Function Explanation
abs(x)
The absolute value of x.
exp(x) ex exp(x) ex
cos(x)
cos x
sin(x)
sin x
factorial(n)
n! for n a non-negative integer.
If x ≥0 this is the largest integer which
is ≤x.
fix(x) If x < 0 this is the smallest integer
which is ≥x.
floor(x)
This is the largest integer which is ≤ x.
The natural log of x, i.e., logex.
log(x)
The common log of x, i.e., log10x.
log10(x)
The remainder of x/y. This is the same
rem(x, y) as mod(x, y) if x, y > 0
sqrt(x)
√x .
tan(x)
tan x.
Complex Numbers
There are standard commands for obtaining the real part, the imaginary part, and the complex
conjugate of a complex number or variable.
For example
> x = 3 - 4i
x = 3 - 4i
>real(x)
ans = 3
> imag(x)
ans = -4
> conj(x)
ans = 3 + 4i
Function Explanation
abs(z)
The absolute value of z = x + iy.
conj(z)
z*= x - iy.
imag(z)
The imaginary part of z, i.e., y.
real(z)
The real part of z, i.e., x.
1 2 3
4 5 6
7 8 9
type
> A = [1, 2, 3; 4, 5, 6; 7, 8, 9]
returns with
A=
1 2 3
4 5 6
7 8 9
or type
> A = [1 2 3; 4 5 6; 7 8 9]
A=
1 2 3
4 5 6
7 8 9
The transpose of a matrix A, denoted ted as AT, is calculated by A.’(i.e., a period followed by a
single quote mark).
For example
The vector
1
2
3
X= 4 = [1 2 3 4 5 6]T
5
6
7
can be entered as
> x=[1 2 3 4 5 6].'
returns with
x=
returns with
x=
10
Also the length of x can be found using length (x) returns the number of elements in vector x.
For example
> length(x)
ans = 10
Elementary Matrices
For example,
> b = zeros(5)
or
> b = zeros(5, 5)
returns with
b=
0 0 0
0 0 0
0 0 0
Also,
> b = zeros(3, 5)
returns with
b=
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Similarly, you can generate a matrix with all ones by ones(n) or ones(m, n).
For example
> b = ones(3, 5)
returns with
b=
1 1 1 1 1
1 1 1 1 1
11111
You can also generate the identity matrix, i.e., the matrix with ones on the main diagonal and
zeroes off of it, by using the command eye with the same arguments as above.
For example
> b=eye(3)
returns with
b=
Diagonal Matrix
100
0 1 0
0 0 1
Plot
plot(y) plots the columns of Y versus their index.
For example
x= linspace(0,2*pi,30);
> y=sin(x);
returns with
Subplot
Create axes in tiled positions.
H = subplot(m,n,p) 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 secondrow, etc.
For example
> x= linspace(0,2*pi,30);
> y=sin(x);
> z=cos(x);
> subplot(2,1,1)
> subplot(2,1,2)
plots y on the top half of the window and z on the bottom half
Software Requirement:
Experimental procedure:
Write the matlab code and generate output for the following expressions-
1. M=5
2. N=6
3. P=M+Ni
4. Q=conjugate of P
5. R=real part of P
6. S=imaginary part of P
7. X=
8. Y=transpose matrix of x
In this experiment, a detailed introduction to MATLAB was given. The interface of MATLAB and
the basic building blocks were discussed. After the completion of this lab, students were able to
understand the structure of the software and will be able to write codes, plotting graphs, making
functions and compute simple and complex mathematical computations.
Reference(s):
[1] Kothari, D P, and I J Nagrath. Modern Power System Analysis. 3rd ed. New Delhi: Tata
McGraw-Hill, 2009. Print.
[2] AIUB Lab manual.
Experiment 1 Student Manual
Manual