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

Lab Task 4

The document contains MATLAB code to plot various signals and their properties. It begins by plotting sine waves with different resolutions to show how the graph changes. It then adds labels and plots multiple signals on the same graph. Finally, it generates stem plots of different discrete-time signals, including delta functions, unit step functions, and decaying exponentials. It concludes by adding two signals and plotting the originals and their sum. The document demonstrates how to generate and manipulate signal plots in MATLAB.

Uploaded by

Jaan Jaan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

Lab Task 4

The document contains MATLAB code to plot various signals and their properties. It begins by plotting sine waves with different resolutions to show how the graph changes. It then adds labels and plots multiple signals on the same graph. Finally, it generates stem plots of different discrete-time signals, including delta functions, unit step functions, and decaying exponentials. It concludes by adding two signals and plotting the originals and their sum. The document demonstrates how to generate and manipulate signal plots in MATLAB.

Uploaded by

Jaan Jaan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

Run the following three lines and explain in your own words why the plots are
different.
M-file:
t = 0:2*pi;
plot(t,sin(t))

Figure 1-1
M-file:
t = 0:0.2:2*pi;
plot(t,sin(t))

Figure 1-2

M-file:
t = 0:0.02:2*pi;
plot(t,sin(t))

Figure 1-3
Explaination:
The difference between the graphs is due to the space given between the
Points in each question is different.

2. For the last graph


a. Add a title of [Your Name]
b. An X-label of [Your Class code]
c. A Y-label of [Your ID]
M-file:
t = 0:0.02:2*pi;
plot(t,sin(t))
xlabel(' EE-2014-B');
ylabel('CU-301-2014');
title('Asif khan');

Asif khan

1
0.8
0.6

CU-301-2014

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

3
4
EE-2014-B

Figure 2-1
3. Plot the two curves y1= x2 and y2= 10x on the same graph using different plot styles.
Label the plot properly.
M-file:
x=0:0.2:10;
y1=(x).^2;
y2=10*x;
plot(x,y1,'+',x,y2,'*');

Figure 3-1
4. Make stem plots of the following signals. Decide for yourself what the range of n
should be.

f(n)=u(n)-u(n-4)
M-file:
clear all;
clc;
n=-5:5;
y=(n>=0)-(n-4>=0);
stem(n,y);
xlabel('n');
ylabel('f(n)');
title('Graph of Discrete-time Signals');
Graph of Discrete-time Signals

1
0.9
0.8
0.7

f(n )

0.6
0.5
0.4
0.3
0.2
0.1
0
-5

-4

-3

-2

-1

0
n

Figure 4-1

g(n)=n.u(n)-2(n-4).u(n-4)+(n-8).u(n-8)
M-file:
clear all;
clc;
n=-20:20;
y=(n.*(n>=0))-((2.*(n-4>=0)).*(n-4>=0))+((n-8).*(n-8>=0));
stem(n,y);
xlabel('n');
ylabel('g(n)');
title('Graph of Discrete-time Signals');
Graph of Discrete-time Signals

30

25

g (n )

20

15

10

0
-20

-15

-10

-5

0
n

10

Figure 4-2
x(n)=(n)-2(n-4)
M-file:
n=-5:5;
y=(n==0)-2.*(n-4==0);
stem(n,y);
xlabel('n');
ylabel('x(n)');
title('Graph of Discrete-time Signals');

15

20

Graph of Discrete-time Signals

0.5

x (n )

-0.5

-1

-1.5

-2
-5

-4

-3

-2

-1

0
n

Figure 4-3
y(n)=(0.9)^n(u(n)-u(n-20))
M-file:
clear all;
clc;
n=-30:30;
y=((0.9).^n).*((n>=0)-(n-20>=0));
stem(n,y);
xlabel('n');
ylabel('y(n)');
title('Graph of Discrete-time Signals');
Graph of Discrete-time Signals

1
0.9
0.8
0.7

y (n )

0.6
0.5
0.4
0.3
0.2
0.1
0
-30

-20

Figure 4-4

-10

0
n

10

20

30

v(n)=cos(0.12?n)u(n)
M-file:
clear all;
clc;
n=-20:.2:20;
y=cos(0.12*pi*n).*(n>=0);
stem(n,y);
xlabel('n');
ylabel('v(n)');
title('Graph of cos(0.12*pi*n)');
Graph of cos(0.12*pi*n)

1
0.8
0.6
0.4

v (n)

0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-20

-15

-10

-5

0
n

10

15

20

Figure 4-5
5. Write a MATLAB program that adds the following two signals, Plot the original signals
as well as their sum.
X[n]= [1 1 1 1 1 0]

Y[n]= [1 1 1 1 1 1]

M-file:
clear all;
clc;
n1=[-5 -4 -3 -2 -1 0];
x1=[1 1 1 1 1 0];
subplot(3,1,1);
stem(n1,x1);
xlabel('n1');
ylabel('x1(n1)');

title('Graph of x1(n1) signal');

x 1(n1)

n2=[0 1 2 3 4 5];
y2=[1 1 1 1 1 1];
subplot(3,1,2);
stem(n2,y2);
xlabel('n2');
ylabel('y2(n2)');
title('Graph of y2(n2) signal');
n3=[-5 -4 -3 -2 -1 0 0 1 2 3 4 5];
y3=[1 1 1 1 1 0 1 1 1 1 1 1];
subplot(3,1,3);
stem(n3,y3);
xlabel('n3');
ylabel('y3(n3)');
title('Addition of the two signals');
Graph of x1(n1) signal

1
0.5

y 2(n2)

0
-5

-4

-3.5

0.5

1.5

-4

-3

-2

-3

-2.5
-2
n1
Graph of y2(n2) signal

-1.5

-1

-0.5

2.5
3
3.5
n2
Addition of the two signals

4.5

0.5
0

y 3(n3)

-4.5

0.5
0
-5

Figure 5-1

-1

0
n3

You might also like