LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Moving Average versus High Sample size Mean

I am doing a data acquisition for single channel @ 5kHz with 250 samples / channel. So the while Loop iterates at 50ms intervals.  

Thus every 50ms  i compute the Mean of the 250 samples , then use the resulting mean value to compute the moving average with a window size of 10.  This is fine to see the trend of a physical parameter like  temperature  which inherently does not change rapidly. But i have problem when it comes to rapidly changing values like pressure as i loose out the valid peaks. The Moving Average snippet is below : 

MovingAverage.png

Instead of the Initial mean computing then doing a Moving Average of those mean values, suppose i increase the samples to 250 x 10 = 2500, will I be better off to get a relatively clean output ? ( of course the time lag resulting with Moving Average will anyway be gone ) 

 

Or any better methods can be thought off ?? 

 

 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 1 of 7
(3,591 Views)

Addressing only one of the questions:

 

Mathematically, the calucalted mean for 2500 samples will be the same whether you compute it once for all 2500 samples or whether you break it down into 10 means each of 250 samples and then take the mean of *those*.

 

"Better" methods for signals with faster dynamics will depend on the characteristics you want to preserve and the # samples you're willing to preserve to represent those characteristics.  At some point, if you don't keep all the samples, you *will* be losing information.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 2 of 7
(3,565 Views)

I take it you are not an Engineer, or have never taken a course in Signal Theory.  Taking an average (moving or not) is a form of low-pass filter (you can work out the exact form the filter will have on the spectrum of the original signal as an exercise).  The larger the average, the lower the frequency above which "information" will be lost.

 

Bob Schor

0 Kudos
Message 3 of 7
(3,563 Views)

@Kevin_Price wrote:

Addressing only one of the questions:

 

Mathematically, the calucalted mean for 2500 samples will be the same whether you compute it once for all 2500 samples or whether you break it down into 10 means each of 250 samples and then take the mean of *those*.

 

"Better" methods for signals with faster dynamics will depend on the characteristics you want to preserve and the # samples you're willing to preserve to represent those characteristics.  At some point, if you don't keep all the samples, you *will* be losing information.

 

 -Kevin P


Thanks for the clarification. Most times i resort to a minimum level of Moving Average to remove the electrical noise. Now before someone says : Noise is better handled at the hardware level and not suppressed after it reaches the DAQ card. 

 

Anyway all said and done some sites are particularly noisy and have to do some clean up post acquisition. 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 4 of 7
(3,553 Views)

@Bob_Schor wrote:

I take it you are not an Engineer, or have never taken a course in Signal Theory.  Taking an average (moving or not) is a form of low-pass filter (you can work out the exact form the filter will have on the spectrum of the original signal as an exercise).  The larger the average, the lower the frequency above which "information" will be lost.

 

Bob Schor

I have high regards for your detailed support posts... And just to answer you : I am a Mechanical engineer by qualification and yes,  they did not teach Signal Theory. 

 

The larger the average, the lower the frequency above which "information" will be lost.

That's a nice way to put it. 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 5 of 7
(3,552 Views)

@MogaRaghu wrote:

@I am doing a data acquisition for single channel @ 5kHz with 250 samples / channel. So the while Loop iterates at 50ms intervals.  

Thus every 50ms  i compute the Mean of the 250 samples , then use the resulting mean value to compute the moving average with a window size of 10.  This is fine to see the trend of a physical parameter like  temperature  which inherently does not change rapidly. But i have problem when it comes to rapidly changing values like pressure as i loose out the valid peaks. The Moving Average snippet is below : 

 

Or any better methods can be thought off ?? 

 

 


Pt by Pt Mean 

Capture.PNG

May help but you may want a oh say a 10 order eliptic IIR filter - there  is one of those on the pt-by-pt palattes too


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 7
(3,544 Views)

@MogaRaghu wrote:

@I am doing a data acquisition for single channel @ 5kHz with 250 samples / channel. So the while Loop iterates at 50ms intervals.  

Thus every 50ms  i compute the Mean of the 250 samples , then use the resulting mean value to compute the moving average with a window size of 10.  This is fine to see the trend of a physical parameter like  temperature  which inherently does not change rapidly. But i have problem when it comes to rapidly changing values like pressure as i loose out the valid peaks. The Moving Average snippet is below : 

MovingAverage.png

Instead of the Initial mean computing then doing a Moving Average of those mean values, suppose i increase the samples to 250 x 10 = 2500, will I be better off to get a relatively clean output ? ( of course the time lag resulting with Moving Average will anyway be gone ) 

 

Or any better methods can be thought off ?? 


It is not clear what you are asking, and most seem to comment on the moving average while you seem to be concerned that a moving average will smooth out rapidly changing signal features. A moving average is not compatible with rapid changes, so you probably need to record both and do more detailed analysis on the real data later to detect and process rapid changes.

 

Yes, mean-ptbypt will do the averaging for you, so get rid of that while loop you show.

 

There are many other problems with your "moving average" code, for example:

  • Memory-wise, it is a really bad idea to build an array by adding elements to the front of it. All elements if the array often need to be shifted in memory with every iteration.
  • Calculating the mean of a potentially large array is redundant if only exactly one of the elements changes with each iteration. For better ideas, have a look at my presentation (sides 12-14 and atttached example). (part II here)
  • etc.

 

 

Message 7 of 7
(3,524 Views)