You are on page 1of 64

S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.

____________________________________________________
1.(a). BASIC OPERATIONS ON MATRICES
AIM:

To write a MATLAB program on basic operations of matrices

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


clc clears all input and output from command
clc window display giving a clear screen

Display prompt can be any MATLAB


expression which is evaluated using variable in
input(‘prompt’) current workspace

Display an array without printing the array


disp(x) name. If x is a string, it is displayed

det(A) The function returns the determinant of


square matrix A

inv(A) The function returns the inverse of square


matrix of A. A warning is given if A is a singular
matrix

PROGRAM:

clc;
clear all;

close all;
a=input('enter matrix a');
Page | 1
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
b=input('enter matrix b');
disp('....');
disp('addition of matrices');
c=a+b
disp('subtraction of matrices:');
d=a-b
disp('multiplication of matrices ');
e=a*b
disp('transpose of matrix b :');
f=b'
disp (' transpose of matrix a:');
g=a'
disp('determinent of matrix a :');
h=det(a)
disp('determinent of matrix b :');
i=det(b)
disp ('inverse of a ');
j=inv(a)
disp('inverse of b')
k=inv(b)
disp('....');

OUTPUT:

enter matrix a[1 2; 3 1]


enter matrix b[3 4;3 2]
....
addition of matrices

c= 4 6
6 3

Page | 2
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
subtraction of matrices:
d = -2 -2
0 -1
multiplication of matrices
e= 9 8
12 14
transpose of matrix b:
f= 3 3
4 2
transpose of matrix a:
g= 1 3
2 1
determinant of matrix a:
h = -5
determinant of matrix b :
i = -6
inverse of a
j = -0.2000 0.4000
0.6000 -0.2000
inverse of b
k = -0.3333 0.6667
0.5000 -0.5000
RESULT:
Thus, the matrix operations addition, subtraction, multiplication, transpose,
determinant and inverse of matrices are successfully executed.

1.(b). FACTORIAL OF A GIVEN NUMBER


Page | 3
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

AIM:

To find factorial of a given umber using MATLAB

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


It clears the variables in MATLAB
clear all expression, which is in current work space

It clears the diagrams and pictures in the


close all current work space

Factorial(n) for a scalar n is the product of


factorial(n) integer from 1 to n

It is the factorial for a scalar ‘n’ is the


prod(1:a) product of integers from 1 to n

if(condition) This provides a means for structure for


statement 1 choosing one group of commands out of
else two possible
statement 2 groups of execution

Page | 4
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

PROGRAM:

clc;

clear all;

close all;

disp('factorial of a given number');

disp('----');
a=input('enter a number');
if(a>=0)
disp('factorial of a given number is:');
disp(prod(1:a));
else
disp('factorial is not possible');
end;

OUTPUT:

enter a number6
factorial of a given number is:
720

RESULT:
Thus, the factorial of the given number is successfully executed.

1.(c). MAXIMUM AND MINIMUM VALUES OF A NUMBER

Page | 5
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
AIM:
To find maximum and minimum values in a given set of numbers using MATLAB

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


min(A) Displays the minimum value of ‘a’

max(A) Displays the maximum value of ‘a’

PROGRAM:

clc;
clear all;
close all;
a = input('enter the values');
c=min(a);
disp('the minimum value of a ');c
d=max(a);
disp('the maximum value of a ');d

OUTPUT:

enter the values [12 13 14]

the minimum value of A is


c = 12

the maximum value of a is


Page | 6
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
d = 14

RESULT:
Thus, a program to find maximum and minimum values of a number is
successfully executed.

1.(d). ASCENDING AND DESCENDING ORDER, SORTTNG OF


GIVEN NUMBER

AIM:
To find the ascending and descending order of a given number
Page | 7
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


Arranges the values either in
sort(x) ascending order or descending order

PROGRAM:
clc;
clear all;
close all;
a=input('enter the values ');
disp('ascending order of values of a');
z=sort(a)
disp('descending order of values of a');
y=sort(a,'descend')

OUTPUT:

enter the values [5 78 65 43 15]

ascending order of values of a

z = 5 15 43 65 78

descending order of values of a

