As the name implies, the moving average filter operates by averaging a number of points from the input signal to produce each point in the output signal. In equation form, this is written:
Where is the input signal, is the output signal, and M is the number of points in the average. For example, in a 5 point moving average filter, point 80 in the output signal is given by:
As an alternative, the group of points from the input signal can be chosen symmetrically around the output point:
This corresponds to changing the summation in Eq. 15-1 from: j = 0 to M-1, to: j = -(M-1)/2 to (M-1)/2. For instance, in a 10 point moving average filter, the index, j, can run from 0 to 11 (one side averaging) or -5 to 5 (symmetrical averaging). Symmetrical averaging requires that M be an odd number. Programming is slightly easier with the points on only one side; however, this produces a relative shift between the input and output signals.
You should recognize that the moving average filter is a convolution using a very simple filter kernel. For example, a 5 point filter has the filter kernel: …0, 0, 1/5, 1/5, 1/5, 1/5, 1/5, 0, 0…. That is, the moving average filter is a convolution of the input signal with a rectangular pulse having an area of one. Table 15-1 shows a program to implement the moving average filter.