Signal Lab
Signal Lab
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
>> 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=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)
>> 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
>> 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
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