Page | 8
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

y = 78 65 43 15 5

RESULT:
Thus, to find the ascending and descending order of given numbers was
successfully executed.

2.(a). GENERATION OF SIGNALS

AIM:

To generate various signals such as unit step, unit impulse, square , saw tooth,
triangular, sinusoidal and ramp sine function
Page | 9
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


subplot(m,n,p) Divides current plane into rectangular
plane an output to current plane on
axis in pth plane of figure divided into
m by n matrix

plot(x,y) It is used to plot x value and y value in


graph

Xlabel(string) Each axis graphics objects can have


one label

For x,y axis, the label appears beneath


Ylabel(string) its respective axis in 2.O plot

title(‘string’) Add title to the axis

PROGRAM:

clc;
clear all;
close all;
tmin=-5;dt=0.1;tmax=5;
t=tmin:dt:tmax;
Page | 10
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
x1=1;
x2=0;
x=x1.*(t==0)+x2.*(t~=0);
subplot(3,3,1);plot(t,x);xlabel('time');ylabel('amplitude');
title('unit impulse signal');
x1=1;
x2=0;
x=x1.*(t>=0)+x2.*(t<0);
subplot(3,3,2);plot(t,x);xlabel('time');ylabel('amplitude');
title('unit step signal');
a=2;
x1=1-abs(t)/a;
x2=0;
x=x1.*(abs(t)<=a)+x2.*(abs(t)>a);
subplot(3,3,3);plot(t,x);xlabel('time');ylabel('amplitude');
title('triangular signal');
T=5;
f=1/T;
x=sin(2*pi*f*t);
subplot(3,3,4);plot(t,x);xlabel('time');ylabel('amplitude');
title('sinusoidal signal');
x1=t;

x2=0;
x=x1.*(t>=0)+x2.*(t<0);
subplot(3,3,5);plot(t,x);xlabel('time');ylabel('amplitude');
title('unit ramp signal');
x=sinc(t);
subplot(3,3,6);plot(t,x);xlabel('time');ylabel('amplitude');
title('sinc signal');
fs=1000;
t=0:1/fs:1.5;
x=sawtooth(2*pi*100*t);
Page | 11
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
subplot(3,3,7);plot(t,x);xlabel('time');ylabel('amplitude');
axis([0,0.1,-1,1]);title('sawtooth signal');
t=(0:0.01:1);
sq.wave=square(4*pi*t);
subplot(3,3,8);plot(t,sq.wave);xlabel('time');ylabel('amplitude');
title('square signal');

OUTPUT:

Page | 12
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

RESULT:

Thus, the program to generate various signals such as unit step, unit impulse,
square, saw tooth, triangular, sinusoidal, ramp and sinc function is successfully
executed.

2.(b). GENERATION OF SEQUENCES

Page | 13
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
AIM:

To generate various sequence such as unit step, unit impulse, square, triangular,
saw tooth, sinusoidal, ramp and sinc function

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


stem(x,y) Used to plot x,y value graph in
discrete signal

PROGRAM:

clc;
clear all;
close all;
nmin=-5;dn=0.5;nmax=5;
n=nmin:dn:nmax;
x1=1;
x2=0;
x=x1.*(n==0)+x2.*(n~=0);
subplot(3,3,1);stem(n,x);xlabel('time');ylabel('amplitude');
title('unit impulse sequence');
x1=1;x2=0;
x=x1.*(n>=0)+x2.*(n<0);
subplot(3,3,2);stem(n,x);xlabel('time');ylabel('amplitude');
title('unit step sequence');
a=2;

