Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

1.

Plot the following functions using MATLAB

(a) Delta function: [n].


%% 1 Delta function

n = -5:5;
x = zeros(size(n));
x(n==0) = 1;
stem(n,x);
axis([-5.5 5.5 -0.2 1.2]);
grid on;

title('Delta Function x[n]');


xlabel('n');
ylabel('x[n]');

(b) Unit step: u(t)and u[n].


%% Unit step

t = -5:0.05:5;
y = zeros(size(t));
y(t>=0) = 1;

subplot(121);
plot(t,y);
axis([-5 5 -0.2 1.2]);
grid on;

title('Unit Step u(t)');


xlabel('t');
ylabel('u(t)');

% DT
n = -5:5;
x = ones(size(n));
x(n<0) = 0;

subplot(122);
stem(n,x);
axis([-5.5 5.5 -0.2 1.2]);
grid on;

title('Unit Step u[n]');


xlabel('n');
ylabel('u[n]');
(c) Ramp: r(t)andr[n].
%% Ramp
y = y.*t;

subplot(211);
plot(t,y);
axis([-5 5 -0.2 5.5]);
grid on;

title('Unit Ramp r(t)');


xlabel('t');
ylabel('r(t)');

%DT
x = x.*n;
subplot(212);
stem(n,x);
axis([-5 5 -0.2 5.5]);
grid on;

title('Unit Ramp r[n]');


xlabel('n');
ylabel('r[n]');

(d) Rectangular dened for time period[2, 3].


t = -5:0.05:5;
y = ones(size(t));
y(t<-2 | t>3) = 0;

subplot(211);
plot(t,y);
axis([-5 5 -0.2 1.2]);
grid on;

title('Rectangle Pa(t)');
xlabel('t');
ylabel('Pa(t)');

% DT
n = -5:5;
x = zeros(size(n));
x(n>=-2 & n<=3) = 1;

subplot(212);
stem(n,x);
axis([-5 5 -0.2 1.2]);
grid on;
title('Rectangle Pa[n]');
xlabel('n');
ylabel('Pa[n]');
2. Write a MATLAB program to generate and plot the signals x1(t)=2cos(t 3 ),
x2(t)=3cos(2t 9 ),and x3(t)= x1(t)+ x2(t). Observe the nature of each signal
and identify their fundamental periods.

t=-10:0.1:10;
x1=2*cos(pi*t/3);
x2=3*cos(2*pi*t/9);
x3=x1+x2;

subplot(3,1,1);
plot(t,x1);
axis([-10 10 -5.2 5.2]);

subplot(3,1,2);
plot(t,x2);
axis([-10 10 -5.2 5.2]);

subplot(3,1,3);
plot(t,x3);
axis([-10 10 -5.2 5.2]);

3. Write a MATLAB program to generate and plot the signals x1[n]=5cos(0.5n)and x2[n]=5cos(2 12 n).
Comment on the nature and periodicity of the signals. Identify the fundamental period of the signals, if
exists.
n=-10:1:10;
x1=5*cos(0.5*n);
x2=5*cos(2*pi*n/12);

subplot(2,1,1);
stem(n,x1);
axis([-10 10 -6.2 6.2]);

subplot(2,1,2);
stem(n,x2);
axis([-10 10 -6.2 6.2]);
4. The Continuous Time (CT) exponential signal is given as x(t)= Cet. Consider the case when C and
are both complex, where C is expressed in polar form i.e., (C =|C|ej)and a in rectangular form i.e.,(a = r
+ jo). Then your function x(t), on simplication, becomes x(t)=|C|ert[cos(ot +)+ jsin(ot +)]. Taking
o =0.1and =0; plot the real and imaginary parts signal for different values ofrand comment on the
results for i) r =0(this case is same as 4. (b) for =0), ii) r <0(take r =0.01,0.1), and iii) r >0(take r
=0.01,0.1). What happens when we take = 4 instead.
C = 1.5;
w = 0.1;
theta = 0;
t = -200:0.1:200;
r = 0;
y = C*exp(r*t).*(cos(w*t + theta) +
j*sin(w*t + theta));

subplot(321);
plot(t,real(y));
grid on;

title('r = 0, Real part');


