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

Lab Report 2

The document describes tasks completed in a lab report for a signals and systems course. The tasks involve using loops, conditional statements, and plotting signals in MATLAB. Key tasks include displaying numbers using different loops, checking if commands produce the same results, explaining differences in sine wave plots with varying step sizes, and plotting multiple signals on the same axis.

Uploaded by

fa769197
Copyright
© © All Rights Reserved
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)
7 views

Lab Report 2

The document describes tasks completed in a lab report for a signals and systems course. The tasks involve using loops, conditional statements, and plotting signals in MATLAB. Key tasks include displaying numbers using different loops, checking if commands produce the same results, explaining differences in sine wave plots with varying step sizes, and plotting multiple signals on the same axis.

Uploaded by

fa769197
Copyright
© © All Rights Reserved
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/ 10

Lab Report - 2

For The Course


EE-232 Signals and Systems

For
B.E. Computer Engineering

Complied By: Checked By:

DEPARTMENT OF COMPUTER ENGINEERING


College of Electrical & Mechanical Engineering (CEME), NUST-Pakistan

Objective:
The objective of this lab is to create an understanding of using loops and conditional
statements in MATLAB. It also introduces the basics of plotting signals.

Tasks:
Task 1:
Write a MATLAB code to display the following using for loop, while loop and if
statements separately:

For Loop:

 First 30 numbers

 Even numbers

 Odd numbers
While Loop:

 First 30 numbers

 Even numbers
 Odd numbers

If else:

Task 2:
(a) Check whether the following set of commands :
for i = 1:20
H(i) = i * 5
End
have the same result as:
H = 1:20;
H = H*5

These two sets of commands have the same result as first command generates a vector and
fills it using for loop from 1 to 20 while the second command generates a vector using colon
operator from 1 to 20. Both vectors have 1 row and 20 columns and contain the same values.

(b) Check whether following set of commands:


for n = 1:100
x(n) = sin(n*pi/10)
end
have the same result as:
n = 1:100;
x = sin(n*pi/10)
These two sets of commands have the same result as first command generates a vector and
fills it using for loop from 1 to 100 while the second command generates a vector using colon
operator from 1 to 100. Both vectors have 1 row and 20 columns and contain the same
values.
Task 3:
Run the following three MATLAB lines of code and explain why the plots are different:

 t=0:2*pi; plot(t, sin(t))


 t=0:0.2:2*pi;plot(t, sin(t))
 t=0:0.02:2*pi; plot(t, sin(t))
The step size of the first plot is 1 so it is not a smooth sinusoid. As the step size decreases,
the smoothness of waveform increases. In the second plot, the step size is less than the
first graph (0.2), so the second sinusoid is smoother than the first one. Same goes for
graph three with step size 0.02 so it is smoother than all.

Task 4:
For the following, use the signal described as:

t=0:0.2:2*pi

Now perform the following operations on the signal t:

 Put two plots on the same axis, i.e. sin(t) and sin(2t)
 Produce a plot without connecting the points

 Try the following command and comment:


 t=0:0.2:2*pi; plot (t, sin(t), t, sin(2t),’r.’)
it plots a sin(t) versus t and a sin(2t) versus t graph in red color and dotted lines because
of parameter ‘r.’.
Conclusion:
We learnt for-loops, while loop and if-else statements in |MATLAB and performed
different tasks using these statements. We learnt to plot graphs in different ways such as
connected graph, graph with circles and with different step sizes.

You might also like