SS Practical
SS Practical
Program:
close all;
clear all; x=input('Enter first
sequence'); subplot(2,3,1);
stem(x);
title('First sequence'); y=input('Enter
second sequence');
subplot(2,3,2);
stem(y); title('Second
sequence');
%Addition
A=x+y;
subplot(2,3,3);
stem(A);
title('Addition');
%Substraction S=x-
y; subplot(2,3,4);
stem(S);
title('Substraction');
%Multiplication
M=x.*y;
subplot(2,3,5);
stem(M);
title('Multiplication');
%Division
A=x./y;
subplot(2,3,6);
stem(A);
title('Division');
Command window:
Enter first sequence [2 6 8 1]
Enter second sequence [4 6 2 5]
Output:
Subject : Signal and system (Lab)
Name: Mayur Ramesh Chavan Roll No.: 46
Class: SY B. Tech Batch: A3 Div : A
Title : Matlab code to generate waveforms
Program:
clear all; close all; n=-
3:1:3; y=[zeros(1,3) 1
zeros(1,3)]; subplot(3,3,1);
stem(n,y); xlabel('Time
index n');
ylabel('Amplitude');
title('Unit impluse sequence');
%program for genetration of unit step
sequence y1=[zeros(1,3) 1 ones(1,3)];
subplot(3,3,2); stem(n,y1); xlabel('Time index
n'); ylabel('Amplitude'); title('Unit step
sequence');
%program for genetration of ramp
sequence m=input('Enter the first
sequence'); n1=0:1:10; if m>0 m=n1;
else
m=0; end
subplot(3,3,3);
stem(n1,m);
xlabel('Time
index n’ );
ylabel('Ampliu
de');
title('Ramp
sequence');
%program for genetration of sine sequence
n=0:0.01:pi;
y=sin(2*pi*n);
subplot(3,3,4);
stem(n,y); xlabel('Time
index n');
ylabel('Amplitude');
title('Sine sequence');
%program for genetration of cosine sequence
t=0:0.01:pi;
y=cos(2*pi*n);
subplot(3,3,5);
stem(n,y); xlabel('Time
index n');
ylabel('Amplitude');
title('Cosine sequence');
%program for genetration of flipper
signal x=[1 2 4 2 8 6]; subplot(3,3,6);
stem(x); rx=fliplr(x); subplot(3,3,7);
stem(rx);
Command window:
Enter the first sequence [2 4 6]
Output:
Subject: Signal and System (Lab)
Name: Mayur Ramesh Chavan Roll No: 46
Class: SY B. Tech Batch: A3 Div : A
Title: Matlab code for finding linearity of system
Program :
%y(n)=a*x(n)=b
clear all;
close all;
a=input('enter the coefficient a');
b=input('enter the constant b');
x1=input('enter the first input sequence');
x2=input('enter the second input sequence');
a1=input('enter the scale factor a1');
a2=input('enter the scale factor a2');
if length(x1)>length(x2)
x2=[x2zeros(1,length(x1)-length(x2))];
else
x1=[x1zeros(1,length(x2)-length(x1))];
end
X=a1*x1+a2*x2;
Y=a*X+b;
Y1=a*x1+b;
Y2=a*x2+b;
Y3=a1*Y1+a2*Y2;
if Y==Y3
disp('given system in linear'); end
subplot(2,1,1);
plot(abs(Y1));
subplot(2,1,2);
plot(abs(Y3));
Command window :
enter the coefficient a 6 enter the
constant b 1 enter the first input
sequence[1 6 4 7] enter the second
input sequence[8 9 5 3]
enter the scale factor a1 7
enter the scale factor a2 3
Output :
Subject: Signal and System (Lab)
Name: Mayur Ramesh Chavan Roll No: 46
Class: SY B. Tech Batch: A3 Div : A
Title: Matlab code for alising and sampling.
Program
%Aliasing program
clear all; close all; n=[0:20];%N=10. so 20 sample will give
display of 2 cycles
f=input('enter audio signal frequency');
fs=input('enter sampling signal frequency');
%fd is digital frequency
fd=f/fs;
%xn is discrete time sequence
xn=3*sin(2*pi*fd*n);
%plot the sequence xn
figure(1);
subplot(2,1,1);stem(n,xn);
%plot the analog signal xt
t=[0:0.0001:2*(1/f)];
xt=3*sin(2*pi*f*t);
subplot(2,1,2);
plot(t,xt);
%discrete signal xln if higher frequency is sampled at the same
rate
x1=input('enter frequency>fs\n');
x1n=3*sin(2*pi*(x1/fs)*n);
figure(2);
subplot(2,1,1); stem(n,x1n);
title('samples of 3300 Hz signal')
%another discrete signal x2n if higher frequency is sampled at
the same %rate x2=input('enter another frequency>fs\n');
x2n=3*sin(2*pi*(x2/fs)*n);
subplot(2,1,2); stem(n,x1n);
title('samples of 30300 hz signal');
command window
:
Output:
Subject: Signal and System (Lab)
Name: Mayur Ramesh Chavan Roll No: 46
Class: SY B. Tech Batch: A3 Div : A
Title: Matlab code to perform linear convolution
Program
clear all;
clc;
x=input('input input sequence'); h=input('input
impulse sequence');
i=length(x);
j=length(h);
Y=zeros(1,(i+j-1));
for m=1:i
for n=1:j
Y(m+n-1)=Y(m+n-1)+x(m)*h(n);
end end subplot(2,2,1); stem(x);
subplot(2,2,2); stem(h);
subplot(2,2,3); stem(Y); p=conv(x,h);
subplot(2,2,4); stem(p);
command window:
input input sequence [2 5 6 9]
input impulse sequence [4 7 8 9]
Output:
Subject: Signal and System (Lab)
Name: Mayur Ramesh Chavan Roll No: 46
Class: SY B. Tech Batch: A3 Div : A
Title: Matlab program to find the z-transform of some standard
signals
Program
Output :
Program
%y(n)=a*x(n)+b x=input('enter
the sequence');
d=input('enter the delay factor');
a=input('enter the coefficient a');
b=input('enter the constan b');
xd=[zeros(1,d)]; y=a*x+b;
yd=[zeros(1,d)]; y1=a*xd+b;
if y1==yd
disp('given system is time invariant'); else
disp('given system is time variant');
end
subplot(2,1,1);
plot((yd)); title('delay
output');
subplot(2,1,2);
plot((y1));
title('output with delayed input');
Command window:
enter the sequence[4 2 8 6]
enter the delay factor 4 enter
the coefficient a 6 enter the
constant b 8
given system is time
variant
Output:
Subject: Signal and System (Lab)
Name: Mayur Ramesh Chavan Roll No:46
Class: SY B. Tech Batch: A3 Div : A
Title: Matlabp rogram for PDF and CDF of Uniform and Normal
signal
Program
clear all;
close all;
x=unifrnd(1,2,[1,1000]);
subplot(3,2,1); plot(x);
title('uniform random signal');
x1=unifpdf(x,1,2); subplot(3,2,2);
plot(x,x1); title('PDF of uniform
random signal');
x2=unifcdf(x,1,2);
subplot(3,2,3); plot(x,x2); title('CDF
of uniform random signal');
y=normrnd(1,2,[1,100]);
subplot(3,2,4); plot(y);
title('Normal random signal');
y1=normpdf(y,1,2);
subplot(3,2,5);
plot(y,y1); title('PDF of Normal
random signal'); y2=normcdf(y,1,2);
subplot(3,2,6);
plot(y,y2); title('CDF of Normal
random signal');
Output:
Subject: Signal and System (Lab)
Name: Mayur Ramesh Chavan Roll No: 46
Class: SY B. Tech Batch: A3 Div : A
Title: Matlab code for calculating autocorrelation.
Program:
Code: N=96;
n=1:N;
x=cos(pi*0.25*n)
d=rand(1,N)-0.5
y=x+d;
r=conv(y,fliplr(y))
k=-28:28;
stem(k,r(68:124))
xlabel('Lag Index')
ylabel('Amplitude')
title('Auto Correlation Of Noise Corrupted Sinosidle Sequnce')
Output: