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

204_lab

The document outlines a series of MATLAB exercises for a Signals and Systems laboratory course, focusing on discrete and continuous time signals, convolutions, and energy calculations. It includes preparation tasks for evaluating convolutions, generating various signals, and comparing results with hand calculations. Additionally, it emphasizes the use of MATLAB functions to analyze and visualize signals, as well as the importance of understanding energy and power in both discrete and continuous time contexts.

Uploaded by

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

204_lab

The document outlines a series of MATLAB exercises for a Signals and Systems laboratory course, focusing on discrete and continuous time signals, convolutions, and energy calculations. It includes preparation tasks for evaluating convolutions, generating various signals, and comparing results with hand calculations. Additionally, it emphasizes the use of MATLAB functions to analyze and visualize signals, as well as the importance of understanding energy and power in both discrete and continuous time contexts.

Uploaded by

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

EE 204 218 Signals and Systems Laboratory 7 %part a) %part b)

n=-10:1:10; n=-10:1:10;
subplot(3,1,1) subplot (3,1,1)
stem(stepDT(n)) stem(((1/2).^n).*stepDT(n-2))
subplot (3,1,2) subplot (3,1,2)
I. PREPARATION stem(stepDT(n-3)) stem(stepDT(n))
subplot(3,1,3) subplot (3,1,3)
1) Evaluate the following convolutions both in discrete y1=conv(stepDT(n), stepDT(n-3)) y2=conv(((1/2).^n).*stepDT (n-2), stepDT (n))
time and continuous time. stem(y1, 'g') stem(y2, 'm')
%part c) %part d)
n=-10:1:10; t=-10:1:10;
a) yln] = un)*un -3] subplot (3,1,1) subplot(3,1,1)
b) yln] = ()"un 2] *un] stem((-1).^n) plot(u(t)-u(t-2))
c) yln] = (1)" *2"u-n+ 2] subplot(3,1,2)
stem ( (2.^n).* (stepDT (-1* n+2) ))
subplot(3,1,2)
plot(u(t))
d) yt) = (u(t) - u(t -2)) * u(t) subplot (3,1,3) subplot (3,1,3)
e) y(t) = (eu(t) +(e-u(t) y3=conv((-1).^n, (2.^n).* (stepDT(-1*n+2))) y4=conv(u(t)-u(t-2),u(t))
stem(y3, 'm') plot (y4, 'c')
2) Find the convolution of the signals x(t) and %part e)
y(t) by hand. t=-10:1:10;
subplot(3,1,1)
plot(exp(-1*t).*u(t))
xít) y(U) subplot(3,1,2)
plot(exp(-3*t).*u(t))
subplot(3,1,3)
y5=conv(exp(-1*t).*u(t), exp (-3*t).*u(t))
plot (y5, 'y')

II. EXPERIMENTAL WORK

1) Write matlab programs that find the result of the


convolutions in preparations 1 and 2. Compare them
with your hand results.
Note: Use the matlab command conv to evaluate
the convolution of two signals.

Prepared by Orhan Gazi who is with Electronics and Communica


tion Engincering Department, Cankaya University, Ankara, Turkiye (e-mail:
[email protected]).
EE 204 Signals and Systems Laboratory 5
1. PREPARATION
in step 3
1) A triangle function can be generated using the ramp xt_sq=xt."2;
functions. Try the following matlab code and see how a Ex=trapz(t,xt sq):
triangle is generated using discrete time ramp functions. disp(" Energy the signal is: '):
Use rampDT function from Lab5. disp(Ex):

function y=tri(n)
II. EXPERIMENTAL WORK
y=rampDT(n+10)-2*rampDT(n)+rampDT(a-10):
1) Generate the following signals using matlab.
2) A periodic signal is obtained by shifting a a) r(t) =e- (u(t) u(t - 4))
non-periodic signal to the left and write by multiples of b) zin] = e-"(un]- un 4)
a period and summing the shifted replicas. A periodic c) Using signals in (a) and (b) generate periodic signals.
triangle function is generated as follows. Try it and d) Find the energy of the signals in parts (a) and (b).
understand how it is written.
2) Using matlab find the energy of the following
n=-150: 150: signals.
N=25; %Period of the signal a)r(n] = cos()(u[n]-ufn -6)
periodicTriangle=zeros(1,length(n): bjzla) = ua]
for k=-5:5
periodicTriangle-periodicTriangle+tri(n-k*N):
end
3) Using matlab find the power of the following
signals
figure; a)r[n = uln]
stem(n,periodicTriangle): b)r(n] = (-1)"
c)rn] =e-jn/2
3) Modify 1 and 2 for continuous time triangle
signal. 4) Sketch the following signal.
4) Write a matlab function that generates a rectangle a)gln) =| (" | utn]
b) Sketch the even and odd part of the signal in part a.
signal around origin, use unit step functions (both in
continuous time and discrete time). 5) Sketch the magnitude and phase of the following
signal
5) Using the rectangle function in 3, write a matlab a) r(k] = sinc(k/2)e-i(2rk/4)
code that generates period rectangle signals. Decide the b) Find its energy using matlab.
all the parameters yourself (i.e., time length, rectangle
length, period).
6) How do you find the energy of a continuous
and discrete time signal. Review the concepts.

