Wa0000.
Wa0000.
Wa0000.
no:1
Date: 07-03-2024
SOFTWARE USED:
MATLAB-R2023B software is used for implementing signal operations on both
continuous and discrete time signals
COMMAND WINDOW:
SAMPLE OUTPUT:
ii
DISCRETE TIME SIGNAL (ALL SIGNAL OPERATIONS):
SOURCE CODE:
clc clearall
disp("NAME:Krishna Priya R V");
disp("Rollno:22L229");
p=input('enter the lower index of input
signal:'); q=input('enter the upper index of
inputsignal:'); n=p:1:q;
fprintf('enter the values of x[n]');
fori=1:length(n)
x(i)=input(' ');
end
c=input('enter the amplitude factor:');
d=input('enter the advance factor:');
e=input('enter the delayfactor:');
f=input('enterthecompressingfactor');
g=input('enter the expanding factor:');
figure();
subplot(3,1,1);
stem(n,x);
xlabel('n');
ylabel('x[n]');
title('Input
signal');
axis([p-1,q+1,min(x)-1,max(x)+1]);
subplot(3,1,2);
stem(n,x*c);
xlabel('n');
ylabel('x[n]');
title('Amplitude
scaling');
axis([p-1,q+1,-5,(max(x)*c)+1]); subplot(3,1,3);
stem(-n,x);
xlabel('n');
ylabel('x[-
n]');
title('Reversedsignal');
axis([-3,3,-2,max(x)+1]);
figure();
subplot(3,1,1);
stem(n,x);
xlabel('n');
ylabel('x[n]');
title('Input
signal');
axis([p-1,q+1,-2,max(x)+1]);
subplot(3,1,2);
stem(n+e,x);
xlabel('n');
ylabel(['x[n-',num2str(e),']'])
; title('Delayedsignal');
axis([min(n)+e-1,max(n)+e+1,-2,max(x)+1]);
subplot(3,1,3);
stem(n-d,x);
xlabel('n');
ylabel(['x[n+',num2str(d),']'])
; title('Advancedsignal');
axis([min(n)-d-1,max(n)-d+1,-2,max(x)+1]);
figure();
subplot(3,1,1);
stem(n,x);
xlabel('n');
ylabel('y[n]');
title('Input
signal');
axis([p-1,q+1,-2,max(x)+1]);
flag=1;
flag1=1;
r=[];
s=[];
fori=p*(g):q*(g)
ifmod(i,g)==0
c(flag1) =i;
d(flag1) =x(flag);
flag=flag+ 1;
else
c(flag1) =i;
d(flag1) = 0;
end
flag1=flag1+1;
end
subplot(3,1,2);
stem(c,d);
xlabel('n');
ylabel(['x[n/',num2str(g),']']
); title('Expanded signal');
axis([(min(n)*g)-1,(max(n)*g)+1,-2,max(d)+1]);
flag=1;
flag1=1;
k=[];
l=[];
fori=p:q
ifmod(i,f)==0
k(flag) =i/f;
l(flag)
=x(flag1);
flag=flag+ 1;
end
flag1=flag1+1;
end
subplot(3,1,3);
stem(k,l);
xlabel('sample_n');
ylabel(['x[',num2str(f),'n]']);
title('Compressed signal');
axis([min(n)-1,max(n)+1,-2,max(l)+1]);
COMMAND WINDOW:
SAMPLE OUTPUT:
COMBINED OPERATIONS ON CONTINOUS TIME
SIGNALS: SOURCE CODE:
clc clearall
disp("NAME:Krishna Priya");
disp("Rollno:22L229");
x=-2:0.001:3;
fori=1:length(x)
ifx(i)>-2&&x(i)<0 y(i)=x(i)
+2;
elseif x(i)>=0&&x(i)<3
y(i)=2;
else
y(i)=0;
end
end
figure(1);
subplot(2,1,1);
plot(x,y);
axis([-44-24]);
xlabel('t');
ylabel('x(t)');
title('Input
Signal');
a=input("Enterthevalue foramplitude scaling:");
e=input("enter 0 foradvanceor 1fordelay");
t0=input("Enter thevalueforshifting:");
f=input('Enter 0 forcompressionor 1forexpansion');
b=input("Enterthevaluefor scaling:");
c=input("Enter -1 forreversingorenter 1 fornon-reversing");
y=y*a;
ife==0
x=x-t0;
end
ife==1
x=x+t0;
end
x=(c)*x;
if f==0
x=x/b;
end
if f==1
x=x*b;
end
figure(1);
ifb==1&&t0==0&&c==1
subplot(2,1,2);
plot(x,y);
axis([min(x)-1,max(x)+1,min(y)-1,max(y)+1])
xlabel('t');
ylabel('x(t)');
title('output
signal');
end
ifb~=1&&t0~=0&&c==-1
subplot(2,1,2);
plot(x,y);
axis([min(x)-1,max(x)+1,min(y)-1,max(y)+1])
xlabel('t');
if f==0&&e==0
ylabel([num2str(a),'x(-',num2str(b),'t+',num2str(t0),')']
); title('Advanced reversed andcompressed
outputsignal'); end
if f==0&&e==1
ylabel([num2str(a),'x(-
t/',num2str(b),'+',num2str(t0),')']); title('Advanced
reversed and Expanded output signal'); end
if f==1&&e==1
ylabel([num2str(a),'x(-t/',num2str(b),'-',num2str(t0),')']);
title('Delayed reversed and Expanded output signal');
end
if f==1&&e==0
ylabel([num2str(a),'x(-',num2str(b),'t-',num2str(t0),')']);
title('Delayedreversedand Compressed outputsignal');
end
end
ifb==1&&t0~=0&&c==1
subplot(2,1,2);
plot(x,y);
axis([min(x)-1,max(x)+1,min(y)-1,max(y)+1])
xlabel('t');
if e==0
ylabel([num2str(a),'x(t+',num2str(t0),')']);
title('advancedoutputsignal');
else
ylabel([num2str(a),'x(t-',num2str(t0),')']);
title('Delayedoutput signal');
end
end
ifb~=1&&t0==0&&c==1
subplot(2,1,2);
plot(x,y);
axis([min(x)-1,max(x)+1,min(y)-1,max(y)+1])
xlabel('t');
if f==0
ylabel([num2str(a),'x(',num2str(b),'t)']);
title('Compressedoutputsignal');
else
ylabel([num2str(a),'x(t/',num2str(b),')']);
title('Expanded outputsignal');
end
end
ifb~=1&&t0==0&&c==-1
subplot(2,1,2);
plot(x,y);
axis([min(x)-1,max(x)+1,min(y)-1,max(y)+1])
xlabel('t');
if f==0
ylabel([num2str(a),'x(-',num2str(b),'t)']);
title('Reversed and Compressedoutput signal');
else
ylabel([num2str(a),'x(-t/',num2str(b),')']);
title('reversedand Expanded outputsignal');
end
end
ifb==1&&t0==0&&c==-1
subplot(2,1,2);
plot(x,y);
axis([min(x)-1,max(x)+1,min(y)-1,max(y)+1])
xlabel('t');
ylabel([num2str(a),'-x(t)']);
title('reversedoutput signal');
end
ifb~=1&&t0~=0&&c==1
subplot(2,1,2);
plot(x,y);
axis([min(x)-1,max(x)+1,min(y)-1,max(y)+1])
xlabel('t');
if f==0&&e==0
ylabel([num2str(a),'x(',num2str(b),'t+',num2str(t0),')']);
title('Advanced andcompressedoutput signal');
end
if f==0&&e==1
ylabel([num2str(a),'x(t/',num2str(b),'+',num2str(t0),')']);
title('Advanced and Expanded outputsignal');
end
if f==1&&e==1
ylabel([num2str(a),'x(t/',num2str(b),'-',num2str(t0),')']);
title('Delayedand Expandedoutputsignal');
end
if f==1&&e==0
ylabel([num2str(a),'x(',num2str(b),'t-',num2str(t0),')']
); title('Delayed and Compressedoutputsignal');
end
end
COMMAND WINDOW:
COMBINED OPERATIONS ON DISCRETE TIME
SIGNALS: SOURCE CODE:
clcclearall;
disp("NAME:Krishna Priya");
disp("Rollno:22L229"); l
ower=input('enter the lower limit:');
upper=input('enter the upper limit:');
x=lower:1:upper;
fori=1:length(x)
n(i)=input('');
end
subplot(2,1,1);
stem(x,n);
axis([lower-1,upper+1,-2,max(n)+1]);
xlabel('n');
ylabel('x[n]');
title('Discrete signal')
;
disp("givescalingfactorgreaterthan 1 for compressingor less than 1 forexpanding");
alpha=input("enter scalingfactoralpha: ");
disp("give shiftingfactor value in positive for delayor
innegativeforadvance"); t0 =input("enter shiftingfactorn0: ");
rev=input("Enter 1 forreversingorenter 0 fornot reversingthesignal:");
e=input("enter thevalueof amplitudefactor");
reversed= 0;
exp=0;
cmp=0;
shifted = 0;
if t0==0 % without shiftingDT
if alpha<1 %expandedsignal
DT flag=1;
flag1=1;
c=[];
d=[];
fori=lower*(1/alpha):upper*(1/alpha)
ifmod(i,1/alpha)==0
c(flag1) =i;
d(flag1) =n(flag);
flag= flag+ 1;
else
c(flag1) =i;
d(flag1) = 0;
end
flag1=flag1+1;
end
end
if alpha>1%compressedsignal
DT flag=1;
flag1=1;
c=[];
d=[];
fori=lower:upper
if mod(i,alpha)==0
c(flag) =i/alpha;
d(flag) = n(flag1);
flag= flag+ 1;
end
flag1=flag1+1;
end
end
if rev==1 %
reversingDT c=-c;
end
if t0~=0 % withsihfting
DT shifted=1; l
lower=lower+t0;
upper=upper+t0;
if alpha<1% expanded signal
DT flag=1;
flag1=1;
c=[];
d=[];
fori=lower*(1/alpha):upper*(1/alpha)
if mod(i,1/alpha)==0
c(flag1) =i;
d(flag1) =n(flag);
flag= flag+ 1;
else
c(flag1) =i;
d(flag1) = 0;
end
flag1=flag1+1;
end
end
if alpha>1%compressedsignal
DT flag=1;
flag1=1;
c=[];
d=[];
fori=lower:upper
if mod(i,alpha)==0
c(flag) =i/alpha;
d(flag) =n(flag1);
flag=flag+ 1;
end
flag1=flag1+1;
end
end
if rev==1 %
reversingDT c=-c;
end
end
%ploting operated DT
signal subplot(2,1,2);
fori=1:length(d)
f(i)=e*d(i);
end stem(c,f);
xlabel("n");
ylabel([num2str(e),"y([-",num2str(alpha),"n+
(",num2str(t0),")"]); axis([-10,10,-5,max(f)+1]);
if t0==0 % unshifted DTplot
ifalpha==1&& rev==1
s =sprintf("Reversedsignal");
title(s);
end
if alpha==1 && rev==0
s=sprintf("Nooperationis done");
title(s);
end
if alpha~=1 && rev==1
s=sprintf("Thesignalisreversedand");
ifalpha>1
s1=sprintf(" compressed", alpha);
else
s1=sprintf(" expanded", alpha);
end
title(s+s1);
end
ifalpha~=1 && rev==0
if alpha>1
s1 =sprintf("The signaliscompressed", alpha);
else
s1 =sprintf("The signalisexpanded",
alpha); end
title(s1);
end
end
if t0~=0 % shifted DT
plot ifalpha==1&&
rev==1
s=sprintf("Thesignal is Reversed");
if t0>0
s1 =sprintf(" delayed", t0);
else
s1 =sprintf(" advanced", t0);
end
title(s+s1);
end
ifalpha==1 && rev==0
if t0>0
s1 =sprintf("The signalisdelayed", t0);
else
s1 =sprintf(" Thesignalisadvanced", t0);
end
title(s1);
end
if alpha~=1&& rev==1
s=sprintf("Thesignalis Reversed");
if t0>0
s1 =sprintf("delayed", abs(t0));
else
s1 =sprintf("advanced", abs(t0));
end
if alpha>1
s2 =sprintf("compressed", alpha);
else
s2 =sprintf("expanded", alpha);
end
title(s+s1+s2);
end
if alpha~=1 && rev==0
if t0>0
s1 =sprintf("Thesignalis delayed", t0);
else
s1 =sprintf("Thesignalis advanced", t0);
end
ifalpha>1
s2 =sprintf("andcompressed", alpha);
else
s2 =sprintf(" andsignal", alpha);
end
title(s1+s2);
end
end
COMMAND WINDOW:
SAMPLE OUTPUT:
RESULT:
Thus, the signal operations such as folding, shifting and scaling was done on
both continuous and discrete time signals and it was implemented and verified.
.