04-14-2018 02:26 AM
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 :
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 ??
04-14-2018 07:41 AM
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
04-14-2018 08:04 AM
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
04-14-2018 09:56 AM
@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.
04-14-2018 10:01 AM
@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.
04-14-2018 11:41 AM - edited 04-14-2018 11:47 AM
@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
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
04-14-2018 02:51 PM
@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 :
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: