Sei sulla pagina 1di 21

SIGNAL ANALYSIS AND

PROCESSING
LAB TASK 2
SAI SRINIDHI K
18BSW0007

Challenges faced: finding the syntax foe plotting discrete signal


with different amplitudes
MATLAB CODE:
clc
clear all
n=-3:3;
x1=[-3,-1,3,2,1,-1,2]
x2=[-5,-2,2,0,-1,2,1]
y1=x1+x2
subplot(2,2,1)
stem(n,y1)
xlabel('time')
ylabel('amplitude')
title('y1(n)')
y2=x1-x2
subplot(2,2,2)
stem(n,y2)
xlabel('time')
ylabel('amplitude')
title('y2(n)')
y3=x1.*x2
subplot(2,2,3)
stem(n,y3)
xlabel('time')
ylabel('amplitude')
title('y3(n)')

OUTPUT GRAPH:
CODE 2:

Challenges faced: finding the limits and multiplying two unit step
functions

clc
clear all
n1=input('lower limit:')
n2=input('upper limit:')
t=n1:n2
u=2-t>=0
x=t>=0
unit=u.*x
plot(t,unit)
ylim([-3 3])
xlabel('time')
ylabel('amplitude')
title('x[n]=u(2-t)*u(t)')

input: n1=-3 n2=3


OUTPUT GRAPH:

Challenges faced: finding the syntax for plotting scale on y axis


CODE :
clc
clear all
n1=input('lower limit:')
n2=input('upper limit:')
t=n1:0.01:n2
u=exp(-2.*t)
x=t>=0
unit=u.*x
plot(t,unit)
ylim([-5 5])
xlabel('time')
ylabel('amplitude')
title('x2(t)=exp(-2*t)*u(t)')

input: n1=-3,n2=3
OUTPUT GRAPH:
Challenges faced: finding the syntax and multiplying the two signals
MATLAB CODE:
clc
clear all
n1=input('lower limit:')
n2=input('upper limit:')
t=n1:0.01:n2
u=exp(-2.*(t+1))
x=t+1>=0
unit=u.*x
plot(t,unit)
xlabel('time')
ylabel('amplitude')
title('x2(t)=exp(-2*t+1)*u(t+1)')

input: n1=-3,n2=-3
OUTPUT GRAPH:

Challenges faced: finding the syntax for shifting the signal by t units
CODE:
clc
clear all
n1=input('lower limit:')
n2=input('upper limit:')
T=-5:0.01:5
t=input('enter t value')
x1=(T+1)>=0
x2=exp(-2*(T+1))
h=x1.*x2
plot(t-T,h)
xlabel('time')
ylabel('amplitude')
title('h(t-T)')
ylim([-2,2])

input: n1=-4,n2=-4

output graph:
Challenges faced: finding the syntax and giving corresponding limits
CODE:

clc
clear all
n1=input('lower limit:')
n2=input('upper limit:')
T=2
t=n1:0.01:n2
u=t+(T/2)>=0
x=t-(T/2)>=0
unit=(u-x)/T
plot(t,unit)
xlabel('time')
ylabel('amplitude')
title('x4(t)=u(t+T/2)-U(t-T/2)/T')

input: n1=-4,n2=4

OUTPUT GRAPH:
Challenges faces: giving the limits and multiplying it by t times
CODE:
clc
clear all
n1=input('lower limit:')
n2=input('upper limit:')
t=n1:0.01:n2
u=t/2
x=t-2>=0
unit=u.*x
plot(t,unit)
xlabel('time')
ylabel('amplitude')
title('x5(t)=t/2*(u(t-2)')
input: n1=-4,n2=4
OUTPUT GRAPH:

Challenges faced: syntax for finding the signal for n>0 and n<0
CODE:
clc
clear all
x1=input('enter lower limit')
x2=input('enter upper limit')
t=x1:x2
a=input('a=')
n=input('n=')
y=(a.^(n-t)).*(t<=n)
stem(t,y)
xlabel('time')
ylabel('amplitude')
title('h(t-T)')

input: x1=-8,x2=8,a=2,n=2
output graph:
Challenges faced: syntax for finding the modulus of n

CODE
clc
clear all
x1=input('enter lower limit')
x2=input('enter upper limit')
t=x1:x2
a=input('a=')
y=(a.^(abs(t)))/(1-(a.^2))
stem(t,y)
xlabel('time')
ylabel('amplitude')
title('y(n)=a^|n|/(1-a^2)')
ylim([-2,2])

input: x1=-5 x2=5

output graph:
x. Generate any arbitrary signal and plot odd and even part of
the signal.
Challenges faced: finding the syntax for separating the even and
odd parts of a signal
CODE:

clc
clear all
syms t
x1=input('x1= ')
x2=input('x2= ')
t=x1:0.1:x2
y=(sin(t.^3)).^2
Ye=(((sin(t.^3)).^2)+((sin((-t).^3)).^2))/2
Yo=(((sin(t.^3)).^2)-((sin((-t).^3)).^2))/2
subplot(3,1,1)
plot(t,Ye)
ylim([-2,2])
title('Even')
subplot(3,1,2)
plot(t,Yo)
ylim([-2,2])
title('Odd')
subplot(3,1,3);
plot(t,y);
ylim([-2,2])
title('Arbitrary Wave')

input: x1=-2,x2=2
output graph:

Potrebbero piacerti anche