x1=1-abs(n)/a;
x2=0;
x=x1.*(abs(n)<=a)+x2.*(abs(n)>a);
Page | 14
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
subplot(3,3,3);stem(n,x);xlabel('time');ylabel('amplitude');
title('triangular sequence');
T=5;
f=1/T;
x=sin(2*pi*f*n);
subplot(3,3,4);stem(n,x);xlabel('time');ylabel('amplitude');
title('sinusoidal sequence');
x1=n;
x2=0;
x=x1.*(n>=0)+x2.*(n<0);
subplot(3,3,5);stem(n,x);xlabel('time');ylabel('amplitude');
title('unit ramp sequene');
x=sinc(n);
subplot(3,3,6);stem(n,x);xlabel('time');ylabel('amplitude');
title('sinc sequence');
n=(0:0.1:1);
sq.wave=square(2*pi*2*n);
subplot(3,3,7);stem(n,sq.wave);xlabel('time');ylabel('amplitude');
title('square sequence');
fs=1000;
n=0:1/fs:1.5;
x=sawtooth(2*pi*100*n);
subplot(3,3,8);stem(n,x);xlabel('time');ylabel('amplitude');
axis([0,0.1,-1,1]);
title('sawtooth sequence');

OUTPUT:
Page | 15
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

RESULT:

Thus, the program to generate various sequence such as unit step, unit
impulse, square, triangular, saw tooth, sinusoidal, ramp, sinc function is
successfully executed.

Page | 16
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
3.(a). EVEN AND ODD PARTS OF A SIGNAL AND REAL AND
IMAGINARY PARTS SIGNAL IN CONTINUOUS TIME
AIM:
To find even and odd parts of a signal , real and imaginary parts of a signal in
continuous time

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


img(a) It represents the imaginary part of the
signal a

PROGRAM:

clc;
clear all;
close all;
tmin=-3;dt=0.1;tmax=3;
t=tmin:dt:tmax;
x1=exp(2*t);
x2=exp(-2*t);
if(x2==x1)
disp('the given signal is even');
elseif(x2==(-x1))
disp('given signal is odd');
else

disp('the given signal is neither even nor odd ');

Page | 17
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
end
xe=(x1+x2)/2;
xo=(x1-x2)/2;
y=xe+xo;
ymin=min([min(x1),min(x2),min(xe),min(xo)]);
ymax=max([max(x1),max(x2),max(xe),max(xo)]);
subplot(3,3,1);
plot(t,x1);
axis([tmin tmax ymin ymax]);
xlabel('t');
ylabel('x1(t)');
title('signalx(t)');
subplot(3,3,2);
plot(t,x2);
axis([tmin tmax ymin ymax]);
xlabel('t');
ylabel('x2(t)');
title('signalx(t)');
subplot(3,3,3);
plot(t,xe);
axis([tmin tmax ymin ymax]);
xlabel('t');
ylabel('xe(t)');
title('signalx(t)');
subplot(3,3,4);
plot(t,xo);
axis([tmin tmax ymin ymax]);
xlabel('t');

ylabel('xo(t)');
title('signalx(t)');
subplot(3,3,5);
plot(t,y);
axis([tmin tmax ymin ymax]);
Page | 18
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
xlabel('t');
ylabel('y(t)');
title('sum of even and odd');
subplot(3,3,6);
plot(t,real(x1));
axis([tmin tmax ymin ymax]);
xlabel('t');
ylabel('real(x1)');
title('real part of x1(t)');
subplot(3,3,7);
plot(t,imag(x1));
axis([tmin tmax ymin ymax]);
xlabel('t');
ylabel('imag(x1)');
title('imaginary part of x1(t)');

Page | 19
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
OUTPUT:

RESULT:
Thus, even and odd parts of a signal, real and imaginary parts of signal in
continuous time is successfully executed.

3.(b). EVEN AND ODD PARTS OF A SIGNAL AND REAL AND


IMAGINARY PARTS OF A SIGNAL IN DISCRTE TIME
Page | 20
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

AIM:
To find even and odd parts of a signal, real and imaginary parts of signal in
discrete time

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


end It terminates block of code

PROGRAM:
clc;
clear all;
close all;
nmin=-3;nmax=3;dn=0.5;
n=nmin:dn:nmax;
x1=exp(2*n);
x2=exp(-2*n);
if(x2==x1)
disp('even');
else if(x2==(-x1))
disp('odd');
else
disp('neither even nor odd');
end

