MAT_167_001_SQ_2018_HW_01_GRADING_RUBRIC.pdf - MAT...

This preview shows page 1 - 3 out of 13 pages.

MAT 167–001 HW 01 SOLUTIONS WITH GRADING RUBRIC SQ 2018 Problem 01 (100 points) This is a MATLAB exercise. (a ) Download the data file: HW 01.mat from Canvas to your working directory, and load it into your MATLAB session by: >> load HW_01; Then, draw the signal x in the data file using the following commands: >> figure(1); >> stem(x); hold on; plot(x); grid; Note that this signal x consists of only 8 points, i.e., a very short signal (vector). (b ) In a different figure window, draw the 8 basis vectors stored as column vectors of the matrix U as follows: >> figure(2); >> for k=1:8 subplot(8,1,k); stem(U(:,k)); axis([0 9 -0.5 0.5]); axis off; hold on; end >> for k=1:8 subplot(8,1,k); plot(U(:,k)); end You may need to see the details of these 8 plots by enlarging the window to a full screen. Print this figure and attach it to your HW submission. (c ) Compute the expansion coefficients (i.e., the weights of the linear combination) of x with respect to the basis vectors U (: , 1) , . . . , U (: , 8) via >> a=U’ * x; (d ) Check the values of the entries of the coefficient vector a and create a new vector a 2 of length 8 whose only nonzero entries are the two largest entries of a in terms of their absolute values. (e ) Construct an approximation x 2 of x using a 2 . Then, plot x 2 over Figure 1 as follows: >> figure(1); stem(x2,’r * ’); plot(x2,’r’); (f ) Now, instead of a 2 , let’s construct a 4 of length 8 whose only nonzero entries are the four largest entries of a in terms of their absolute values. Then, (g ) Construct an approximation x 4 of x using a 4 . Then, plot x 4 over Figure 1 as follows (note using the different color from x 2 ): >> figure(1); stem(x4,’gx’); plot(x4,’g’); Then, print out Figure 1, and attach it to your HW submission. © 2018 Professor E. G. Puckett) – 1 – Revision 1.03 Thu 3 rd May, 2018 at 16:42
MAT 167–001 HW 01 SOLUTIONS WITH GRADING RUBRIC SQ 2018 (h ) Consider now x 8 , which is just a full reconstruction without throwing out any coefficients, i.e., >> x8=U * a; Finally, compute the relative error of x 8 by >> sqrt(sum((x-x8).ˆ2)/sum(x.ˆ2)) and report the result. Similarly compute the relative error of x 4 and x 2 , and report the results. (i ) Write a detailed explanation of what this MATLAB program does. Solution to Problem 01 : Here is one possible MATLAB script used to solve this problem. The data on the following page comes from running this MATLAB script. Code In- cluded: 20 points -5 points If your code runs with an error clear, clc % Homework 1: Math 167 % Problem 1: Change of Basis to the Discrete Cosine Basis % Related to Music Sampling %P1-Part (a) load hw01.mat %Download Data figure(1) %Initialize figure 1 stem(x); %plot stems hold on; %allow for multiple graphs on same figure plot(x); %plot piecewise linear funciton grid; %print grid on figure 1 %P1-Part(b): View Basis vectors figure(2); %Initialize figure 2 for k = 1:8 subplot(8,1,k); stem(U(:,k)); axis([0 9 -.5 .5]); axis off; hold on; end %for(k) for k = 1:8 subplot(8,1,k); plot(U(:,k)); end %for(k) %P1-Part(c): Compute Expansion coefficients a = U' * x; %Part(d-e): Create a2: isolate 2 largest magnitude entries (thresholding) [tmp, I] = sort(abs(a), 'descend' ); %find indices: largest to smallest mag.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture