Matlab Record
Matlab Record
____________________________________________________
1.(a). BASIC OPERATIONS ON MATRICES
AIM:
APPARATUS:
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:
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.
AIM:
APPARATUS:
Page | 4
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
PROGRAM:
clc;
clear all;
close all;
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.
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:
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:
RESULT:
Thus, a program to find maximum and minimum values of a number is
successfully executed.
AIM:
To find the ascending and descending order of a given number
Page | 7
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
APPARATUS:
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:
z = 5 15 43 65 78
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.
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:
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.
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:
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:
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
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.
AIM:
To find even and odd parts of a signal, real and imaginary parts of signal in
discrete time
APPARATUS:
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)');
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.
AIM:
Page | 24
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
To write a MATLAB program to generate operations on signals and sequence
APPARATUS:
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');
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:
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.
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:
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);
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
RESULT:
Thus, a program to find the MATLAB program to verify linearity property of a
system is executed successfully.
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:
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:
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.
AIM:
To write a MATLAB program to find convolution between sequences:
APPARATUS:
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:
OUTPUT:
Page | 41
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
RESULT:
The MATLAB program for convolution between sequence is successfully
executed.
Page | 42
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
AIM:
To write a MATLAB program to find the convolution between the signals
APPARATUS:
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.
Page | 44
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
AIM:
To write a MATLAB program on auto correction and cross relation between
sequences
APPARATUS:
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:
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.
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:
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.
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:
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:
H = s^2 + s + 1
------------------------
s^3 + 17 s^2 + 16 s + 12
RESULT:
The program to find the poles and zeroes in s plane is successfully executed.
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:
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:
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:
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:
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:
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:
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:
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:
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:
Page | 63
S V UNIVERSITY COLLEGE OF ENGINEERING, TIRUPATI.
____________________________________________________
OUTPUT:
RESULT:
Page | 64