

2.3 Assignment  Lecture 2
For this assignment you will experiment with vectors and matrices in the form of sound files and images, while getting a sense for Matlab. You will solve several small problems that amount up to 2 exercises. You should use the exercise from class as a guide to solving this assignment.
One of the main foci of this assignment is for you to get a really good grip on knowing the difference between rows and columns. Make sure that you understand the difference and how to handle them well!
Use vector and matrix operations where necessary. This includes arithmetic and indexing operations. For example, when asked to divide one vector by another, do it is not permitted to perform this operration explicitely on each pair of numbers  you should use vector operations instead.
Suppress the
Command Window output of all steps, unless otherwise noted.
 Download the image file above.
 Load it in Matlab and assign it to a variable.
 Display the image.
 For each color (
Red, Green, and Blue), extract the submatrix between rows 558:643 and columns 622:703 and assign each of the 3 submatrices to a variable (for example, subimageR, subimageG, subimageB). Display each of the three images.
 Pick the image that tells you the most  one of the images contains more information that you expect. If all of the images are blank, you should revisit the previous step (Hint: Did you perhaps confuse rows and columns?).
 Convert the chosen image to data type double and assign it to a new variable. Use this new variable from here on.
 Extract the vector between rows 13:80 and column 24 and assign it to the variable
vectorA
 Extract the vector between rows 13:80 and column 45 and assign it to the variable
vectorB
 Extract the vector between rows 13:80 and column 46 and assign it to the variable
vectorCNow, perform the following operations:
 Exponentiate
vectorA to vectorB (elementbyelement) and assign the result to a new variable.
 Multiply the resulting variable by
vectorB (elementbyelement) and assign the result to a new variable.
 Add the previous result to
vectorC and assign this result to a new variable.
 Now add the scalar
32 to the previous result and assign this result to a new variable.
 Now use function char() on the result, e.g. if the previous result is stored in variable
A, use char(A). Make sure not to use a semicolon for this last step. Read the result in plain English. If the result does not make sense, you should go over this assignment again.
 Finally, transpose the result from char() from the previous step, in order to put the phrase in one row as opposed to one column. Do not supress the output from this step.
 Download the sound file above.
 Load the sound file and assign it to a variable, e.g.
soundfile
 Play the sound file to make sure that it has been loaded correctly.
 Assign the waveform
sin([0:0.4:pi*150])
to a variable.
 Play the waveform. You will use this waveform to replace a part of
authoritah.wav
 Extract the word "authoritah" from the sound file, just like it has been done in the inclass exercise, and assign it to a new variable. The word is between indices 9800:length(
soundfile)
 Find out the length of the extracted word's sound file using either function
length() or size(). The waveform resembling a beep will need to be of this size in order to replace the word "authoritah". Do not suppress the output from this step.
 To find out how many times the sine wave needs to be repeated, compute the following:
x = length * 0.4/pi
where length is the previously computed length. Note that the variable pi is already defined in Matlab.
 Generate the beep waveform of the correct length as follows:
sin([0.4:0.4:pi*x])
and assign the result to a new variable.
 Verify that the length of the word "
authoritah" is the same as that of the new waveform. Do not suppress the output from this step.
 Now, replace the sound "
authoritah" between indices 9800:length(soundfile) of the original sound file with the new waveform. You must use matrixsubscripting (indexing) for this step. It is not acceptable to concatenate different matrices in order to produce the result of this step.
 Play back the changed wave form. The sound "
authoritah" should now be replaced by a beep.
Build a small image with color lettering "
HELLO". Generate 3 matrices, one for each of the color intensity layers: red, green, and blue. The matrices should be sized to 7 rows and 21 columns. Populate each matrix with color intensity values to form the word "HELLO", with H: red, E: green, L: blue, L: yellow, O: cyan, and all remaining pixels (background): black. The bitmap image is as follows:
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21 
1                      
2   H   H   E  E  E   L     L      O   
3   H   H   E     L     L     O   O  
4   H  H  H   E  E  E   L     L     O   O  
5   H   H   E     L     L     O   O  
6   H   H   E  E  E   L  L  L   L  L  L    O   
7                      
Steps:
 Red Layer: Generate a 2D matrix in variable
r sized to 7 rows and 21 columns with all zeros. Have a look at function zeros!
 Green Layer: Generate the same matrix in variable
g.
 Blue Layer: Generate the same matrix in variable
b.
 Populate each of the matrices (in any order) with pixel intensity values of
255. You'll have to decide what matrices to place these values in to generate the correct color, but you must follow the instructions below on whether to place individual pixels, row vectors, or columns vectors. In other words, if the assignment asks you to place a column vector, you should do so with one command, and not several substeps.
Hint: Recall from lecture how to replace individual elements in matrices, and how to replace rows, columns, and submatrices: In an assignment where the lefthand side denotes a destination and the righthand side denotes a value, the dimensionality of the value must match the dimensionality of the destination (see lecture 1). For example, to place a column vector
C in matrix M, the lefthand side should address the correct location of C, and the righthand side should resemble a column vector of equal size with a set of new values.
 H:
 Column vector in column 2 and row 26,
 Column vector in column 4 and row 26,
 Pixel at row 4 and column 3.
 E:
 Row vector in row 2 and column 68,
 Row vector in row 4 and column 68,
 Row vector in row 6 and column 68,
 Pixel value at row 3 and column 6,
 Pixel value at row 5 and column 6.
 L:
 Column vector in column 10 and row 26,
 Row vector in row 6 and column 1112.
 L:
 Column vector in column 14 and row 26,
 Row vector in row 6 and column 1516.
 O:
 Column vector in column 18 and row 35,
 Column vector in column 20 and row 35,
 Pixel value at row 2 and column 19,
 Pixel value at row 6 and column 19.
 Generate a 3D matrix in variable
hello by merging the 3 color intensity matrices. The individual color intensity matrices are 2D with columns and rows. In order to create a 3D matrix with columns, rows, and layers (depth), you must address variable hello at the appropriate depth values, and place the 2D matrices at those locations. Have a look at lecture 2 for examples on 3D indexing.
 Display the matrix in the
Command Window. Do not supress the output for this step.
 Convert the type of 3D matrix
hello to data type uint8.
 Display the image represented by matrix
hello.

