0% found this document useful (0 votes)
39 views

CS MATLAB Assignment

This document contains MATLAB code to generate and analyze signals. It includes code to: 1) Generate a simple plot of a signal y(t) defined as a step function multiplied by an exponential and sine function. 2) Plot an original signal y(t) and transformed versions including y(2t), y(t+2), and y(2-2t). 3) Generate a periodic signal y_periodic and calculate its power and energy over time. 4) Define several signals g1-g5 and original signal x(t) and calculate the correlation between each.

Uploaded by

Fahad Mahmood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

CS MATLAB Assignment

This document contains MATLAB code to generate and analyze signals. It includes code to: 1) Generate a simple plot of a signal y(t) defined as a step function multiplied by an exponential and sine function. 2) Plot an original signal y(t) and transformed versions including y(2t), y(t+2), and y(2-2t). 3) Generate a periodic signal y_periodic and calculate its power and energy over time. 4) Define several signals g1-g5 and original signal x(t) and calculate the correlation between each.

Uploaded by

Fahad Mahmood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

To generate simple plot

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))

You might also like