0% found this document useful (0 votes)
53 views6 pages

Problem 1: Use MATLAB, Plot The Following Function Defined by

The document contains MATLAB code to plot various functions and their transformations. It first defines a piecewise function G(t) and plots it. It then plots the transformed functions 3G(t+1), 0.5G(3t), and -2G((t-1)/2). The document also plots various built-in MATLAB functions like diric, square, sinc, and sawtooth. Finally, it contains MATLAB code for exercises involving shifting unit samples, plotting discrete-time functions and their transformations, calculating signal energy/power, and finding the even and odd parts of signals.
Copyright
© Attribution Non-Commercial (BY-NC)
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)
53 views6 pages

Problem 1: Use MATLAB, Plot The Following Function Defined by

The document contains MATLAB code to plot various functions and their transformations. It first defines a piecewise function G(t) and plots it. It then plots the transformed functions 3G(t+1), 0.5G(3t), and -2G((t-1)/2). The document also plots various built-in MATLAB functions like diric, square, sinc, and sawtooth. Finally, it contains MATLAB code for exercises involving shifting unit samples, plotting discrete-time functions and their transformations, calculating signal energy/power, and finding the even and odd parts of signals.
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 6

CS LAB II

Problem 1: Use MATLAB, plot the following function defined by


G(t)= 0 t<-2
-4-2t -2<t<0
-4+3t 0<t<4
16-2t 4<t<8
0 t>8
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;
g2=-4+3*t2;
g3=16-2*t3;
g4=0;
plot(t,g,t1,g1,t2,g2,t3,g3,t4,g
4)
xlabel('time fuction')
ylabel('G(t)')

Then plot the transformed functions:


3G(t+1)
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=3*g1.*(t1+1);
g2=-4+3*t2;
g2=3*g2.*(t2+1);
g3=16-2*t3;
g3=3*g3.*(t3+1);
g4=0;
g4=3*g4.*(t4+1);
plot(t,g,t1,g1,t2,g2,t3,g3,t4,g4)
xlabel('time fuction')
ylabel('G(t)')

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

Problem 2: Draw the following built-in funtions:


a. Diric
close all;clear all;clc;
x=1:0.1:10;
y=diric(x,3)
plot(x,y)
xlabel('time function')
ylabel('diric')

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;

2. Using MATLAB, graph the following discrete-time function:


g[n]= 10 e-/4 sin(3n/16) u[n] then graph the following functions:
a. g[2n] b.g[n/3]
clear all;close all;clc;
n=[-40:0.1:40];
n=n;
n0=0;
u=[(n-n0)>=0];
g=10*exp(-pi/4)*(sin(3*pi*n/16).*u);
plot(n,g);
xlabel('time');
ylabel('given function');

clear all;close all;clc;


n=[-40:0.1:40];
n=2*n;
n0=0;
u=[(n-n0)>=0];
g=10*exp(-pi/4)*(sin(3*pi*n/16).*u);
plot(n,g);
xlabel('time');
ylabel('given function');

clear all;close all;clc;


n=[-40:0.1:40];
n=n/3;
n0=0;
u=[(n-n0)>=0];
g=10*exp(-pi/4)*(sin(3*pi*n/16).*u);
plot(n,g);
xlabel('time');
ylabel('given function');

EE-133

Using MATLAB, find the energy or power of the following signals:


a. x(t) = tri ((t-3)/10)
b. X[n] = e-[n/10] sin (2n/4)
(a)clear all;close all;clc;
t=[-20:0.005:20];
xt=tripuls((t-3),10);
plot(t,xt);
grid on;
xlabel('time');
ylabel('x(t)');
abs_xt_2=abs(xt.^2);
delta_t=0.005;
normalized_power=sum(abs_xt_2)*delta_t

(b) clear all;close all;clc;


t=[-20:0.005:20];
n=0:0.005:20;
xn=exp(-n/10).*sin(2*pi*n/4);
plot(n,xn);
grid on;
xlabel('n');
ylabel('x(n)');
abs_xn_2=abs(xn.^2);
delta_n=0.005;
normalized_power=sum(abs_xn_2)*delta_n

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;

You might also like