You are on page 1of 13

EXPERIMENT NO.

2
AIM : Plotting Elementary continuous time signals, Elementary discrete
time signals, Generate rectangular, sinc and triangle function.
APPARATUS/RESOURCE REQUIRED : Matlab Software
THEORY : A continuous -time signal x(t) is a function of an independent
variable t, that is time. A continuous -time signal x(t) is a mathematically
continuous function, and is defined continuously in the time domain.
A discrete-time signal y(n) is a function of an independent variable n, that is an integer. It is
important to note that a discrete-time signal is not defined at instants between two successive
samples. Also it is incorrect to think that y(n) is not defined for non-integer
values of n. y(n) can be obtained from sampling the continuous
signal y(t), then y(n) =y(nT), where T is the sampling period (i.e. the time between successive
samples).

IN LAB EXERCISE:

Basic CT Signals and DT Signals

Q1. Plot the following continuous-time functions over the specified intervals.
Write single
script files for all CT signals with name CTsignals_GroupNo. X.m. Use the plot and
figure command, and be sure to label the time axes.

(a) Unit Impulse function, x1 (t) = δ (t)

CODE:

t=-1:.01:1;
a=0.*(t>0)+0.*(t<0)+1.*(t==0);
plot(t,a);
xlabel('time')

OUTPUT:
1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
time

(b) Unit Step function, x2(t) = u (t) for t = [-2, 2]

CODE:
t=-2:.01:2;
u=(1.*(t>0)+0.*(t<0))
plot(t,u);
xlabel('time(t)')

OUTPUT:

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
time(t)

(c) Unit Ramp function, x3(t) = r (t) for t = [-2, 5]


CODE:
t=-2:.1:5;
a=-t.*(t>0)+0.*(t<0);
plot(t,a);
xlabel('time(t)')

OUTPUT:

-0.5

-1

-1.5

-2

-2.5

-3

-3.5

-4

-4.5

-5
-2 -1 0 1 2 3 4 5
time(t)

(d) sinusoidal function, x4(t) = 3*sin(2*pi*f*t), where f = 200 Hz for t = - 1 to 1 secs

CODE:
t=-1:.01:1;
f=200;
y=3*sin(2*pi*f*t);
plot(t,y);
xlabel('time(t)')

OUTPUT:

(e) Exponential function, x5(t) = e-at for t = [-4, 4] for a= 0.5, 1.5. Comment on the
effect
of time scaling.

CODE:
t=-4:.1:4;
a=0.5;
b=exp(-2(a*t));
subplot(2,1,1)
plot(t,b);
xlabel(‘time(t)’)
a1=1.5;
b1=exp(-2(a*t));
subplot(2,1,2)
plot(t,b1);
xlabel(‘time(t)’)

OUTPUT:

60

40

20

0
-4 -3 -2 -1 0 1 2 3 4
time(t)

60

40

20

0
-4 -3 -2 -1 0 1 2 3 4
time(t)

(f) rect(t) for t = [ -2 , 2]


(g) sinc(t) for t = [-1, 10]
CODE:
t=-1:.01:1;
a=1.*(t>0)+0.*(t<0);
plot(t,a);
xlabel('time(t)')

OUTPUT:
POST LAB EXERCISE:
1.Generate the waveform of following signals:
For CT signals, t = is -10 to 10 sec
Take appropriate value of sampling interval.

a. xa(t) = δ(t + 1)

ans:-
t=-10:1:10;
u=1.*(t==-1)+0.*(t<-1)+0.*(t>-1);
plot(t,u);
xlabel('time(t)')

OUTPUT:

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
time(t)

b. xb(t) = δ(t + 1/2) - δ(t -1/2)

CODE:
t=-10:10;
u=(1.*(t==-0.5)+0.*(t<-0.5)+0.*(t>-0.5))-(1.*(t==0.5)+0.*(t<0.5)+0.*(t>0.5));
plot(t,u);
xlabel('time(t)')

OUTPUT:
1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
-10 -8 -6 -4 -2 0 2 4 6 8 10
time(t)

c. xc(t) = t u(t)

CODE:
t=-10:10;
u=t.*(1.*(t>0)+0.*(t<0));
plot(t,u);
xlabel('time(t)')

