You are on page 1of 14

Experiment No-3

AIM:- Generate Arrays and matrix and perform basic operations using Matlab
software.

AIM: Generate a matrix and perform basic operation on matrices using


Matlab software.
Software Required:
Matlab software 7.0 and above.
Theory:

MATLAB treats all variables as matrices.


Vectors are special forms of matrices and contain only one row or one
column. Where as Arrays 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.

Program:

% Creating a arrray

>> a=[1 2 3 4]

a=

1 2 3 4
% Creating a column vector
b=[1;2;3]

b=

1
2
3

% Creating a matrix

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

A=

1 2 3
4 5 6
7 8 9

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

B=

9 8 7
6 5 4
3 2 1

%Multiplication of two matrices


>> C=A*B

C=

30 24 18
84 69 54
138 114 90

% Elementwise Multiplication of two matrices

>> D=A.*B

D=

9 16 21
24 25 24
21 16 9

%invesre of a matrix

>> inv(A)
ans =

-0.4504 0.9007 -0.4504


0.9007 -1.8014 0.9007
-0.4504 0.9007 -0.4504

% Extracting sub matrix from matrix

>> x1=A(2:3,2:3)

x1 =

5 6
8 9

% extracting column vector from matrix

>> x2=A(:,2)

x2 =

2
5
8
% extracting row vector from matrix

>> x3=A(3,:)

x3 =

7 8 9

% transpose of a matrix

>> A'

ans =

1 4 7
2 5 8
3 6 9

% cube of matrix a( power of the matrix)


>> x5=A^3

x5 =

468 576 684


1062 1305 1548
1656 2034 2412
% vector power 3 of matrix a

>> x6=A.^3

x6 =

1 8 27
64 125 216
343 512 729

RESULT: Matrix operations are performed using Matlab software.


Experiment No-4

AIM:- To Plot the basic signals like Unit Ramp, Impulse, Unit Step, Square Wave
and Sinc Functions using MATLAB.

Theory:

If the amplitude of the signal is defined at every instant of time then it is called
continuous signal. If the amplitude of the signal is defined at only at some instants
of time then it is called discrete signal. If the signal repeats itself at regular
intervals then it is called periodic signal. Otherwise they are called aperiodic
signals.

Ramp sinal:

r(t)= t ;when t>=0

Unit impulse signal:

Y(t)= 1 only when t=0

=0 other wise

Unit step signal:

u(t)= 1 only when t>=0

=0 other wise

Sinc signal:

G(x)=(sinx)/x
ROGRAM:

clc;

clear all;

t=0:0.1:5;

%generation of ramp signal

y=t;

subplot(6,2,1); plot(t,y)

xlabel('time');

ylabel('amplitude');

title('ramp signal');
%generation of ramp sequence

subplot(6,2,2); stem(y)

xlabel('n');

ylabel('amplitude');

title('ramp sequence');

%generation of impulse signal

y1=(t==0);

subplot(6,2,3); plot(t,y1);

xlabel('time');

ylabel('amplitude');

title('impulse signal');

%generation of impulse sequence

subplot(6,2,4); stem(y1);

xlabel('n');

ylabel('amplitude');

title('impulse sequence');
%generation of unit step signal

y2=(t>=0);

subplot(6,2,5); plot(t,y2);

xlabel('time');

ylabel('amplitude');

title('unit step signal');

%generation of unit step sequence

subplot(6,2,6);stem(t,y2);

xlabel('n');

ylabel('amplitude');

title('unit step sequence');

%generation of square wave signal

% y = square(t) with time period 2pi

% y = square(t,duty) with duty cycle in 0 to 100


y3=square(t);

subplot(6,2,7); plot(t,y3);

xlabel('time');

ylabel('amplitude');

title('square wave signal');

%generation of square wave sequence

subplot(6,2,8); stem(y3);

xlabel('n');

ylabel('amplitude');

title('square wave sequence');

%generation of sinusoidal

t1 = -3:0.1:3;

y4=sin(t1);

subplot(6,2,9); plot(t1,y4);

xlabel('time');

ylabel('amplitude');
title('sinsoidal wave signal');

%generation of sin wave sequence

subplot(6,2,10); stem(y4);

xlabel('n');

ylabel('amplitude');

title('sin wave sequence');

%generation of sinc signal

y5=sinc(t1);

subplot(6,2,11); plot(t1,y5);

xlabel('time');

ylabel('amplitude');

title(' sinc signal');


%generation of sinc sequence

subplot(6,2,12); stem(y5);

xlabel('n');

ylabel('amplitude');

title('sinc sequence');

Result: Various signals & sequences generated using Matlab software.

You might also like