Sie sind auf Seite 1von 8

%Program for various discrete time signals

%Aim :- Use of stem for plotting discrete time signals


U=ones(1,21);
n=21;
subplot(3,2,1)
stem(U);
xlabel('X');
ylabel('Y');
title('Unit step signal');
%--------------------------------------------------------------
subplot(3,2,2);
for p=1:1:21 % Run a loop until it encounters an end
command.
x1(p)=sin(0.02*pi*p)+sin(0.03*pi*p); % Defines the signal
end

stem(x1);
xlabel('X');

%--------------------------------------------------------------
subplot(3,2,3)
for p=1:1:21

x2(p)=.8^p;

end
stem(x2);
%--------------------------------------------------------------

for p=1:1:21

x3(p)=1.2^p;

end
subplot(3,2,4)
stem(x3);
xlabel('n');
title('Exponential signal for a>1');
%--------------------------------------------------------------

subplot(3,2,5);
for p=1:1:21

x4(p)= p;

end
stem(x4);
xlabel('n');
ylabel('x4');
title('Ramp Signal');
%--------------------------------------------------------------
subplot(3,2,3);
xlabel('n');
ylabel('x2');
title('Exponential signal for a<1');
ylabel('x2');
%--------------------------------------------------------------

subplot(3,2,2);
xlabel('n');
ylabel('x1(n)');
title('Sinosoidal Signal');

%--------------------------------------------------------------

subplot(3,2,1);
xlabel('n');

%--------------------------------------------------------------
subplot(3,2,6);
for p=1:1:21
x5(p)=sin(0.03*pi*p)+cos(0.97*pi*p); % Defines the signal
end

stem(x5);
xlabel('n');
ylabel('x5(n)');

title('x5(p)=sin(0.03*pi*p)+cos(0.97*pi*p)');

Output:
Unit step signal Sinosoidal Signal
1 2

0.5 1

x1(n)
Y

0 0
0 10 20 30 0 10 20 30
n n
Exponential signal for a<1 Exponential signal for a>1
1 50

0.5
x2

0 0
0 10 20 30 0 10 20 30
n n
Ramp Signal x5(p)=sin(0.03*pi*p)+cos(0.97*pi*p)
40 2

20 0
x5(n)
x4

0 -2
0 10 20 30 0 10 20 30
n n

%Program for Difference Equation


%Taking the value of order
order=input('Please input the order of the equation');

for n=1:1:order
a(n)= input('Enter the value of co-efficient a(n)');
end

numinput=input('Please input the number of x(n) values provided:');

for n=1:1:numinput
b(n)=input('Enter the values of co-efficient b(n)');
end

for n=1:1:numinput
x(n+order)=input('Enter the values of input function x(n):');
end

for n=1:1:order
y(n)=input('Enter the values of output function y(n):');
end

for n=1:1:numinput
y(n+order)= 0

for k=1:1:order
y(n+order)=(y(n+order))- (a(k)*y(n+order-k));
end

for k=1:1:numinput
if(n+order-k>0)
y(n+order)=(y(n+order))+ (b(k)*x(n+order+1-k));
end
end
end

%Displaying the result

disp('x(n)');
disp(x);
disp('y(n)');
disp(y);

Output :

Please input the order of the equation5


Enter the value of co-efficient a(n)1
Enter the value of co-efficient a(n)2
Enter the value of co-efficient a(n)1
Enter the value of co-efficient a(n)3
Enter the value of co-efficient a(n)5
Please input the number of x(n) values provided:2
Enter the values of co-efficient b(n)3
Enter the values of co-efficient b(n)2
Enter the values of input function x(n):5
Enter the values of input function x(n):2
Enter the values of output function y(n):2
Enter the values of output function y(n):2
Enter the values of output function y(n):3
Enter the values of output function y(n):3
Enter the values of output function y(n):3

y =

2 2 3 3 3 0