7) Using matlab help utility learn the usage of


the following matlab function "rapz".
8) Look at the following matlab code and understand
how the energy of a continuous time signal is found
using integration.
t-7:0.1:13;
xt=tri((t-3)/10):% tri(t) is the your C.T. triangle function
Prepared by Orhan Gazi who is with Electronics and Communica
tion Engineering Department, Cankaya University, Ankara, Turkiye (e-mail:
[email protected]).
1

EE 204 Signals and Systems Laboratory 6


I. PREPARATION gtSq=g.*gt:
1) A discrete time signal x[n] is defined as below Ex=trapz(t.gtSq):
Px=Ex/(max(t)-min():; % 10-(-10)=20 is the length of
r[n]=eln/10 sinTn the time interval over which integration is taken
4 disp([("The energy of signal is: 'num2str(Ex)|]):
Inspect the following matlab code which computes the disp(["The power of the signal is: '.num2str(Px)]):
energy and power of the signal.
4) Now generate a periodic CT signal using x(t)
n=-100: 100: in part 3. Determine the period value T by yourself.
rn = erp-abs(n/10)). * sin(2 * pi * n/4): Compute the power and energy of the periodic signal.
stem(n,rn):
TnSq = n. *rn; 5) Determine the periods of the following signals
Er = sum(znSq): by hand computation.
disp(['Energy of the signal is :",num2str(Er)]): a) (t) = 10cos(100mt)
Pa = Er/length (n); b) y(t) = 40cos(60 t) + 20sin(40zt)
disp([' Powerof the signal is: '.num2str(Pa)]):
II. EXPERIMENTAL WORK
Play with the n range and see the energy and 1) Draw the signals in part 5, then do the followings
power values. For a aperiodic signal energy value is a
constant. In addition, power equals 0 as n range goes a) Compute the Energy and power of the signals
to infinity. in one period.
2) Now generate a periodic signal using the above b) Sum the signals in preparation 5a, 5b. Plot it.
x[n]. Lets say that the period equals N. Modify the Can you determine the periodicity using graph. If yes,
above matlab code into a matlab function. Using the determine the period. Compute energy and power of
matlab function generate a periodic signal with period the summed signal. Compare the values with that of
N. Compute the energy of the periodic signal. Compute the ones in Experimental work la.
the power of the periodic signal.
2) Sketch the following DT functions and compute their
Note: Compute the energy of the periodic signal Energy and power. Using the sketch first determine
in one period and divide this value to the period to find whether that are periodic or not. Then compute energy
the power of the periodic signal. As you will notice and power.
the power of a periodic signal is not zero. However
the power of that aperiodic signal equals zero in our a) gln] = 2(0.9)" sin(2z )
example.
b) g[n] = cos(un + 1] cos()ufn)
3) A continuous time signal x(t) is defined as
below: %question1 ) gln] = 3nt2n
%function a
function y=a(t)
z(t) =5e-l|/2cos(2nt) y=10*cos(100*pi*t);
%function b
function y=b(t)
y=40*cos(60*pi*t) + 20*sin
(40*pi*t);
t = -0.1:0.0001:0.1;
figure
Inspect the following matlab code that computes plot(t, a(t)); % Plot the signal
the energy and power of the signal. a
figure
plot(t, b(t)); % Plot the signal
b
t=-10:0.01:10; Ta=0.02;
gt-S*exp(-abs(U2).*cos(2*pi*t);: t = -Ta/2:0.0001:Ta/2;
energya = trapz(t, a(t).^2)
plot(t.gt): powera = energya /Ta
disp(['Energy of the a signal is: ', num2str(energya)])
disp(['Power of the a signal is: ', num2str(powera)])
Prepared by Orhan Gazi who is with Electronics and Communica
tion Engineering Department, Cankaya University, Ankara, Turkiye (e-mail: Tb=0.1;
t = -Tb/2:0.0001:Tb/2;
o.gazi@ ari.cankaya.edu.tr). energyb = trapz(t, b(t).^2)
powerb = energyb /Tb
disp(['Energy of the a signal is: ', num2str(energyb)])
disp(['Power of the a signal is: ', num2str(powerb)])
EE 204 Signals and Systems Laboratory 34
1. PREPARATION II. EXPERIMENT

A. Please study the followings, l) Draw the following discrete time signals using
matlab
a) sl[n] = 6n -3)
Unit Step:
function y= u() b) sl[n] = 62n -2)+Q2n -6]+ 8(2rn 1o] +s[n - 8]
y= ( 0): ) s3|n] = un +2] u<n -5|
d) s4[n] = u[n +2]+ s<n - 5)
Kamp: e) s5|n] = ön - 3]n²+ u<n -4]
function r = ramp(t)
r=t. (t > 0): ) stial = rln] - 2r(n -2] +r(n - 4]
Aiso draw these continuous time signals using Matiab. f) aT[n] = r[n +2) 2r[n - 2) + r[n -6
Impulse:
function y = imp(t) n=-10:0.01:10; ARRSNRe IiewserRHAASusing Matab
y= (t == 0): a) s()=u-2) +S(-5)
subplot(7,1,1)
Rectangle: stem(n,impDT(n-3),'g') b) $;(t) = u(t +l)+ 8)-u(t-3) +r(t-6)
functiony= red(t) subplot(7,1,2)
y= u(t +0.5) u(t-0.5): stem(n,impDT((2*n)-2)+impDT((2*n)-6)+impDT((2*n)-10)
+impDT(n-8),'y') c) sj()=u)+u((-1)- 38(1 -5)+u((-8)- 3u(t-10)
subplot(7,1,3)
Dscrele megek stem(n,stepDT(n+2)-stepDT(n-5),'m')
d) s(t)=rt)-3r- 4)-S(-6)+ u(t-8)
subplot(7,1,4)
stem(n,stepDT(n+2)+impDT(n-5),'r')
subplot(7,1,5)
&S=od(rounda) -=n): stem(n,(impDT(n-3).*(n.^2))+stepDT(n-4),'c') e) ss()= 2u(t +2) +u) +58(1-3)-S(-5)r
subplot(7,1,6)
stem(n,rampDT(n)-(2*rampDT(n-2))+rampDT(n-4),'r')
eod subplot(7,1,7)
cnd stem(n,rampDT(n+2)-(2*rampDT(n-2))+rampDT(n-6),'m') 3) Draw the following signals in Matlab:
x() =eut)-ruy?
Discrete tinse impube:
functiany= impDTIn)
*z[n]= cos(n )u(n n
odpand(a) -= n:
i-tsempty(s) function y=pieceu(t,epsilon)
y(s)=NaN;
for i=1:length(t)
4) Consider the following piecewise function:
t< -e
if t(i)<=(-1*epsilon) -E<t<e
y(i)=0;
elseif (-1*epsilon)<=t(i) && t(i)<=epsilon t>e
y(i)=(1/(2*epsilon))*t(i);
F=enas(inn - elseif epsilon<=t(i)
y(a 0) = n(0 O; y(i)=1; Show that when e goes to zero, this function converges
da)-=n): else to the unit step function.
y(i)=0;
vsshNaN: end
5) Draw the following signal in Matlab step by step:
end
f=r(-t) r(-t-2) 2u(-t
5-
- 2) + 6(t)
% Define the time range
B. Please do the followings, 6) Consider the following signal: % Define the signals
% Plot each signal
separately
% Add all the signals
I) Draw the following signals by hand. together
a) sl(t) u(t- 1) % Plot the combined signal
b) s2(0) = u(2t + 4)
c) s3(t) = u(3t + 1) + u(t- 1) + u(t -3) + 3u(t-5)
d) s4(t) = r(t + 1)
e) a5(t) = r(t + 1)- 2r(t) + r(t - 1)
) s6(0) = r(t- 1)- 2r(t -4)
g) s7(0) = 6(21 - 1) +6(34 2) +6(4t +3) +6(22-4) Draw this signal in Matlab step by step.
h) s8(t) = u(t - 2) +&(t - 1) +u(t+ 4)
i) s9(0)= u(t+ 1 - 2)
7) Draw the following piecewise function:
2) Draw the following discrete time signals by sin(t) ts-10
for i=1:length(t)
hand f= 8(¢) - 10 <ts 10
a) sl(n] = 6n - 2 if t(i)<=(-10)
y(i)=sin(t(i));
u(t) t 10
b) sl[n] = Q|n 2] + 8|2r 6]+ Q[n -2] +6|n - 2] elseif (-10)<=t(i) && t(i)<=10
y(i)=imp(t(i));
c) s3|n]= un -2] - u<n -5| elseif 10<=t(i)
d) s4[n] = uln - 2] + Q[n - 5] y(i)=u(t(i));
e) s5[n] = ô<n 2)n²+ uln - 2] +1 else
y(i)=0;
) s6ln] =r[n]-2r[n -2 + r[n -4] end

end
EE 204 Signals and Systems Laboratory 10
EXPERMENTAL WORK
Questionl

1|

-N -N+1 1 figure(1) N
N=2;
n=-1000:1000;
Fourier transform of xn] is: xn=(n>=-N) .* (n<=N) ;
w=-20*pi:pi/100:20*pi;
xw=zeros (1,length(w)) ;
o]= xn]ejan for i=1:length(w)
xw(i)=sum(xn.*exp(-j*w(i).*n)) ;
end
n=-0
subplot(4,1,1)

