Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Signal Lab Report 1

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

Signals and system (lab report 01)

Submitted to: Ma’am Zainab


Submitted by: Umm-e-Hani
Registration no: FA22-EEE-040
Dated: 26 October, 2023
IN LAB TASKS:
1. Identify if the following variable is a scalar, a row vector, a column
vector or a matrix and write your findings in the blank space
provided in front of each part.

a. var = [1 2 3 4 5]
Row vector
b. var = [100]
Scalar
c. var = [10 : 10 : 50]
Row vector
d. var = [10:15]
Row vector
e. var = [ 5 : -1 : 1]
Row vector
f. var = [1 ; 2 ; 3]
Column vector
g. var = [0 -1; 2 4]
Matrix
h. var = [1 2 3 4 5]’
Column

2. Create a 3 × 2 matrix containing arbitrary data. Explore using


the following MATLAB functions.
(where N = 3 and M = 2 for this example Give a one-line
explanation of each function in the space below.

zeros() This fuction fills the array with zeros.


ones() fills the array with ones.
eye() makes a diagonal matrix.
rand() makes a matrix of
random numbers
size() gives the size of a
matrix.
length() gives the length of a
vector.
3. Use the functions size() and length() to compute the size of the arrays
given by array1 = - 1: 0.1 : 0.1 and array2 = 10 : 2 : 28. Consider
general array constructor patter, i.e., array = start : step : stop. Answer
in the space provided after evaluating each expression in MATLAB.
a. How many elements are in each array?
Array1 has 12 elements, array2 has 10 elements.

b. Can you add these arrays? Give reason.


No we cannot add because size of two arrays is not same.

c. Now concatenate ones such that the number of columns in array1 are increased by
2, ( i.e., says array3 = [ ones(1,2), array2 ] ). Can you add array1 and array3? Give
reason to your answer.
Yes because size of two arrays is same.
d. Multiply array1 and array2 without the element-by-element operator (“.”).
Write the error prompted as well as the reason for the error.
The error is Incorrect dimensions for matrix multiplication.

e. Multiply array1 and the transpose of array2 (i.e array 1 * array2’) as in part d.
Explain your findings?
gives error because the size of two vectors is not same.

f. Repeat the same with the expression given by array2’ * array1. What are the
dimensions of your output now?
The dimensions of output vector are 12, 10

4 Any built-in function that operates on a scalar can also operate on an


array or a matrix. e.g., lo to the base 10 is computed in command
window as given below,
This is known as vectorization. Using vectorization, a row vector that
tabulates the values of cos function for the input {0, π⁄10 , 2π} is shown
below.
a. Following the same procedure, compute the values of the following
function with input given along. (write the first five values of the
outputs in table below)

MATLAB Function | Domain | Range (first five values)


log2() | 2 : 2 : 14 | 1.0000 2.0000 2.5850 3.0000 3.3219
sin() | {0, 𝜋⁄10 , 2π} | 0 0.3090 0.5878 0.8090 0.9511
sec() | {0, 𝜋⁄10 , 2π} | 0.0000 0.0000 0.0000 0.0000
0.0000
tan() | {0.25𝜋, 𝜋⁄10 , 0.25π} | 1.0000
atan() | 0 : 0.1 : 1 | 0 0.0997 0.1974 0.2915 0.3805

b. Take any function from the functions in Table IL 1, use the following functions
given by Table IL 2 on the outputs and write down the results in the following table.
e.g.,

MATLAB Domain | Range (first five


Function | values)
round() | 2 : 2 : 14 | 1 2 3 3 3
ceil() | {0, 𝜋⁄10 , 2π} | 0 1 1 1 1
floor() | {0, 𝜋⁄10 , 2π} | 0 0 0 0 0

What does each function in table IL 2 does to the


input?
round() It rounds off input towards nearest
decimal.
ceil() It rounds input towards + infinity.
floor() It rounds input towards - infinity.

5: Let’s visualize(plot) a sinusoid represented by the following expression,


x(t) = sin(2𝜋𝑓𝑡) ∀ 𝑡 ∈ [0,5] and 𝑓 = 1 𝐻𝑧
For this purpose, type in the following code in the command window, skip
the text with a “%” symbol
before it. The percent sign is generally used to indicate nonexecutable text
within the body of a
program.
Now open the variable “x” from the command window as indicated in Figure L.1.7. Insert a value at
the 52nd place and execute the “plot()” function again. (you may use arrow key up from your keyboard
to recall the code line-by-line) and answer the following.

a. Write the syntax for the plot() function and brief description. (use MATLAB help: type “help
plot”
in the command window and then click doc plot).

plot(X,Y) plots vector Y versus vector X.

b. Did the code run successfully?


No

c. What error did you encounter? Please write the error displayed by MATLAB in your
command
window.
Error using plot Vectors must be the same length

D : Define a new variable Fs = 8000;, where Fs is the sampling frequency, write the following
code and listen to the sound. See the expression for plot and the dimension of the variables.
What happens

when we only use the plot command as plot(t, , ‘b-’)? How many cycles of the signals can you see
in
the figure?
12 cycles of signals can be seen in figure.

POST LAB TASK:


1. Create a 5 × 5 matrix A using the magic function and comments on the results. (Include results as
in command window in our report)

A. Add the matrix A with another 5 × 5 matrix created using the rand() function.
B. Multiply the matrix A by 2

C. Multiply the matrix A by a 1 × 5 vector creaded using rand() function.

D. Multiply the matrix with a diagonal matrix. (construct the diagonal matrix manually)

E. Find out the inverse of this matrix

F. Multiply this matrix by itself to get A2. The find the maximum value of the matrix
using the max() function.

G. Multiply this matrix by itself using the element-by-element operator.

H. Interchange the rows 2 and 3 of the matrix A.

I. Replace the numbers on the locations (2:3,3) and (4,3:5) with zeros.

2. Evaluate the following expressions in MATLAB and give the length of time, ‘t’ and output, ‘x’
vectors. Plot the signals as well. (t=startvalue: 0.05: endvalue;)
a. x(t) = 2cos(10𝜋𝑡) ∀ 𝑡 ∈ [0,5]
3. What is the purpose of the following built-in MATLAB functions and special variables; give
concise answers include format of the functions and an example as well. (Use mathworks
website
or MATLAB help)

abs(), real(), conj(), diag(), size(), inv(), max(), atan(), sound(), soundsc(), audioread(),
audiowrite(), NaN, Inf/inf, mod(), ceil(), rand(), plot()

Abs():abs Absolute value.


abs(X) is the absolute value of the elements of X. When
X is complex, abs(X) is the complex modulus (magnitude) of
the elements of X.

real():
real Complex real part.
real(X) is the real part of X.
See I or J to enter complex numbers.

Diag(): diag Diagonal matrices and diagonals of a matrix.


diag(V,K) when V is a vector with N components is a square matrix
of order N+ABS(K) with the elements of V on the K-th diagonal. K =
0
is the main diagonal, K > 0 is above the main diagonal and K < 0
is below the main diagonal.

Size():
size Size of array.
Inv():
Inverse of array or matrix

Max():
Find maximum value of array or matrix

Atan():
atan Inverse tangent, result in radians.
atan(X) is the arctangent of the elements of X.

sound():
sound Play vector as sound.

Audioread():
audioread Read audio files

audiowrite():

audiowrite write audio files

NaN:
NaN Not-a-Number.
NaN is the IEEE arithmetic representation for Not-a-Number.
A NaN is obtained as a result of mathematically undefined
operations like 0.0/0.0 and inf-inf.

Inf:
inf Infinity.
inf returns the IEEE arithmetic representation for positive
infinity. Infinity is also produced by operations like dividing by
zero, eg. 1.0/0.0, or from overflow, eg. exp(1000).

Mod():
mod Modulus after division.

Ceil():
ceil Round towards plus infinity.
ceil(X) rounds the elements of X to the nearest integers
towards infinity.

Rand():
rand Uniformly distributed pseudorandom numbers.
R = rand(N) returns an N-by-N matrix containing pseudorandom
values.

Plot():
plot Linear plot.
plot(X,Y) plots vector Y versus vector X. If X or Y is a matrix,
then the vector is plotted versus the rows or columns of the matrix,
whichever line up. If X is a scalar and Y is a vector, disconnected
line objects are created and plotted as discrete points vertically at
X.

You might also like