There is a bit of a confusing in the terminology in signal processing. Moving average filters are filters calculating a series of weighted means of the input signal. In addition to Balázs Kotosz’ comment, it is important that the weights are not equal, i.e. you calculate the running arithmetic mean of the input signal. This type of filter is usually called running mean. You shouldn’t use those because they eliminate some frequencies in your spectrum and others are reversed. That’s bad if you are interested in a specific frequency band, which is either eliminated (no response) or reversed (change of sign and hence causality) (see Page 177 in my textbook MATLAB Recipes for Earth Sciences, Springer 2010).
Here's a MATLAB Example to see the effect of running means. As an example, applying the filter to a signal with a period of approximately 1/0.09082 completely eliminates that signal. Furthermore, since the magnitude of the frequency response is the absolute of the complex frequency response, the magnitude response is actually negative between ~0.09082 and ~0.1816, between ~0.2725 and ~0.3633, and between ~0.4546 and the Nyquist frequency. All signal components having frequencies within these intervals are mirrored on the t-axis. As an example, we try a sine wave with a period of 7.0000, e.g., a frequency of approximately 0.1429, which is within the first interval with a negative magnitude response:
t = (1:100)';
x10 = 2*sin(2*pi*t/7);
b10 = ones(1,11)/11;
m10 = length(b10);
y10 = filter(b10,1,x10);
y10 = y10(1+(m10-1)/2:end-(m10-1)/2,1);
y10(end+1:end+m10-1,1) = zeros(m10-1,1);
plot(t,x10,t,y10)
Here is the amplitude response of the filter showing the zeros and the clipping:
[h,w] = freqz(b10,1,512);
f = 1*w/(2*pi);
magnitude = abs(h);
plot(f,magnitude)
The sine wave with a period of 7 experiences an amplitude reduction of
1-interp1(f,magnitude,1/7)
e.g., around 80% but also changed sign as you can see from the plot. The elimination of certain frequencies and flipping of the signal has important consequence while interpreting causality in earth sciences. These filters, though they are offered as standard in spreadsheet programs for smoothing, should therefore be completely avoided. As an alternative, filters with a specific frequency response should be used, such as a Butterworth lowpass filter.
Actually, before using the method of moving averages, one should first be able to decide the length of the smallest cycle associated with the data. Unless that is known, moving averages would lead to bad statistical analysis.
A Gaussian kernel or B-spline kernel have much better properties than the average kernel (e.g. rotation invariance, differentiability, band limitation, etc). Efficient recursive implementations exist, similar to running average. For more information see [Bouma, LNCS 4485, 2007].
PDF available at: http://home.kpn.nl/henri.bouma/research
A good deal would be using structural time series, and in it the locar linear trend model which is basically an IMA model. I suggest having a looka at Durbin and Koopman (2001) about Kalman filtering methods. Using Kalman filter is 'optimal' in my point of view.
the weight function of your moving average filter should be symmetric. Otherwise the filtered values are shifted in phase: depending on the structure of the weight function the phase lag can reach half the length of the weight function.
For example: a one-sided Kalman Filter has got an asymmetric weight function.
Further on, be careful in interpreting the filtered values at the both ends of a time-series, they've got a structural phase lag always.