HOMEWORK #4
DUE OCTOBER 21
(3 POINTS)

Write a subroutine that calculates a moving average. Your subroutine should average data within a (variable length) window that moves along the array of  N data points.
 

Turn in:

A copy of the moving average subroutine and a copy of convolution subroutine.

The original and filtered data from step 2, 3 and 4.Turn in only the plots not the data values.

Supplement:

Some of you have problems understanding convolution. Here is a small example to try to show how easy it is to do, and direct you on how to write a subroutine to do convolution.

Suppose you have 2 arrays that you want to convolve. We shall call these arrays A and B. Let,

A=(a1,a2,a3,a4,a5)
B=(b1,b2,b3)

To convolve these 2 arrays you must reverse the order of one of them. Let us reverse the order of B. You then slide the 2 arrays along, multiplying and adding as you do. We will put the output into the array C. Note that the length of C is one less than the sum of lengths of A and B (i.e array C will have a length 7).

After much tedious work by hand, we get the following values for the variables of C.

c1 = a1b1
c2 = a1b2 + a2b1
c3 = a1b3 + a2b2 + a3b1
c4 =            a2b3 + a3b2 + a4b1
c5 =                        a3b3 + a4b2 + a5b1
c6 =                                    a4b3 + a5b2
c7 =                                                a5b3

Note that as your proceed across the columns from left to right, the subscript on the a's increase. As you go down the rows, the subscript on the b's increase. As you go down the rows, note also that the c's increase. This should give you some hint on how to write a FORTRAN subroutine that will take care of the subscripts and only use 2 do loops. Another hint that you may want to note: you don't always have to calculate all of the variables for each value of C before going to the next value. You can fill several values within the same loop.