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

Signal Lab

The document contains MATLAB code to perform various operations on matrices and evaluate signal expressions. For part a, it creates a 5x5 magic matrix A and comments on the results. It then adds A with a random matrix, multiplies A by scalars and vectors, constructs a diagonal matrix to multiply with A, finds the inverse of A, and performs other operations like interchange rows and replacing elements. For part b, it generates time and signal vectors to evaluate expressions like 2cos(10πt), 2cos(10πt)sin(16πt), -2e^0.5tsin(2πt), and log2(1.5+10e^0.5tsin(2πt

Uploaded by

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

Signal Lab

The document contains MATLAB code to perform various operations on matrices and evaluate signal expressions. For part a, it creates a 5x5 magic matrix A and comments on the results. It then adds A with a random matrix, multiplies A by scalars and vectors, constructs a diagonal matrix to multiply with A, finds the inverse of A, and performs other operations like interchange rows and replacing elements. For part b, it generates time and signal vectors to evaluate expressions like 2cos(10πt), 2cos(10πt)sin(16πt), -2e^0.5tsin(2πt), and log2(1.5+10e^0.5tsin(2πt

Uploaded by

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

Question 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.

>> A=magic(5)
A=
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> B=A+rand(5)
B=
17.7577 24.7060 1.8235 8.4387 15.4898
23.7431 5.0318 7.6948 14.3816 16.4456
4.3922 6.2769 13.3171 20.7655 22.6463
10.6555 12.0462 19.9502 21.7952 3.7094
11.1712 18.0971 25.0344 2.1869 9.7547

b. Multiply the matrix A by 2

>> A*2
ans =
34 48 2 16 30
46 10 14 28 32
8 12 26 40 44
20 24 38 42 6
22 36 50 4 18

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

>> C=rand(5,1)
C=
0.3517
0.8308
0.5853
0.5497
0.9172
>> A*C
ans =
44.6591
38.7104
45.1728
38.9023
42.8090
d. Multiply the matrix with a diagonal matrix. (construct the diagonal matrix manually)

>> D = [1 0 0 0 0;0 1 0 0 0;0 0 1 0 0;0 0 0 1 0;0 0 0 0 1]


D=
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
>> D*A
ans =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9

e. Find out the inverse of this matrix.

>> inv(A)
ans =
-0.0049 0.0512 -0.0354 0.0012 0.0034
0.0431 -0.0373 -0.0046 0.0127 0.0015
-0.0303 0.0031 0.0031 0.0031 0.0364
0.0047 -0.0065 0.0108 0.0435 -0.0370
0.0028 0.0050 0.0415 -0.0450 0.0111

f. Multiply this matrix by itself to get A^2. The find the maximum value of the matrix
using the max() function
>> max(A*A)
ans =
1090 1075 1145 1075 1090

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

>> A.*A
ans =
289 576 1 64 225
529 25 49 196 256
16 36 169 400 484
100 144 361 441 9
121 324 625 4 81

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

A=
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> x=A(2,:);
>> A(2,:)=A(3,:);
>> A(3,:)=x
A=
17 24 1 8 15
4 6 13 20 22
23 5 7 14 16
10 12 19 21 3
11 18 25 2 9
i. Replace the numbers on the locations (2:3,3) and (4,3:5) with zeros.
>> A
A=
17 24 1 8 15
4 6 13 20 22
23 5 7 14 16
10 12 19 21 3
11 18 25 2 9
>> A(2:3,3)=0
A=
17 24 1 8 15
4 6 0 20 22
23 5 0 14 16
10 12 19 21 3
11 18 25 2 9
>> A (4,3:5)=0
A=
17 24 1 8 15
4 6 0 20 22
23 5 0 14 16
10 12 0 0 0
11 18 25 2 9

Question2: 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𝜋𝑡)
>> t=0:0.05:5;
>> x=2*cos(10*pi*t);
>> plot(t,x)
>> length(x)
ans =
101
>> length(t)
ans =
101

b. x(t) = 2cos(10𝜋𝑡). 𝑠𝑖𝑛(16𝜋 𝑡)


>> t=0:0.05:5;
x=2*cos(10*pi*t).*sin(16*pi*t);
plot(t,x)
length(t)
length(x)
ans =
101
ans =
101
c. 𝑥(𝑡) = −2𝑒0.5𝑡𝑠𝑖𝑛(2𝜋 𝑡)
>> x=-2*exp(0.5*t).*sin(2*pi*t);
>> plot(t,x)
length(t)
ans =
201
>> length(x)
ans =
201
d. 𝑥(𝑡) = log2(1.5 + 10𝑒0.5𝑡𝑠𝑖𝑛(2𝜋 𝑡))
>> t=0:0.05:10;
>> x=log2(1.5+10*exp(0.5*t).*sin(2*pi*t));
>> plot(t,x)
Warning: Imaginary parts of complex X and/or Y arguments ignored
>> length(x),length(t)
ans =
201
ans =
201

You might also like