end
xe=(x1+x2)/2;
xo=(x1-x2)/2;
y=xe+xo;
Page | 21
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
ymin=min([min(x1),min(x2),min(xe),min(xo)]);
ymax=max([max(x1),max(x2),max(xe),max(xo)]);
subplot(3,3,1);
stem(n,x1);
axis([nmin nmax ymin ymax]);
xlabel('n');
ylabel('x1(n)');
title('signal x(n)');
subplot(3,3,2);
stem(n,x2);
axis([nmin nmax ymin ymax]);
xlabel('n');
ylabel('x2(n)');
title('signal x(-n)');
subplot(3,3,3);
stem(n,xe);
axis([nmin nmax ymin ymax]);
xlabel('n');
ylabel('xe(n)');
title('even part of x(n)');
subplot(3,3,4);
stem(n,xo);
axis([nmin nmax ymin ymax]);
xlabel('n');
ylabel('xo(n)');

title('odd part of x(n)');


subplot(3,3,5);
stem(n,y);
axis([nmin nmax ymin ymax]);
xlabel('n');
ylabel('y(n)');
title('sum of even and odd');
subplot(3,3,6);
Page | 22
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
stem(n,real(x1));
axis([nmin nmax ymin ymax]);
xlabel('n');
ylabel('real(x1)');
title('real part of x1(n)');
subplot(3,3,7);
stem(n,imag(x1));
axis([nmin nmax ymin ymax]);
xlabel('n');
ylabel('imag(x1)');
title('imaginary part of x1(n)');

OUTPUT:

Page | 23
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

RESULT:
Thus, even and odd parts of signal, real and imaginary parts of signal is
executed successfully.

4. OPERATIONS ON SIGNALS AND SEQUENCES

AIM:
Page | 24
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
To write a MATLAB program to generate operations on signals and sequence

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


stem(x,y) Used to plot x, y value graph in
discrete signal

PROGRAM:

clc;
clear all;
close all;
% continous signal
t=0:pi/100:2*pi;
x1=sin(t);
subplot(4,4,1);
plot(t,x1);
grid on
xlabel('t');
ylabel('sin(t)');
title('plot the sine function');
x2=cos(t);
subplot(4,4,2);
plot(t,x2);

grid on
xlabel('t');
ylabel('cos(t)');
title('plot the cosine function');
Page | 25
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
x=x1+x2;
subplot(4,4,3);
plot(t,x);
grid on
xlabel('t');
ylabel('additon of signals');
title('plot the additon of signals ');
x3=x1.*x2;
subplot(4,4,4);
plot(t,x3);
grid on
xlabel('t');
ylabel('multiplication of signals');
title('plot the multiplication of signals ');
x4=4*x1;
subplot(4,4,5);
plot(t,x4);
grid on
xlabel('t');
ylabel('scaling of signal');
title('plot the scaling of signal');
subplot(4,4,6);
plot(t-2,x1);
grid on
xlabel('t');

ylabel('time shifting of signal');


title('plot the time shifting of signal');
x5=-x1;
subplot(4,4,7);
plot(-t,x5);
grid on
xlabel('t');
Page | 26
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
ylabel('time folding of signal');
title('plot the time folding of signal');
x6=x1.^2;
x7=trapz(x6);
subplot(4,4,8);
plot(t,x6);
grid on
xlabel('t');
ylabel('energy');
title('plot the energy of signal');
x8=x7%t;
subplot(4,4,9);
plot(t,x8);
grid on
xlabel('t');
ylabel('power');
title('plot the power of signal');
% discrete signal
a1=0:2:10;b1=[0,1,2,3,4,5];
subplot(4,4,10);
stem(b1);
grid on

xlabel('n');
ylabel('amplitude');
title('plot the discrete signal');
b2=[0,1,2,3,4,5];
subplot(4,4,11);
stem(b2);
grid on
xlabel('n');
ylabel('amplitude');
title('plot the discrete signal');
Page | 27
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
b3=b1+b2;
subplot(4,4,12);
stem(b3);
grid on
xlabel('n');
ylabel('addition');
title('plot the addition of discrete signal');
b4=b1.*b2;
subplot(4,4,13);
stem(b4);
grid on
xlabel('n');
ylabel('multiplication');
title('plot the multiplication of discrete signal');
b5=2*b1;
subplot(4,4,14);
stem(b5);
grid on
xlabel('n');
ylabel('scaling');
title('plot the scaling of discrete signal');
subplot(4,4,15);
stem(a1-1,b1);
grid on
xlabel('n');
ylabel('shifting');
title('plot the shifting of discrete signal');
b6=-b1;
subplot(4,4,16);
stem(b6);
grid on
xlabel('n');
ylabel('folding');
title('plot the folding of discrete signal');
Page | 28
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