xlabel('t');
ylabel('real(x(t))');
subplot(322);
plot(t,imag(y));
grid on;
title('r = 0, Imaginary part');
xlabel('t');
ylabel('imag(x(t))');
r = -0.01;
y = C*exp(r*t).*(cos(w*t + theta) +
j*sin(w*t + theta));
subplot(323);
plot(t,real(y));
axis([-200 200 -12 12]);
grid on;
title('r < 1, Real part');
xlabel('t');
ylabel('real(x(t))');
subplot(324);
plot(t,imag(y));
axis([-200 200 -12 12]);
grid on;
title('r <1 , Imaginary part');
xlabel('t');
ylabel('imag(x(t))');
r = 0.01;
y = C*exp(r*t).*(cos(w*t + theta) +
j*sin(w*t + theta));
subplot(325);
plot(t,real(y));
axis([-200 200 -12 12]);
grid on;
title('r > 1, Real part');
xlabel('t')
ylabel('real(x(t))');
subplot(326);
plot(t,imag(y));
axis([-200 200 -12 12]);
grid on;
title('r >1 , Imaginary part');
xlabel('t');
ylabel('imag(x(t))');

5. The Discrete Time (DT) exponential function is given as x[n]= Cn.


(a) Plot x[n] for the case when C and are both real numbers. Taking
C =1.5, observe and comment on the results for different cases of :
i) >1=> ( =1.5), ii) =1, iii)0< <1=> ( =0.5), iv)1< <0=> (
=0.5), v) =1, and vi) <1=> ( =1.5).
C = 1;
n = -5:5;
a = 1.5;
y = C*a.^n;
subplot(321);
stem(n,y);
grid on;
title('alpha > 1');
xlabel('n');
ylabel('real(x[n])');
a = 1.0;
y = C*a.^n;
subplot(322);
stem(n,y);;
grid on;
title('alpha = 1');
xlabel('n');
ylabel('imag(x[n])');
a = 0.5;
y = C*a.^n;
subplot(323);
stem(n,y);
grid on;
title('0<alpha<1');
xlabel('n');
ylabel('x[n]');
a = -0.5;
y = C*a.^n;
subplot(324);
stem(n,y);
grid on;
title('-1<alpha<0');
xlabel('n');
ylabel('x[n])');
a = -1;
y = C*a.^n;
subplot(325);
stem(n,y);
grid on;
title('alpha=-1');
xlabel('n');
ylabel('x[n]');
a = -1.5;
y = C*a.^n;
subplot(326);
stem(n,y);
grid on;
title('alpha < -1');
xlabel('n');
ylabel('x[n]');

(b) Consider the case when C and are both complex, where C =|C|
ej and =||ejo. Then x[n]becomes x[n]=|C|||nej(on+).
Taking C =1.5, =0and o = 6 , observe and comment on results
for different cases of : i)||=1 ii)||>1=> (||=1.5) iii)||
<1=> (||=1.5).

C = 1.5;
w = pi/6;
theta = 0;
a = 1;
y = abs(C)*(abs(a).^n).*exp(1j*w*n+theta);

figure(2);

subplot(321);
stem(n,real(y));
grid on;

title('alpha = 0, Real part');


xlabel('n');
ylabel('real(x[n])');

subplot(322);
stem(n,imag(y));
grid on;

title('alpha = 0, Imaginary part');


xlabel('n');
ylabel('imag(x[n])');

a = 1.05;
y = abs(C)*(abs(a).^n).*exp(1j*w*n+theta);

figure(2);
subplot(323);
stem(n,real(y));

grid on;

title('|alpha| > 1, Real part');


xlabel('n');
ylabel('real(x[n])');

subplot(324);
stem(n,imag(y));
grid on;

title('|alpha| > 1, Imaginary part');


xlabel('n');
ylabel('imag(x[n])');

a = 0.95;
y =
abs(C)*(abs(a).^n).*exp(1j*w*n+theta);

figure(2);

subplot(325);
stem(n,real(y));
grid on;

title('|alpha| < 1, Real part');


xlabel('n');
ylabel('real(x[n])');

subplot(326);
stem(n,imag(y));
grid on;

title('|alpha| < 1 , Imaginary part');


xlabel('n');
ylabel('imag(x[n])');

You might also like