0% found this document useful (0 votes)
145 views20 pages

Exp 2

The document provides instructions for students to complete lab exercises involving plotting various continuous-time and discrete-time signals. For the continuous-time signals, students are asked to plot unit impulse, unit step, unit ramp, sinusoidal, and exponential functions. For the discrete-time signals, students are asked to plot the corresponding stem functions. Additionally, students are instructed to generate random Gaussian signals, calculate their averages, and plot the results. Finally, students are given exercises to sketch waveforms for additional time domain signals and derivatives.

Uploaded by

Rohit Jain
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)
145 views20 pages

Exp 2

The document provides instructions for students to complete lab exercises involving plotting various continuous-time and discrete-time signals. For the continuous-time signals, students are asked to plot unit impulse, unit step, unit ramp, sinusoidal, and exponential functions. For the discrete-time signals, students are asked to plot the corresponding stem functions. Additionally, students are instructed to generate random Gaussian signals, calculate their averages, and plot the results. Finally, students are given exercises to sketch waveforms for additional time domain signals and derivatives.

Uploaded by

Rohit Jain
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/ 20

IN LAB EXERCISE

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)
(b) Unit Step function, x2(t) = u (t) for t = [-2, 2]
(c) Unit Ramp function, x3(t) = r (t) for t = [-2, 5]
(d) sinusoidal function, x4(t) = 3*sin(2*pi*f*t), where f = 20 Hz for t = - 1 to 1 secs
(e) Exponential function, x5(t) = e-at for t = [-4, 4] for a= 0.5, 1.5. Comment on the effect
of time scaling.
(f) rect(t) for t = [ -2 , 2]
(g) sinc(t) for t = [-1, 10]
Sol:
a) t=(-100:1:100);
i=1.*(x==0)
plot(x,y)

b) t=-2:0.01:2;
u=1.*(x>=0);
plot(x,u,'cr')

c)
t=-2:0.01:5
r=t.*(t>=0);
plot(t,r,'cg');

d) t=(-1:0.1:1);
s=3*sin(2*pi*200*t);
plot(t,s)

-13

x 10

3
2
1
0
-1
-2
-3
-4
-1

-0.8

e) t=(-4:0.1:4);
c=exp(-0.5.*t);
d=exp(-1.5.*t);
subplot(2,1,1)
plot(t,c)
subplot(2,1,2)
plot(t,d)

-0.6

-0.4

-0.2

0.2

0.4

0.6

0.8

8
6
4
2
0
-4

-3

-2

-1

-3

-2

-1

-0.5

0.5

1.5

500
400
300
200
100
0
-4

f) t=-2:0.01:2;
rec=1.*(t>=-0.5&t<=0.5);
plot(t,rec)
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-2

-1.5

-1

g) t=-1:.1:10;
sinc=sin(pi.*t)/pi.*t;
plot(t,sinc)
3

-1

-2

-3

-4
-2

10

Q2. Also write another .m - script file to stem the corresponding discrete-time function
with name DTsignals_GroupNo. X.m. Use the subplot command to put Q2.a) - c) plots in a
figure 1, Q2.d) - e) plots in a figure 2 and Q2.f) - g) plots in a figure 3. Issue the command
orient (tall) just prior to printing to prevent crowding of the subplots.
a)
t=-10:.1:10;
y=1.*(t==0) ;
subplot(3,1,1);
stem(t,y)
t=-10:2:10;
y=1.*(t==0) + 0;
subplot(3,1,1);
stem(t,y)
t=-2:1:2;
y=1.*(t>=0) + 0.*(t<0);
subplot(3,1,2);
stem(t,y)
t=-2:.5:5;
y=t.*(t>=0) + 0.*(t<0);
y=t.*(t>=0) + 0.*(t<0);
subplot(3,1,3); stem(t,y)

0.5

0
-10

-8

-6

-4

-2

10

0.5

0
-2

-1.5

-1

-0.5

0.5

1.5

6
4
2
0
-2

b)
>> t=-1:0.2:1;
f=200;
y=3*sin(2*pi*f*t);
subplot(2,1,1);
stem(t,y)
t=-4:0.2:4;
a=.5;
y=exp(-a*t);
subplot(2,1,2);
stem(t,y)

-1

-13

x 10

2
0
-2
-4
-1

-0.8

-0.6

-0.4

-0.2

0.2

0.4

0.6

0.8

8
6
4
2
0
-4

-3

-2

-1

d) t=-2:1:2;
y=1.*(t>=-.5 & t<=0.5) + 0;
subplot(2,1,1);
stem(t,y)
t=-1:1:10;y=sin(pi.*t)/pi.*t;subplot(2,1,2);
stem(t,y)

0.5

0
-2

-1.5

-1

-0.5

0.5

1.5

-15

x 10

2
0
-2
-4
-2