OUTPUT:

RESULT:
Thus, a program to generate operations on signals and sequence is executed
successfully.
5.FINDING FOURIER TRANSFORM OF SIGNAL AND PLOT ITS
MAGNITUDE AND PHASE RESPONSE

AIM:
Page | 29
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
To write a MATLAB program to find the Fourier transform for a signal and plot
its magnitude and signal

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


It gives the fourier transform for the
fourier(x) given signal x(t)

It indicates magnitude spectrum and


abs(x) & atan (img(y)/real of (y)) phase response of fourier transform
of signal x(t)

PROGRAM:

clc;
clear all;
close all;
Xn=[1 1 1];
N=50;
Xk=fft(Xn,N);
magXk=abs(Xk);

angXk=angle(Xk);
k=0:N-1;
subplot(2,1,1);
stem(k,magXk);
xlabel('k');
ylabel('|X(k)|');
Page | 30
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
subplot(2,1,2);
stem(k,angXk);
xlabel('k');
ylabel('arg(X(k))');

OUTPUT:

RESULT:
Thus, a MATLAB program for Fourier transform of a signal and its magnitude
and phase response is executed successfully.

6.(a).TO VERIFY LINEARITY PROPERTY OF A SYSTEM


(DISCRETE SEQUENCE)

AIM:

Page | 31
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
To write a MATLAB program to verify the given systems is linear or non linear
system

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


conv(h) It indicates the convolution between
the two signals x and h

PROGRAM:
clc;
close all;
clear all;
x1=input('type the samples of x1');
x2=input('type the samples of x2');
if(length(x1)~=length(x2))
disp('error=length of x1 and x2 are different');
return;
end;
h=input('type the samples of h[n]');
w=length(x1)+length(h)-1;
disp('length of output signal will be');
disp(w);

a1=input('the scale factor a1 is');


a2=input('the scale factor a2 is');
x=a1*x1+a2*x2;
y01=conv(x,h);
y1=conv(x1,h);
%scaled response of x1
Page | 32
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
y13=a1*y1;
y2=conv(x2,h);
%scaled response of x2
y23=a2*y2;
y2=conv(x2,h);
y02=y13+y23;
disp('output sequence y01 is');
disp(y01);
disp('output sequence y02 is');
disp(y02);
if(y01==y02)
disp('the system is linear');
else
disp('the system is non linear');
end;

OUTPUT:
type the samples of x1 [5 3 7]
type the samples of x2[2 1 8]
type the samples of h[n] [8 6]
length of output signal will be
4

the scale factor a1 is2


the scale factor a2 is 3
output sequence y01 is
128 168 358 228

output sequence y02 is


128 168 358 228

the system is linear


Page | 33
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

RESULT:
Thus, a program to find the MATLAB program to verify linearity property of a
system is executed successfully.

6.(b).TO VERIFY TIME INVARIANCE PROPERTY OF A SYSTEM

AIM:
To write a MATLAB program to verify the system is time invariant or time
variant.

APPARATUS:
Page | 34
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
PC loaded with MATLAB 2019

PROGRAM:
clc;
clear all;
close all;
x=input('enter the sequence x[n]');
h=input('enter the sequence h[n]');
d=input ('enter the positive number for delay d=');
xdn=[zeros(1,d),x];
yn=conv(xdn,h);
y=conv(x,h);
ydn=[zeros(1,d),y];
figure;
subplot(2,1,1);
stem(0:length(x)-1,x);
xlabel('n');
ylabel('amp');
title('the sequence of x[n]');
subplot(2,1,2);stem(0:length(xdn)-1,xdn);
xlabel('n');
ylabel('amp');
title('the delayed sequence of x[n]');figure;
subplot(2,1,1);stem(0:length(yn)-1,yn);
xlabel('n');

