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

SCHOOL OF ENGINEERING SCIENCE

SIMON FRASER UNIVERSITY


ENSC 180 Introduction to Engineering Analysis
Lab 1 – Due: 4:20PM, Thur. Jan. 11, 2024

Submission instruction: Since the questions in Lab 1 are quite easy, please include all of your
commands, the corresponding outputs, and your analysis (if asked) as a single pdf file, with
necessary titles (such as Q1.1). No need to submit separate Matlab file. For example,

Q1.1:
>> a = 10
a =
10

Q1: Vector Mean and Variance (15 points)

Consider a vector A = [17, 5, 2, 1, 4, 3, 2, 1, 0, 7, 7, 6];

1) (5 points) Use the sum( ) function to find the mean value of the vector, which is defined as

1 𝑁𝑁
𝜇𝜇𝐴𝐴 = 𝑁𝑁
�𝑘𝑘=1 𝐴𝐴(𝑘𝑘), where N is the length of the vector.

2) (10 points) Use the sum ( ) function to find the variance of the vector, which is defined as

1 𝑁𝑁
𝜎𝜎𝐴𝐴2 = 𝑁𝑁
�𝑘𝑘=1(𝐴𝐴(𝑘𝑘) − 𝜇𝜇𝐴𝐴 )2.

Q2: Matrix (35 points)

Consider the 5x5 magic matrix B given by the magic(5) function in Matlab.

1) Find the sum of each column of B.


2) Find the sum of each row of B.
3) Find the sum of the diagonal entries of B, i.e., B(k, k), for k = 1, 2, 3, 4, 5.
4) With the help of the fliplr( ) function, find the sum of the anti-diagonal entries of B, i.e.,
B(1, 5), B(2, 4), B(3,3), B(4,2), B(5,1). Check the help information of the fliplr( ) function to
understand what it does.
5) Find a logical array showing which entries of B are < 5.
6) Find a logical array showing which entries of B are >= 20.
7) Set entries of B that meet the conditions in 5) or 6) above to be 100.
Q3: DCT Matrix (50 points)

The Discrete Cosine Transform (DCT) is the most widely used linear transform in image and
video compression. It is used in popular compression standards such as JPEG, H.264, H.265, and
H.266.

The DCT is a matrix with closed-form expression for any size M x M. Let T be the M x M DCT
matrix, and X be a M x M data matrix, then the one-dimensional DCT transform of X is defined
as:

Y1 = T * X,

And the two-dimensional DCT transform of X is defined as:

Y2 = T * X * T’,

Where T’ is the transpose of T.

The DCT matrix T can be obtained using the Matlab command


T = dct(eye(M));
where eye(M) returns the M x M identity matrix,because when X = I (the identity matrix),
we have Y1 = T * I = T.

1) Let M = 2, find the 2x2 DCT matrix T2.


2) Find the result of T2 * T2’.
3) Let X2 = ones(2), find T2 * X2.
4) Find T2 * X2 * T2’.
5) Let M = 4, find the 4x4 DCT matrix T4.
6) Find the result of T4 * T4’.

1 2 3 4
7) Let 𝑋𝑋4 = �1 2 3 4� . Find T4 * X4.
1 2 3 4
1 2 3 4

8) Find T4 * X4 * T4’.
9) Find the sum of each row of the 4x4 DCT matrix T4.
10) No programming is needed: Discuss the symmetry of each row in the DCT matrix T4.

You might also like