12-19-2008 01:46 PM
Using TSA Moving Average.vi, from the Time Series Analysis toolbox. It is not workingas I expect. Is it defective or am I doing something wrong or expecting the wrong thing from it? Attached VI generates a simulated sinusoidal waveform, plots it, and plots the moving average of same. TSA Moving Average says it will uses user-supplied weights for the average, and if those are not supplied, it uses one of 5 user-selectable methods. My demo program uses a "flat" set of weights, the number of which is settable by the user, up to a max of 121.
My default sine wave is 1 Hz, sampled at 40 Hz. Therefore a 40 or 41-point wide flat moving average should return essentially zero, since it is averaging all the points in 1 full period. But it does not. Similarly unexpected results seen for other choices of "points to average". When the "points to avergae" is set to zero, no weights are passed to TSA Moving Average.vi, which then uses the method selected by "AvgMethod". Here too the results are not as expected. Since a moving average is a linear operation, it should give a sinusoidal output if the input is sinusoidal. But this is not quite true: the output is markedly non-sinusoidal; it is "bumpy". Any suggestions? Thank you.
Bill R.
12-22-2008 12:22 PM
01-05-2009 07:46 PM
01-06-2009 10:20 AM
Hello WCR,
The nature of the TSA moving average.vi is to first collect all the data and then perform the average. This is because future values are not known at the time of sampling. We don't have a function that will perform an average on the fly. If you want to have an average that updates as the points come in you will have to code it yourself. We have an example program that takes the running average of an array. This should get you started. Try extracting the last N points of the array then averaging them.