CS MATLAB Assignment
CS MATLAB Assignment
t=[-2:0.01:3];
unitstep = t>=0;
u1=unitstep.*(t+1)
y=exp(-t).*sin(10*pi*t).*u1;
fig1=plot(t,y);
set(fig1,'Linewidth',2);
xlabel('\it t');
ylabel('{\bf y}({\it t})');
title('{\bf y}_{\rm time domain}');
Signal operations
t=[-3:0.002:5];
unitstep = t>=0;
u1=unitstep.*(t)
u2=unitstep.*(t-4)
y=exp(-abs(t)/4).*(u1-u2);
subplot(2,2,1);
fig0=plot(t,y);
grid;
set(fig0,'Linewidth',2);
xlabel('\it t');
ylabel('{\bf y}({\it t})');
title('original signal y(t)');
t1=t/2;
subplot(2,2,2)
fig1=plot(t1,y);
grid;
set(fig1,'Linewidth',2);
xlabel('\it t');
ylabel('{\bf y}({\it t})');
title(' y(2t)');
t2=t-2;
subplot(2,2,3)
fig2=plot(t2,y);
grid;
set(fig2,'Linewidth',2);
xlabel('\it t');
ylabel('{\bf y}({\it t})');
title(' y(t+2)');
t3=(t/2)+2;
subplot(2,2,4)
fig3=plot(-t3,y);
grid;
set(fig3,'Linewidth',2);
xlabel('\it t');
ylabel('{\bf y}({\it t})');
title(' y(2-2t)');
Periodic signals and power
echo off;
clear;
Dt=0.002;
T=6;
M=3;
t=(0:Dt:T-Dt);
unitstep = t>=0;
u1=unitstep.*(t);
u2=unitstep.*(t-4);
y=exp(-abs(t)/2).*sin(2*pi*t).*(u1-u2);
time=[];
y_periodic=[];
for i=-M:M-1
time=[time i*T+t];
y_periodic=[y_periodic y];
end
fy=plot(time,y-periodic);
set(fy,'Linewidth',2);
xlabel('t');
echo on
y_power=sum(y_periodic*y_periodic')*Dt/(max(time)-min(time));
y_energyT=sum(y.*conj(y))*Dt;
Corelation
T=6;
t=(-1:Dt:T);
unitstep = t>=0;
u1=unitstep.*(t);
u2=unitstep.*(t-5);
x=u1-u2;
g1=0.5*(u1-u2);
g2=-(u1-u2)
g3=exp(-t/5).*(u1-u2);
g4=exp(-t).*(u1-u2);
g5=sin(2*pi*t).*(u1-u2);
subplot(2,3,1);
sig1=plot(t,x,'k');
xlabel('t');
ylabel('x(t)');
set(sig1,'Linewidth',2);
grid;
subplot(2,3,2);
sig2=plot(t,g1,'k');
xlabel('t');
ylabel('g1_(t)');
set(sig2,'Linewidth',2);
grid;
subplot(2,3,3);
sig3=plot(t,g2,'k');
xlabel('t');
ylabel('g2_(t)');
set(sig3,'Linewidth',2);
grid;
subplot(2,3,4);
sig4=plot(t,g3,'k');
xlabel('t');
ylabel('g_3(t)');
set(sig4,'Linewidth',2);
grid;
subplot(2,3,5);
sig5=plot(t,g4,'k');
xlabel('t');
ylabel('g_4(t)');
set(sig5,'Linewidth',2);
grid;
subplot(2,3,6);
sig6=plot(t,g5,'k');
xlabel('t');
ylabel('g_4(t)');
set(sig6,'Linewidth',2);
grid;
E0=sum(x.*conj(x))*Dt;
E1=sum(g1.*conj(g1))*Dt;
E2=sum(g2.*conj(g2))*Dt;
E3=sum(g3.*conj(g3))*Dt;
E4=sum(g4.*conj(g4))*Dt;
E5=sum(g5.*conj(g5))*Dt;
C0=sum(x.*conj(x))*Dt/(sqrt(E0*E0))
C1=sum(x.*conj(g1))*Dt/(sqrt(E0*E1))
C2=sum(x.*conj(g2))*Dt/(sqrt(E0*E2))
C3=sum(x.*conj(g3))*Dt/(sqrt(E0*E3))
C4=sum(x.*conj(g4))*Dt/(sqrt(E0*E4))
C5=sum(x.*conj(g5))*Dt/(sqrt(E0*E5))