y =

2 2 3 3 3 -13 0

x(n)
0 0 0 0 0 5 2

y(n)
2 2 3 3 3 -13 1

%Program for Normalized correlation

% Taking the left and Right limit values of x(n) and y(n)

xmin = input('Enter value of minimum index of x(n):');


xmax = input('Enter value of minimum index of x(n):');
ymin = input('Enter value of minimum index of y(n):');
ymax = input('Enter value of minimum index of y(n):');

% Taking the Left and Right limit values for various co-relation
functions

rxymin=xmin-ymax;
rxymax=xmax-ymin;

rxxmin=xmin-xmax;
rxxmax=xmax-xmin;

ryymin=ymin-ymax;
ryymax=ymax-ymin;

ryxmin=ymin-xmax;
ryxmax=ymax-xmin;

%calculate a shifting factor to shift y axis to the left to make sure


all
%left limits are positive.

sf=abs(min(min(rxxmin,ryymin),min(ryxmin,rxymin)))+1;

%Shifting y axis to the left by shifting factor.

xmin=xmin+sf;
ymin=ymin+sf;
xmax=xmax+sf;
ymax=ymax+sf;

rxymin=rxymin+sf;
rxymax=rxymax+sf;
rxxmin=rxxmin+sf;
rxxmax=rxxmax+sf;
ryymin=ryymin+sf;
ryymax=ryymax+sf;
ryxmin=ryxmin+sf;
ryxmax=ryxmax+sf;

pxymin=rxymin;
pxymax=rxymax;

%Enter the values for x(n) and y(n)

for n=xmin:1:xmax

x(n)= input('Enter the values for x(n)');


end

for n=ymin:1:ymax
y(n)= input('Enter the values for y(n)');
end
%Calculation various co-relation functions

for l=rxymin:1:rxymax
rxy(1)=0;

for n=xmin:1:xmax
h=n-1+sf;
if(n>=xmin && n<=xmax && h>=ymin && h<=ymax)
rxy(1)=rxy(1)+(x(n)*y(h));
end
end
end

for l=ryxmin:1:ryxmax
ryx(1)=0;

for n=ymin:1:ymax
h=n-1+sf;
if(n>=ymin && n<=ymax && h>=xmin && h<=xmax)
ryx(1)=ryx(1)+(y(n)*x(h));
end
end
end

for l=rxymin:1:rxymax
ryx2(1)=0;
for n=xmin:1:xmax
h=n+1-sf;
if(n>=ymin && n<=ymax && h>=xmin && h<=xmax)
ryx2(1)=ryx2(l)+(y(n)*x(h));
end
end
end

disp(ryx2);

for l=rxxmin:1:rxxmax
rxx(1)=0;
for n=xmin:1:xmax
h=n-1+sf;
if(n>=xmin && n<=xmax && h>=xmin && h<=xmax)
rxx(1)=rxx(1)+(x(n)*x(h));
end
end
end

for l=ryymin:1:ryymax
ryy(1)=0;
for n=ymin:1:ymax
h=n-1+sf;
if(n>=ymin && n<=ymax && h>=ymin && h<=ymax)
ryy(1)=ryy(1)+(y(n)*y(h));
end
end
end

% Calculatin of normalised co-relation function

for l=pxymin:1:pxymax
pxy(1)=(rxy(1))/(sqrt(rxx(sf)*ryy(sf)));
end

% Displaying various outputs

disp('x(n)');
disp(x);
disp('y(n)');
disp(y);
disp('rxx(1)');
disp(rxx);
disp('ryy(1)');
disp(ryy);
disp('ryx(1)');
disp(ryx);
disp('rxy(1)');
disp(rxy);
disp('ryx2(1)=ryx(-1)=rxy(1)');
disp(ryx2);
disp('Normalized co-relation Pxy(1)=');
disp(pxy);

Output:

Das könnte Ihnen auch gefallen