Compute o] for different values of N: stem (w, abs (xw))


title('N=2, Magnitude of the function')
subplot(4,1,2)
a) N=2 stem(w,angle(xw))
title('N=2, Phase of the function')
b) N=20 subplot(4,1,3)
stem(w,xw)
c) N=50 title('N=2, Fourier Transform of the original function')
d) N=5 subplot(4,1,4)
stem(n,xn)
title('N=2, Original function')

Plot the magnitude and the phase for different N values.


% Part (a)
figure(1)
Question2 t=-10*pi:pi/100:10*pi;
w=-50:0.01:50;
xt=cos(2*t);
a) x(t)= cos(2 ) xw=zeros(1,length(w)) ;
for i=1:length(w)
xw(i)=trapz(t,xt.*exp(-j*w(i)*t));
end
Fourier transform of x(t) is: subplot (3,1,1)
plot (w,xw)
title( 'Fourier Transform of cos (2t)')
subplot (3,1,2)
plot (w, abs(xw))
x(o) = (x()e-i d title ('Magnitude of the Fourier Transform of cos (2t)')
subplot (3,1,3)
plot(w,angle(xw))
title ('Phase of the Fourier Transform of cos (2t)')

Compute x(o) by writing aMatlab program, plot the magnitude and the phase of x(o).
b) Repeat part a) for x(1) = sin(2r)
imp=@(t)(t==0) subplot(4,1,1)
w=-10*pi:pi/100:10*pi; plot(w,fw)
t=-50:0.01:50; title('Fourier Transform of f
Question3 ft=imp(t-1);
(t)')
subplot(4,1,2)
fw=zeros(1,length(w)); plot(w,gw)
title('Fourier Transform of g
f(t)=imp(t-1) and g(t)-imp(t-2) for i=1:length(w)
fw(i)=trapz(t,ft.*exp(-j*w(i)*t));
(t)')
subplot(4,1,3)
end plot(w,hw)
title('Fourier Transform of h
a) What are the fourier transform of f(t) and g(t) gt=imp(t-2);
gw=zeros(1,length(w));
(t)')
subplot(4,1,4)
plot(w,sqrt(2*pi).*fw.*gw)
for i=1:length(w) title('Fourier Transform of
b)lf h(t) =f(0*g(t), then what is the Fourier Transform of h(t)? gw(i)=trapz(t,gt.*exp(-j*w(i)*t));
end
sqrt(2*pi).*f(w).*g(w)')

ht=imp(t-3);
c)ls the rule h(w)=sqrt(2pi).f(w).g(w)satisfied ? hw=zeros(1,length(w));

for i=1:length(w)
hw(i)=trapz(t,ht.*exp(-j*w(i)*t));
end

You might also like