ylabel('amp');
title('the response of the system to the delayed sequence of x[n]');
figure;
subplot(2,1,2);stem(0:length(ydn)-1,ydn);
xlabel('n');
ylabel('amp');
title('the delayed output sequence is')
Page | 35
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
if(yn==ydn)
disp ('the given system is a time invariant system');
else
disp('the given system is a time variant system');
end;

OUTPUT:

enter the sequence x[n][1 2 3]


enter the sequence h[n] [2 2 1]
enter the positive number for delay d=2

the given system is a time invariant system

Page | 36
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

RESULT:
Thus, the MATLAB program to verify the time invariant property of a system is
successfully executed.

Page | 37
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
7.COMPUTATION OF UNIT STEP SAMPLE, UNIT STEP RESPONSE
AND SINUSOIDAL RESPONSE OF GIVEN SYSTEM

AIM:
To write a MATLAB program for computation of unit sample, unit step
response and sinusoidal responses of the given LTI system and verify its physical
realizability and stability properties.

APPARATUS:

PC loaded with MATLAB 2019

PROGRAM:

clc;
clear all;
close all;
b=[1 1 1];
a=[1 -1 0.9];
n=0:5:30;
x1=(n==0);
h1=filter(b,a,x1);
subplot(3,1,1);stem(n,h1);xlabel('n');ylabel('h(n)');title('impulse response');
x2=(n>0);
s=filter(b,a,x2);
subplot(3,1,2);stem(n,s);xlabel('n');ylabel('s(n)');title('step response');
t=0:0.5:3*pi;
x3=cos(t);
h=filter(b,a,x3);
subplot(3,1,3);stem(x3,h);xlabel('n');ylabel('n(s)');title('sinusoidal response');
figure;

zplane(b,a);

Page | 38
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

OUTPUT:

Page | 39
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

RESULT:
Thus, the MATLAB program for computation of unit sample, unit step and
sinusoidal response of a given system is successfully executed.

8.(a). CONVOLUTION BETWEEN SEQUENCES


Page | 40
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

AIM:
To write a MATLAB program to find convolution between sequences:

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


conv(x,y) It is the convolution of two signals or
sequences

PROGRAM:

clc;
clear all;
close all;
x=input('enter input sequence');
h=input('enter impulse response');
y=conv(x,h);
subplot(3,1,1);stem(x);xlabel('n');ylabel('x(n)');title('input sequence');
subplot(3,1,2);stem(h);xlabel('n');ylabel('h(n)');title('impulse response');
subplot(3,1,3);stem(y);xlabel('n');ylabel('y(n)');title('covolution');

INPUT:

enter input sequence[1 1 1]


enter impulse response[6 6 6]

OUTPUT:

Page | 41
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

RESULT:
The MATLAB program for convolution between sequence is successfully
executed.

8.(b). CONVOLUTION BETWEEN SIGNALS

Page | 42
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
AIM:
To write a MATLAB program to find the convolution between the signals

APPARATUS:

PC loaded with MATLAB 2019

PROGRAM:

clc;
clear all;
close all;
t=0:0.1:10;
x1=exp(-t);
h1=exp(2*t);
y1=conv(x1,h1);
figure;
subplot(3,1,1);plot(t,x1);xlabel('t');ylabel('x(t)');title('input signal');
subplot(3,1,2);plot(t,h1);xlabel('t');ylabel('h(t)');title('impulse signal');
subplot(3,1,3);plot(y1);xlabel('t');ylabel('y(t)');title('convolution');

OUTPUT:
Page | 43
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

RESULT:
The MATLAB program for convolution between signals is executed successfully.

9.(a). AUTO AND CROSS CORRELATION BETWEEN SEQUENCE

Page | 44
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
AIM:
To write a MATLAB program on auto correction and cross relation between
sequences

APPARATUS:

PC loaded with MATLAB 2019

FUNCTION AND SYNTAX DESCRIPTION


corr(x,y) It is the correlation of two signals and
sequences i.e x and y
corr(x,x) It is the auto correlation of the same
two signals and sequences

PROGRAM:

