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

University of Engineering &

Technology, Taxila

LAB REPORT 1
Introduction to Programming in MATLAB
Wireless Networks-Lab
(CP-404)

LAB INSTRUCTOR
Dr. Asif Khan

SUBMITTED BY
Hareem Khan
17-CP-29

Faculty of Telecommunication & Information Engineering


B.Sc. Computer Engineering
Introduction to Programming in MATLAB
OBJECTIVES
The objective of this lab session is:
1) Plotting of Signals.
2) Plotting of Multiple Signals.
3) Creating Subplots.

LAB TASK 01
1. Use MATLAB to draw the graph of f (x) = x2 − 2x − 3 on the
interval [−1, 3].
x=-1:3;
y=x.^2-2.*x-3;
plot(x,y)
xlabel("X-axes")
ylabel("Y-axes")
title("GRAPH of f(x)= x2?2x?3")

2. Generate following elementary DT signals:


– Unit Impulse
function out=Task_1_2_2(start_point,end_point)
x=start_point:end_point;
for i=1:length(x)
if(x(1,i)==0)
y(1,i)=1;
else
y(1,i)=0;
end
end
stem(x,y);
title('Unit Impulse Signal')
xlabel('n')
ylabel('x[n]')
end
– Unit Step
function out=Task_1_2(start_point,end_point)
x=start_point:end_point;
for i=1:length(x)
if(x(1,i)>=0)
y(1,i)=1;
else
y(1,i)=0;
end
end
stem(x,y)
title('Unit Step Signal')
xlabel('n')
ylabel('x[n]')
end

– Exponential Sequence
function out=Task_1_2_3(start_point,end_point,A,a)
x=start_point:end_point;
y=A*a.^x;
stem(x,y);
title('Expoential function');
xlabel('X-axes');
ylabel('Y-axes');

3. Generate the following signal for -10<n<10


x = (10cosπn)(5cos0.25πn)
n=-10:10;
x1=10.*cos(pi.*n);
x2=5.*cos(0.25*pi.*n);
x= x1.*x2
plot(n,x)
xlabel('X-axes')
ylabel('Y-axes')
title('Graph of (10cos?n)(5cos0.25?n)')
LAB TASK 02
1. Create a symbol plot with the data generated by adding noise
to the given function:
y = 5*x.*exp(-3*x)
Where x = 0:0.01:2;

x = 0:0.01:2;
y = 5*x.*exp(-3*x);
subplot(1,2,1)
plot(x,y)
xlabel('x-axes')
ylabel('y-axes')
title('Graph 1 without noise')
y1=rand(1,201);
y2=y1+y;
subplot(1,2,2)
plot(x,y2)
xlabel('x-axes')
ylabel('y-axes')
title('Graph 2 with noise')

2. Sketch the graphs of f (x) = 1/x and g(x) = ln(x − 1) on the


interval [2, 5].
x= 2:5;
f=1./x;
g=log(x-1);
subplot(1,2,1)
plot(x,f)
xlabel('x-axes')
ylabel('y-axes')
title('Graph f(x)=1/x')
subplot(1,2,2)
plot(x,g)
xlabel('x-axes')
ylabel('y-axes')
title('Graph g(x)=ln(x-1)')
TASK NO 03
1. Write a sequence of MATLAB commands in the space below to
plot the discrete time sinusoid
x (n) = cosωn (-5 < n < 5) for the following values of
angular frequency.
You must divide your figure into 6 subplots.
• ω = 0.10π
• ω = 0.25π
• ω=π
• ω = 1.25π
• ω = 1.50π
• ω = 2π

n=-5:5;
w1=0.10*pi;
w2=0.25*pi;
w3=pi;
w4=1.25*pi;
w5=1.50*pi;
w6=2*pi;
x1=cos(w1.*n);
x2=cos(w2.*n);
x3=cos(w3.*n);
x4=cos(w4.*n);
x5=cos(w5.*n);
x6=cos(w6.*n);
subplot(2,3,1)
plot(n,x1)
xlabel('x-axes')
ylabel('y-axes')
title('Graph 1')
subplot(2,3,2)
plot(n,x2)
xlabel('x-axes')
ylabel('y-axes')
title('Graph 2')
subplot(2,3,3)
plot(n,x3)
xlabel('x-axes')
ylabel('y-axes')
title('Graph 3')
subplot(2,3,4)
plot(n,x4)
xlabel('x-axes')
ylabel('y-axes')
title('Graph 4')
subplot(2,3,5)
plot(n,x5)
xlabel('x-axes')
ylabel('y-axes')
title('Graph 5')
subplot(2,3,6)
plot(n,x6)
xlabel('x-axes')
ylabel('y-axes')
title('Graph 6')

You might also like