LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TSA Moving Average

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.

Download All
0 Kudos
Message 1 of 4
(6,764 Views)
Hello WCR,

I think I have found out what is wrong with your program. You set the number of samples to 4 inside the simulate signal express VI. Each iteration of the loop only has 4 values. This is why your output looked stepped. Change this to 200 (5 cycles) and observe what happens. You need to first acquire your data then display it. I have modified your example. Take a look and let me know if you have any more questions.



Jon S.
Regards,

Jon S.
National Instruments
LabVIEW NXG Product Owner
Download All
Message 2 of 4
(6,716 Views)
Thank you Jon S.  I see that the default automatic setting in Simulate_Signal express VI results in 4-point-long waveforms.  When I make the number 200, as you suggested, there are 2 things I don't like about the results: I must wait 5 sec between screen updates, at which point I get 200 points all at once, instead of smooth updates every point, and worse, there are huge glitches at the start/end of each 200 points (see attached screenshot).  "All I want" is smooth scrolling updates so that with each data point collected, I see the running average of N preceding points.  Thank you.
0 Kudos
Message 3 of 4
(6,627 Views)

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.  

 


Running Average of Array
Regards,

Jon S.
National Instruments
LabVIEW NXG Product Owner
Message 4 of 4
(6,608 Views)