0% found this document useful (0 votes)
71 views

Experiment - 1: A) MATLAB Program To Find Rank, Determinent, Trace and Inverse of The Given Matrix

The document contains a MATLAB program to generate and perform operations on various signals like unit impulse, unit step, sine, square, sawtooth, triangular, ramp and sinc signals. It includes programs to find rank, determinant, trace and inverse of a matrix and to perform addition, subtraction and multiplication of matrices. Other programs demonstrate operations like addition, multiplication, scaling, folding, shifting, computing energy and power on signals. The last program separates even and odd parts of a complex signal and its real and imaginary components.

Uploaded by

Ganga Prasad N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Experiment - 1: A) MATLAB Program To Find Rank, Determinent, Trace and Inverse of The Given Matrix

The document contains a MATLAB program to generate and perform operations on various signals like unit impulse, unit step, sine, square, sawtooth, triangular, ramp and sinc signals. It includes programs to find rank, determinant, trace and inverse of a matrix and to perform addition, subtraction and multiplication of matrices. Other programs demonstrate operations like addition, multiplication, scaling, folding, shifting, computing energy and power on signals. The last program separates even and odd parts of a complex signal and its real and imaginary components.

Uploaded by

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

EXPERIMENT -1

A) MATLAB Program to find Rank, Determinent, Trace and Inverse of the


given Matrix
clear all;
close all;
clc;
A=input('Enter the matrix A::');
%Finding the rank of the matrix
disp('Rank of matrix A is ::');
disp(rank (A));
%find the determinant of the matrix
disp('determinant of the matrix A is ::');
disp(det(A));
%find the trace of the matrix
disp('trace of matrix A is::');
disp(trace(A));
%find the inverse of the matrix
disp('inverse of matrix A is ::');
disp(inv(A));

B) MATLAB Program to find Addition, Subtraction and Multiplication of the


two given Matrices
clear all;
close all;
clc;
A=input('enter the matrix A: :');
B=input('enter the matrix B: :');
%%%finding the size of matrixes
disp('the size of matrix A is : :');
disp(size(A));
disp('the size of matrix B is : :');
disp(size(B));
%%%finding the length of vector
P=length(A);
Q=length(B);
%%%addition of two matrices
disp('addition of A and B matrices is : :');
disp(A+B);
%%%substraction of two matrices
disp('substraction of A and B matrices is : :');
disp(A-B);
%%%%%multiplication of two matrices
disp('multiplication of A and B matrices is : :');
disp(A*B);

EXPERIMENT -2
A) MATLAB Program to generate Unit Impulse Signal
clear all:
m1=input('enter a negative number for m1');
m2=input('enter a postive number for m2');
m=(m1:m2);
X=zeros(1,m2-m1+1);
m0=input('type o for unit impulse negative / postive for delay/advanced
signal');
X(m0-m1+1)=1;
stem(m,X);
axis([m1 m2 -1.5 1.5]);
xlabel('time index t(sec)');
ylabel('amplitude');
title('unit impulse signal sequence');

B) MATLAB Program to generate Unit Step Signal


k1=input('negative no for k1');
k2=input('postive no for k2');
k0=input('type o for normal unit step,negative or postive no for
one');
k=(k1:k2);
X=zeros(1,k2-k1+1);
X(k0-k1+1:end)=1;
stem(k,X,'r');
axis([k1 k2 -1.5 1.5]);
xlabel('time');
ylabel('amplitude');
title('unit step signal amplitude');

C) MATLAB Program to generate Square Signal


t=0:0.00001:1;
y=square(2*pi*50*t);
plot(t,y);
axis([0 .1 -2 2])
xlabel('Time index t(sec)');
ylabel('amplitude');
title('square time signal sequence');

D) MATLAB Program to generate Saw tooth Signal


fs=100000;
t=0:1/fs:1.5;
x=sawtooth(2*pi*100*t);
plot(t,x);
axis([0 0.05 -1 1])
xlabel('time index');

shifted

ylabel('amplitude');
title('sawtooth signal');

E) MATLAB Program to generate Triangular Signal


fs=100000;
t=0:1/fs:1.5;
x=sawtooth(2*pi*100*t,0.5);
plot(t,x);
axis([0 0.05 -1 1]);
xlabel('time index t(sec)');
ylabel('amplitude');
title('triangular wave signal

sequence');

F) MATLAB Program to generate Sine Wave Signal


N=20;
t=-N:0.001:N;
theta=input('The Phase angle is');
x=sin(2*pi*50*t+theta);
plot(t,x);
axis([-0.04 0.04 -1 1]);
grid;
xlabel('Time index t(sec)');
ylabel('Amplitude');
title('sinusoidal signal');

G) MATLAB Program to generate Ramp Signal


t=0:0.01:1;
y=0.5*t;
plot(t,y);
xlabel('time index t(sec)');
ylabel('amplitude');
title('Ramp signal sequence');

H) MATLAB Program to generate Sinc Signal


t=linspace(-5,5);
y=sinc(t);
subplot(2,1,1);
plot(t,y)
xlabel('time index t(sec)');
ylabel('amplitude');
title('sine function');
subplot(2,1,2);
stem(t,y);
xlabel('time index t(sec)');
ylabel('amplitude');
title('sine function');

