Implementing Moving Average Algorithm for Data Analysis

  • Thread starter Thread starter khdani
  • Start date Start date
  • Tags Tags
    Average
Click For Summary

Discussion Overview

The discussion revolves around implementing the moving average algorithm for data analysis, specifically in the context of smoothing spectra graphs. Participants explore various methods to achieve a smoother representation of data while retaining significant peaks, considering both moving averages and alternative filtering techniques.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant seeks clarification on how to plot new data points after calculating a moving average of five values.
  • Another participant states that the output at time n is the average of the input at times n and the four preceding values.
  • A participant questions whether there are better algorithms that yield more accurate results, prompting a discussion on the definition of accuracy.
  • One participant shares their experience with spectra graphs and expresses a desire for a smoother representation without small fluctuations, asking for alternatives to moving averages.
  • Another suggests increasing the sample size of the moving average to achieve greater smoothing.
  • Concerns are raised about the shifting of peaks in the smoothed graph, with suggestions to adjust the graph's position or to average points symmetrically around the target point.
  • A participant inquires about implementing a high pass filter and expresses confusion regarding its application and effectiveness.
  • Discussion includes considerations of real-time processing versus post-processing and the implications for data averaging methods.
  • One participant clarifies that a low-pass filter would be more appropriate for reducing high-frequency fluctuations in the data.
  • Another participant provides a formula for enhancing peaks and discusses the challenges of maintaining peak positions during real-time processing.

Areas of Agreement / Disagreement

Participants express various viewpoints on the effectiveness of moving averages versus other filtering techniques, with no consensus reached on the best approach. There is ongoing debate regarding the definition of accuracy and the implications of different filtering methods on data representation.

Contextual Notes

Participants mention the limitations of real-time processing and the challenges of maintaining peak positions when using different averaging techniques. There are unresolved questions regarding the implementation of filters and the specific definitions of accuracy in the context of data analysis.

khdani
Messages
53
Reaction score
0
hello,
i'm trying to implement the moving average algorithm
http://en.wikipedia.org/wiki/Moving_average

i don't understand, after i calculate an average of say 5 values, what do i do
with the x values? how do i plot the new data points?
 
Physics news on Phys.org
The output at time n is equal to the average of the input at times n, n-1, n-2, n-3, and n-4.

- Warren
 
thanks chroot,
is there a better algorithm, which gives more accurate results ?
 
Define accurate. What are you trying to represent?
 
Increase the "sample size" of your moving average. That should smooth it out some more.
 
Look carefully at the peaks of the two graphs. The one with the running average has the peaks shifted to the right. The larger the sample size, the more they will shift to the right. You might consider moving your whole graph to the left by half the number of points in your running average.

Or consider averaging a point with the same number of points to the left and to the right of it. This method has the disadvantage of averaging fewer points at the left and right extremes of your data.
 
khdani said:
but i want it to be without this small fluctuations, as linear as possible, but only the noticeable peaks to keep.
so, is there any other techniques except moving average ?

Do you know to implement a high pass filter?

Are you working in Excel or programming this in a particular language?
 
i'm programming this in C#,
i don't know how to implement high pass filter, would you please explain what exactly do you mean by implementing a high pass filter and would it help?

Or consider averaging a point with the same number of points to the left and to the right of it. This method has the disadvantage of averaging fewer points at the left and right extremes of your data.

i didn't understand this, would you please explain this ?
 
  • #10
That will depend on whether you're doing this in real-time. If you are, then you can only use data that you've already taken, or in the past. That will force you to use a backwards method. If you are doing this post-processing, then you can average from both behind and in front of your point of interest. This will keep the peaks at the right place in time.

Alternately you can look at CFD dissipation algorithms which are similar in a way to what you're doing.
 
  • #11
Well, you'd want a low-pass filter, not a high-pass.

A low-pass filter is a system which permits low low frequencies to pass from input to output, but blocks high frequencies. The small wiggles on your plot are high-frequency information, and would be blocked by such a filter.

If you don't know how to design one, it's really too complex a topic for us to explain here. If you have access to MATLAB, though, you can design some basic filters with just a couple of lines of code, and we can help you with that.

- Warren
 
  • #12
khdani said:
i'm programming this in C#,
i don't know how to implement high pass filter, would you please explain what exactly do you mean by implementing a high pass filter and would it help?

i didn't understand this, would you please explain this ?

Only you know what want and what you consider accurate. If what you want is to locate the peaks without regard to actual values this may be of help.

Again given the raw data points at A(n) and output at B(n), B(n) = A(n+2) - A(n-2) + A(n)*Exp(t).
You may be able to enhance the peaks by changing the value of t or raising the result to an odd power greater than one. Try starting with a value for t of -1.

B(n) = (A(n+2) - A(n-2) + A(n)*Exp(t))^3
Running averages typically average the current value with historical values resulting in a shift of the curve to the right by half the number of data points that are being averaged. To prevent that, the running average must average the same number of future points as it averages historical points. Obviously this isn't possible if you're doing real time processing or averaging at either end of the data series.
 

Similar threads

  • · Replies 17 ·
Replies
17
Views
4K
Replies
7
Views
2K
Replies
86
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
7
Views
3K
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
19K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K