OUTPUT:
10

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
time(t)

d. xd(t) = u (t+2) – u(t - 5)

CODE:
t=-10:10;
u=(1.*(t>-2)+0.*(t<-2))-(1.*(t>5)+0.*(t<5));
plot(t,u);
xlabel('time(t)')
OUTPUT:

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
time(t)

e. xe(t) = r (t +1) – r (t) + r (t - 2)

CODE:
t=-10:.01:10;
r=(t.*(t>-1))+(0.*(t<-1))-(t.*(t>0))-(0.*(t<0))+(t.*(t>2))+(0.*(t<2));
plot(t,r);
xlabel('time(t)')

OUTPUT:
10

-2
-10 -8 -6 -4 -2 0 2 4 6 8 10
time(t)

f. xf(t) = exp(-t) sin(2πt) + exp(-t/2) cos(5 πt)


CODE:

t=-10:.01:10;
y=(exp(-t).*sin(2.*pi.*t))+(exp(-t/2).*cos(5.*pi.*t));
plot(t,y);
xlabel('time(t)')
ylabel('y(t)')

OUTPUT:
4
x 10
2

1.5

0.5
y (t)

-0.5

-1

-1.5
-10 -8 -6 -4 -2 0 2 4 6 8 10
time(t)

Q2. For DT signals, n = -5 to 5 samples

a. xa[n] = r[-n]

CODE:
n=-5:1:5;
y=(-n).*(n<0)+0.*(n>0)+(-n).*(n==0);
stem(n,y);
xlabel('time(seconds)');
ylabel('r[-n]');

OUTPUT:
5

4.5

3.5

3
r[ -n ]

2.5

1.5

0.5

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
time(seconds)

b. xb[n] = exp(n-1)

CODE:
n=-5:1:5;
y=exp(n-1);
stem(n,y);
xlabel('time(seconds)')
ylabel('exp(n-1)');

OUTPUT:

60

50

40
exp(n-1)

30

20

10

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
time(seconds)

c. xc[n] = [n - 1] δ[n - 2]
CODE:
n=-5:1:5;
y=(n-1).*((1.*(n==2))+(0.*(n<2))+(0.*(n>2)));
stem(n,y);
xlabel('time(seconds)');
ylabel('[n-1]impulse[n-2]');

OUTPUT:
1

0.9

0.8

0.7
[n -1 ]im p u ls e [n -2]

0.6

0.5

0.4

0.3

0.2

0.1

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
time(seconds)

d. xd[n] = u [n + 1] – 2u[ n] + u [n-1]

CODE:
n=-5:1:5;
y=1.*(n>(-1))+0.*(n<(-1))+1.*(n>1)+0.*(n<1)-2.*1.*(n>0)+0.*(n<0);
stem(n,y);
xlabel('time(seconds)');
ylabel('y(t)');

OUTPUT:
1

0.8

0.6

0.4

0.2
y(t)

-0.2

-0.4

-0.6

-0.8

-1
-5 -4 -3 -2 -1 0 1 2 3 4 5
time(seconds)

e. xe[n] = r [n + 3] – r [n - 3]

CODE:
n=-5:1:5;
y=n.*(n>-3)+n.*(n==-3)+0.*(n<-3)-(n.*(n>3)+n.*(n==3)+0.*(n<3));
stem(n,y);
xlabel('time(seconds)');
ylabel('y(t)');

OUTPUT:

f. x [n] = an cos(2 πn)


CODE:
n=-5:1:5;
a=2;
y=(a.^n).*cos(2.*pi.*n);
stem(n,y);
xlabel('time(seconds)');
ylabel('y(t)');

OUTPUT:
35

30

25

20
y(t)

15

10

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
time(seconds)
LEARNING OUTCOMES:-
a)Stem: stem (n, x (n)); plots the discrete function x(n) vs. n.
Stem: stem (n, Y (n)); plots the data sequence Y as stems the x axis terminated
with circles for the data value. If Y is a matrix then each column is plotted as a
separate series.

b)We learnt how to generate the various signals ex. Ramp,exponential,impulse


etc. and how to plot them using the plot and stem command for continous and
discrete time respectively.

You might also like