EXPERIMENT -3
A) MATLAB Program to perform Addition of two Signals
t=(0:0.01:1);
f1=2;
s1=sin(2*pi*f1*t);
grid;
subplot(3,1,1);
plot(t,s1);
xlabel('time')
ylabel('amplitude')
title('signal1')
f2=4;
s2=3*sin(2*pi*f2*t);
subplot(3,1,2);
plot(t,s2);
xlabel('time');
ylabel('amplitude');
title('signal2');
subplot(3,1,3);
plot(t,s1+s2);
xlabel('time');
ylabel('amplitude');
title('signal 3');

B) MATLAB Program to perform Multiplication of two Signals


t=(0:0.01:1);
f1=2;
s1=sin(2*pi*f1*t);
grid;
subplot(3,1,1);
plot(t,s1);
xlabel('time');
ylabel('amplitude');
title('signal1');
f2=4;
s2=3*sin(2*pi*f2*t);
subplot(3,1,2);
plot(t,s2);
xlabel('time');
ylabel('amplitude');
title('signal2');
subplot(3,1,3);
plot(t,s1.*s2);
xlabel('time');
ylabel('amplitude');
title('signal3');

C) MATLAB Program to perform Scaling operation on Signal


clc;
clear all;
N=input('Type the desired length of the signal');
t=0:0.001:N-1;
x=sin(2*pi*1/10*t);
A=input('Input scale factor');
y=A*x;
figure;
subplot(2,1,1);
plot(t,x);
axis([0 N-1 -A A]);
grid;
xlabel('time in sec');
ylabel('magnitude x(t)');
title('sine wave form');
subplot(2,1,2);
plot(t,y);
axis([0 N-1 -A A]);
grid;
xlabel('time in sec');
ylabel('magnitude y(t)');
title('scaled sine wave form');

D) MATLAB Program to perform Folding operation of Signal


clc;
clear all;
t=0:0.1:10;
x=0.5*t;
lx=length(x);
nx=0:lx-1;
nf=-fliplr(nx);
xf=fliplr(x);
subplot(2,1,1);
stem(nx,x);
xlabel('time index nx');
ylabel('magnitude x(nx)');
title('Original signal');
subplot(2,1,2);
stem(nf,xf);
xlabel('time index nf');
ylabel('magnitude of folded signal xf(nf)');
title('Folded signal');

E) MATLAB Program to perform Shifting operation on Signal


clc;
clear all;
x=input('type the samples of signal');
n1=input('type the time origin at which the signal sample is');
N=length(x);
n2=n1+N-1;
n=n1:n2;
disp('the program will ask amount of shift');
disp('Enter positive no for delay,negative no for advanced');
disp('press any key to contiue');
pause;
d=input('Enter desired amount of shift');
nn=n+d;
xs=x;
subplot(2,1,1);
stem(n,x);
xlabel('time index n');
ylabel('signal x(n)');
title('Original signal');
subplot(2,1,2);
stem(nn,xs);
xlabel('time index nn');
ylabel('magnitude of shifted signal xs(nn)');
title('Shifted signal');

F) MATLAB Program to perform computation of Energy of Signal


clc;
clear all;
n=0:1:50;
x=(1/2).^n;
stem(n,x);
axis([0 25 0 1]);
disp('calculated energy E of signal is');
E_cal=sum(abs(x).^2)
disp('Theoretical signal energy is');
E_Theory=4/3

G) MATLAB Program to perform computation of Power of Signal


clc;
clear all;
N=input('type value for N');
t=-N:0.001:N;
x=cos(2*pi*50*t).^2;
disp('calculated power of signal is');
p_calc=sum(abs(x).^2)/length(x);
plot(t,x);
axis([0 0.1 0 1]);
disp('Theoretical power of signal is');
p_Theory=3/8

EXPERIMENT -4
MATLAB Program to find Even and Odd parts of signal and also to find real
and imaginary parts of signals
clc;
clear all;
x=[0,2+j*4,-3+j*2,5-j*1,-2-j*4,-j*3,0];
n=-3:3;
xc=conj(x);
xc_folded=fliplr(xc);
xc_even=0.5*[x+xc_folded];
xc_odd=0.5*[x-xc_folded];
figure;
subplot(2,1,1);
stem(n,real(x));
title('real part of complex signal x(n)');
xlabel('time index n');
ylabel('magnitude of real part of x(n)');
subplot(2,1,2);
stem(n,imag(x));
title('imaginary part of complex signal x(n)');
xlabel('time index n');
ylabel('magnitude of imaginary part of x(n)');
figure;
subplot(2,1,1);
stem(n,real(xc_even));
title('real part of even signal xc_even');
xlabel('time index n');
ylabel('magnitude of real part of xc_even');
subplot(2,1,2);
stem(n,imag(xc_even));
title('imaginary part of even signal xc_even');
xlabel('time index n');
ylabel('magnitude of imaginary part of xc_even');
figure;
subplot(2,1,1);
stem(n,real(xc_odd));
title('real part of odd signal xc_odd');
xlabel('time index n');
ylabel('magnitude of real part of xc_odd');
subplot(2,1,2);
stem(n,imag(xc_odd));
title('imaginary part of odd signal xc_odd');
xlabel('time index n');
ylabel('magnitude of imaginary part of xc_odd');

You might also like