You are on page 1of 5

IEC LABWORK

Lab 3

SHARUKH V S
2020BCS0185
)Generate the signals using Matlab

t=-3:0.01:3;
y=zeros(1,length(t));

for i=1:length(t)
if t(i)>=-1 && t(i)<=0
y(i)=1+t(i);
elseif t(i)>0 && t(i)<=1
y(i)=1-t(i);
end
end

plot(t,y,'r')

2 Generate the signal using matlab


t=-3:0.5:3;
y=zeros(1,length(t));

for i=1:length(t)
if t(i)<=-2 || t(i)>=2
y(i)=2;
elseif t(i)<0
y(i)=-t(i);
else
y(i)=t(i);
end
end

stem(t,y,'r')
2) Generate the following signal and find the even and odd components using Matlab.
n=-10:10;
y=[0 0 0 0 0 0 0 0 0 2 5 6 5 2 6 5 2 0 0 0 0];
even=zeros(1,length(n));
odd=zeros(1,length(n));

max=length(n)+1;
for i=1:length(n)
even(i)=(y(i)+y(max-i))/2;
odd(i)=(y(i)-y(max-i))/2;
end

subplot(3,1,1)
stem(n,y,'r')
subplot(3,1,2)
stem(n,even,'k')
subplot(3,1,3)
stem(n,odd,'b')

3) Write and execute Matlab program to sketch the continuous time signal (CTS)
x(t)=2e^(-2t) for an interval 0<=t<=2. Sample the continuous signal with time period
T=0.2s and sketch the discrete time signal (DTS).
t=0:0.01:2;
y=zeros(1,length(t));

for i=1:length(t)
y(i)=2*exp(-2*t(i));
end

n=0:0.2:2;
z=zeros(1,length(n));
for i=1:length(n)
z(i)=y(i*20-19);
end

subplot(2,1,1);
plot(t,y,'b')
subplot(2,1,2);
stem(n,z,'m')

4) Write and execute Matlab program to sketch the continuous time signal (CTS)
x(t)=2e^(t^2/2) for an interval -1<=t<=1. Sample the continuous signal with time period
T=0.1s and sketch the discrete time signal (DTS).
t=0:0.01:2;
y=zeros(1,length(t));

for i=1:length(t)
y(i)=2*exp((t(i)^2)/2);
end

n=0:0.1:2;
z=zeros(1,length(n));
for i=1:length(n)
z(i)=y(i*10-9);
end
subplot(2,1,1);
plot(t,y,'b')
subplot(2,1,2);
stem(n,z,'m')

You might also like