clc;
close all;
clear all;
x=input('enter input sequence');
h=input('enter impulse response');
subplot(2,2,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('input sequence');
subplot(2,2,2);
stem(h);
xlabel('n');
ylabel('h(n)');

title('input response');
Page | 45
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
y=xcorr(x,h);
subplot(2,2,3);
stem(y);
xlabel('n');
ylabel('y(n)');
title('cross correlation of sequences');
z=xcorr(x,x);
subplot(2,2,4);
stem(z);
xlabel('n');
ylabel('z(n)');
title('auto correlation of sequences');

INPUT:

enter input sequence[3 3 3]


enter impulse response[6 6 6]

OUTPUT:

Page | 46
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

RESULT:
Thus, the MATLAB program to find cross and auto correlation of sequences is
successfully executed.

9.(b). AUTO AND CROSS CORRELATION OF SIGNALS

AIM:
Page | 47
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
To write a MATLAB program to find the cross correlation and auto correlation
of signals

APPARATUS:

PC loaded with MATLAB 2019

PROGRAM:

clc;
clear all;
close all;
t=0:0.2:10;
x1=exp(+t);
h1=exp(2*t);
subplot(3,2,1);
plot(t,x1);
xlabel('t');
ylabel('x(t)');
title('input signal');
subplot(3,2,2);
plot(t,h1);
xlabel('t');
ylabel('h(t)');
title('impulse response');
y=xcorr(x1,h1);
subplot(3,2,3);
plot(y);
xlabel('t');
ylabel('y(t)');
title('cross correlation of signals');
z=xcorr(x1,x1);
subplot(3,2,4);
plot(z);
xlabel('t');
Page | 48
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
ylabel('z(t)');
title('auto correlation of signals');

OUTPUT:

RESULT:
The program to find the cross relation and auto correlation of signal is
successfully executed.

10.(a). LOCATION OF POLES AND ZEROES ON S-PLANE

AIM:
To write a MATLAB program to find the poles and zeroes of s plane
Page | 49
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

APPARATUS:

PC loaded with MATLAB 2019

PROGRAM:

clc;
close all;
clear all;
num=input('enter the numerator coefficients');
den=input('enter the denominator coefficients');
H=tf(num,den);
poles=roots(den)
zeros=roots(num)
sgrid
pzmap(H)
grid on
title('pole/zero of complex poles and zeros in s plane');

INPUT:

enter the numerator coefficiens[1 1 1]


enter the denominator coefficients[1 17 16 12]

H = s^2 + s + 1
------------------------
s^3 + 17 s^2 + 16 s + 12

Continuous-time transfer function

poles = -16.0497 + 0.0000i


-0.4752 + 0.7224i
Page | 50
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
-0.4752 - 0.7224i

zeros = -0.5000 + 0.8660i


-0.5000 - 0.8660i

RESULT:
The program to find the poles and zeroes in s plane is successfully executed.

10.(b). LOCATION OF POLES AND ZEROES IN Z-PLANE

AIM:
To write a MATLAB program to find the poles and zeroes in z plane

Page | 51
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
APPARATUS:

PC loaded with MATLAB 2019

PROGRAM:

clc;
close all;
clear all;
num=input('enter the numerator coefficients');
den=input('enter the denominator coefficients');
p=roots(den)
z=roots(num)
zplane(z,p);
title('pole/zero plot for complex poles and zeros in zplane')

INPUT:

enter the numerator coefficients[1 2 5]


enter the denominator coefficients[1 6 11 6]

p=
-3.0000
-2.0000
-1.0000

z=
-1.0000 + 2.0000i
-1.0000 - 2.0000i

OUTPUT:

Page | 52
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

RESULT:
The program to find the poles and zeroes in z plane is successfully executed.

Page | 53
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
11.SAMPLING A BAND LIMITED CONTINUOUS TIME SIGNAL

AIM:
To write a program to sample a band limited continuous time signal
(a) Nyquist rate
(b)Twice the Nyquist rate
(c)Half the Nyquist rate and fixed effect in each others

APPARATUS:

PC loaded with MATLAB 2019

PROGRAM:

clc;
clear all;
close all;
t=0:0.001:0.1;
fm=input('enter input frequency');
y=2*cos(2*pi*fm*t);
fs=input('enter sampling frequency');
ts=(1/fs);
tx=0:ts:0.1;
ys=2*cos(2*pi*fm*tx);
subplot(2,2,1);
plot(t,y);
xlabel('t-->');
ylabel('amp-->');
title('input signal');
subplot(2,2,2);

stem(tx,ys);
xlabel('t-->');
Page | 54
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
ylabel('amp-->');
title('sampled signal');
x=abs(fft(y,100));
subplot(2,2,3);
k=0:length(y)-1;
stem(x)
xlabel('frequency');
ylabel('amp-->');
title('spectrum of input signal');
p=abs(fft(ys,100));
k1=0:length(ys)-1;
subplot(2,2,4);
stem(p);
xlabel('freq-->');
ylabel('amp-->');
title('spectrum of sampled signal');

OUTPUT:

Enter input frequency 100


Enter sampling frequency 0.1

Page | 55
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

Page | 56
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

Page | 57
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

RESULT:

Thus, the band signal is sample at different Nyquist rates

Page | 58
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
12.(a). LOW PASS FILTER
AIM:
To write a MATLAB program to plot magnitude and the phase plots of
butterworth low pass and high pass filters

APPARATUS:

PC loaded with MATLAB 2019

PROGRAM:

%LPF
clc;
clear all;
close all;
rp=0.2;
rs=20;
fp=200;
fs=600;
f=2000;
wp=2*(fp/f);
ws=2*(fs/f);
[n,wn]=buttord(wp,ws,rp,rs);
[b,a]=butter(n,wn);
[h,w]=freqz(b,a);
subplot(2,2,1);
plot(w/pi,20*log(abs(h)));
grid;
xlabel('nf');
ylabel('mag');

title('mag response');
Page | 59
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
subplot(2,1,2);
plot(w/pi,angle(h));
grid;
xlabel('nf');
ylabel('angle');
title('phase response');

OUTPUT:

RESULT:
Thus, magnitude and phase plots of butterworth low pass filters are plotted
successfully using MATLAB program.
12.(b). HIGH PASS FILTER
Page | 60
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________

AIM:
To write a MATLAB program to plot magnitude and phase plots of butterworth
high pass filter

APPARATUS:

PC loaded with MATLAB 2019

PROGRAM:

%HPF
clc;
clear all;
close all;
rp=0.2;
rs=20;
fp=200;
fs=600;
f=2000;
wp=2*(fp/f);
ws=2*(fs/f);
[n,wn]=buttord(wp,ws,rp,rs);
[b,a]=butter(n,wn,'high');
[h,w]=freqz(b,a);
subplot(2,2,1);
plot(w/pi,20*log(abs(h)));
grid;
xlabel('nf');
ylabel('mag');

title('mag response');
subplot(2,1,2);
plot(w/pi,angle(h));
grid;
Page | 61
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
xlabel('nf');
ylabel('angle');
title('phase response');

OUTPUT:

RESULT:

Thus, magnitude and phase plots of butterworth high pass filter are plotted
successfully.

13.ESTIMATION OF PSD
Page | 62
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
AIM:
To write a MATLAB code to find the estimation of Power spectral density

APPARATUS:

PC loaded with MATLAB 2019

PROGRAM:

clc;

clear all;
close all;
t=0:0.001:0.6;
x=sin(2*pi*50*t)+sin(2*pi*120*t);
y=x+2*randn(size(t));
subplot(2,1,1);
plot(1000*t(1:50),y(1:50));
title('signal corrupted with zero mean random noise');
y=fft(y,512);
pyy=y.*conj( y)/512;
f=1000*(0:256)/512;
subplot(2,1,2);
plot(f,pyy(1:257));
title('frequency constent of y');

INPUT:

Enter filter coefficients:[3 4 5]


Enter the input sequence:[4 5 6]
Enter decimation factor:[2]
Coefficient of decimation analysis filter is:
6.6667+0.0000i , -3.3333+5.7735i

Page | 63
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
OUTPUT:

RESULT:

Thus, a program for estimation of power spectral density is successfully


executed.

Page | 64

You might also like