CS 221 Fall 2011 Problem Set 3

CS 221 Fall 2011 Problem Set 3

Out: Friday, October 28
Due: 23:59:59 Monday, November 7

Problem 1: Plotting Time Series Data in MATLAB

Time series data occur in a wide variety of settings: signal processing, sales, traffic patterns, brain scans, manufacturing processes, investing, and even goals scored in soccer. In this problem, you will be importing, analyzing, and graphing weekly coal production in eastern and western Kentucky using data from the U.S. Energy Information Administration. (Source: http://www.eia.gov/FTPROOT/coal/weekly/weekprodforecast2002.xls.) Note that you could pull this the data directly into MATLAB from the Excel file on the above EIA site, using the xlsread. But to make the project simpler, we have extracted a simplified dataset called coalprod.csv. ("csv" stands for "comma-separated values". It is a simple, commonly-used file format in which values are presented with one row per line, with column values separated by commas.) Create a MATLAB script, "coalprod.m" in which you:

Problem 2: "Smoothing" Data

Sometimes when working with a highly variable time-series of measurements it is useful to create a "smoothed" version of the data—that is, a version in which sudden changes have been "filtered" out. A simple way to smooth a sequence of data points is to replace each value with a "moving average" obtained by averaging that value with the values in a "window" around it. In the simplest case, each value is replaced by the average of the value and the two values on either side of it. (Note that first and last values are not changed by this method.)

Write a function smooth() that takes a single m-by-n matrix (array) A as its only argument, and returns a matrix with the same first and last rows as A, but with with the values in each row averaged with the values in the previous and following rows. So, for example, given this matrix:

A = [ 4,      100,      3,       55;
     -1,        0,     57,       22;
     76,       13,     78,       33;
     88,       45,    101,       50 ]
smooth(A) would return the following matrix:
smooth(A) = 
    [ 4,      100,       3,      55;
     26.3,    37.7,     46,      36.7;
     54.3,    19.3,    78.7,     35;
     88,       45,     101,      50 ];
The entry B(2,3) is 46 because A(2,3), which is 57, is replaced by the average of 57 with the entries in the same column, in the rows before (3) and after (78) it. So (3 + 57 + 78)/3 = 138/3 = 46. In general, the entry in row i and column j of the result, for each i, 1 < i < # rows in A, is equal to (A(i-1,j)+A(i,j)+A(i+1,j))/3.

Note the following:

Submit your file smooth.m in the zip file as described below.

Submission Instructions

To submit your solutions, follow these steps: