Problem 1: Use MATLAB, Plot The Following Function Defined by
Problem 1: Use MATLAB, Plot The Following Function Defined by
0.5G(3t)
close all;clear all;clc;
t=-2;
t1=-2:0.1:0;
t2=0:0.1:4;
t3=4:0.1:8;
t4=8;
g=0;
g1=-4-2*t1;
g1=0.5*g1.*(3*t1);
g2=-4+3*t2;
g2=0.5*g2.*(3*t2);
g3=16-2*t3;
g3=0.5*g3.*(3*t3);
g4=0;
g4=0.5*g4.*(3*t4);
plot(t,g,t1,g1,t2,g2,t3,g3,t4,g4)
xlabel('time fuction')
ylabel('G(t)')
EE-133
EE-133
-2G((t-1)/2)
close all;clear all;clc;
t=-2;
t1=-2:0.1:0;
t2=0:0.1:4;
t3=4:0.1:8;
t4=8;
g=0;
g1=-4-2*t1;
g1=-2*g1.*((t1-1)/2);
g2=-4+3*t2;
g2=-2*g2.*((t2-1)/2);
g3=16-2*t3;
g3=-2*g3.*((t3-1)/2);
g4=0;
g4=-2*g4.*((t4-1)/2);
plot(t,g,t1,g1,t2,g2,t3,g3,t4,g4)
xlabel('time fuction')
ylabel('G(t)')
b. square
close all;clear all;clc;
x=1:1:50;
y=square(x);
plot(x,y)
xlabel('time function')
ylabel('square')
c. sinc
close all;clear all;clc;
x=1:1:150;
y=sinc(x);
plot(x,y)
xlabel('time function')
ylabel('sinc')
ee-133
d. sawtooth
close all;clear all;clc;
x=1:1:100;
y=sawtooth(x);
plot(x,y)
xlabel('time function')
ylabel('sawtooth')
e. tripuls
close all;clear all;clc;
x=1:1:100;
y=tripuls((x-5),7);
plot(x,y)
xlabel('time function')
ylabel('tripuls')
Exercise:
1. Generate a code which uses input to shift unit-sample right or left using function.
clear all;close all;clc;
n=[-30:0.1:30];
n0=input('enter delay=');
x=[(n-n0)>=0];
plot(n,x);
xlabel('n');
ylabel('u(n)');
grid on;
EE-133
4. find and sketch the even and odd parts of these signals:
g[n]= u[n]- u[n-4]
g[n]= cos (2n/4)
g[n]= sin(2n/4)
g[n]= e-(n/4)u[n]
clear all;close all;clc;
n=[-10:0.01:10];
%g=(n>=0)-((n-4)>=0);
%g=cos(2*pi*n/4);
%g=sin(2*pi*n/4);
g=(n>=0).*exp(-n/4);
subplot(3,1,1);
plot(n,g);
title('given function')
xlabel('n');
ylabel('g(n)');
grid on;
n_inv=[10:-0.01-10];
%g_inv=(n_inv>0)-((n_inv-4)>0);
%g_inv=cos(2*pi*n_inv/4);
%g_inv=sin(2*pi*n_inv/4);
g_inv=(n_inv>0).*exp(-n_inv/4);
subplot(3,1,2);
even=(g+g_inv)/2;
plot(n,even);
title('even function')
xlabel('n');
ylabel('even part');
subplot(3,1,3);
odd=(g-g_inv)/2;
plot(n,odd);
title('odd part of function');
xlabel('n');
ylabel('odd part');
grid on;