10

Q3. Generate two discrete-time signals called sig1 and sig2 of length 1, 000. The
samplesof sig1 should be independent, Gaussian random variables with mean 0 and
variance 1.The samples of sig2 should be independent, Gaussian random variables with
mean 0.2 andvariance 1. Use random or randnto generate these signals, and then plot
them in a samefigure. (An alternative name for a Gaussian random variable is a normal
random variable.)Next form a new signal ave1(n) of length 1, 000 such that ave1(n)
is the average of thevector sig1(1:n) (theexpression sig1(1:n) returns a vector
containing the first nelements of sig1). Similarly, compute ave2(n) as the average
of sig2(1:n). Plot thesignals ave1(n) and ave2(n) versus n on a same
plot.Comment on how the average values changes with n.
Sol:
r=0+1*randn(1000);
t=0.2+1*randn(1000);
subplot(3,1,1);
plot(x);
title('sig(1)');
subplot(3,1,2);
plot(y);
title('sig(2)');
r=mean(r);
t=mean(t);
subplot(3,1,3);
plot(r);
holdon
plot(t);
title('average')

sig(1)
10
0
-10

500

1000

1500

2000

2500

sig(2)
2
1
0

0.2

0.4

0.6

0.8

1.2

1.4

1.6

1.8

600

700

800

900

1000

average
0.4
0.2
0

100

200

300

400

500

POST LAB EXERCISE


Q1.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)
(b) xb(t) = (t + 1/2) (t - 1/2)
(c) xc(t) = t u(t)
(d) xd(t) = u (t + 2) u(t - 5)
(e) xe(t) = r (t +1) r (t) + r (t - 2)
(f) xf(t) = exp(-t) sin(2t) + exp(-t/2) cos(5 t)
Sol:
a) x=-10:0.01:10;
y=2.*(x==-2)+0;
plot(x,y)

2
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
-10

-8

-6

-4

-2

10

-4

-2

10

b) t=-10:0.01:10;
y=2.*(t==-2)+-2.*(t==2);
plot(x,y)
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
-10

c)x=-10:0.01:10;

-8

-6

y=x.*(x>=0)+0;
plot(x,y)

10
9
8
7
6
5
4
3
2
1
0
-10

-8

d)x=-10:0.01:10;
y=1.*(x>0)-1.*(x>5);
plot(x,y)

-6

-4

-2

10

e)x=-10:0.01:10;
y=(x+1).*(x>-1)-x.*(x>0)+(x-2).*(x>2)+0;
plot(x,y)
9
8
7
6
5
4
3
2
1
0
-10

f)t=-10:.2:10;

-8

-6

-4

-2

10

y=exp(-t).*sin(2*pi*t) + exp(-t/2).*cos(5*pi*t);
plot(t,y)
4

x 10

1.5

0.5

-0.5

-1
-10

-8

-6

-4

-2

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


a. xa[n] = r[-n]
b. xb[n] = exp(n-1)
c. xc[n] = [n - 1] [n - 2]
d. xd[n] = u [n + 1] 2u[ n] + u [n-1]
e. xe[n] = r [n + 3] r [n - 3]
f. xf [n] = an cos(2 n)
sol:
a)
n=-5:1:5;
y=-n.*(n<=0) + 0.*(n>0);
stem(n,y)

10

5
4.5
4
3.5
3
2.5
2
1.5
1
0.5
0
-5

b) t=-5:1:5;
y=exp(n-1);
stem(n,y)

c)

-4

-3

-2

-1

n=-5:5
for n=-5:5
if(n==2)
y=n-1
stem(n,y,'k--')
end
end

Q3. Sketch the waveform:

b. Using the result of part (a), compute the derivative of v(t), and sketch its waveform
sol:
t=0:.01:7;
v=20.*(exp(-2.*t)).*(t<=2)+10.*(t-3).*(t>2 & t<3)+(-10*t+50).*(t>3 & t<5)+(10*t-70).*(t<7
& t>5);
plot(t,v);
xlabel('t(s)');
ylabel('V(t)');
figure
der=diff(v)./diff(t);
der(1,length(t))=0;
plot(t,der);
xlabel('t');
ylabel('deravitive');

20
15
10

V(t)

5
0
-5
-10
-15
-20

t(s)

2000
1500
1000

deravitive

500
0
-500
-1000
-1500
-2000

3
t

Q4. Sketch the waveform

Sol:
t=-5:15;
fori=1:length(t)
if t(i)<=0
g(i)=5;
elseif t(i)<=4 && t(i)>0
g(i)=5-3.*t(i);
elseif t(i)<=8 && t(i)>4
g(i)=-23+t(i)^2;
else
g(i)=41;
end
end
stem(t,g);
45
40
35
30

g(n)

25
20
15
10
5
0
-5

5
n

10

15

You might also like