204_lab
204_lab
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')
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.
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 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