LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Post Processing array for moving average

Greetings. Hope someone out there can help me on this. I have read all the posts I could find about doing a moving average and they all had to do with performing it as the data is being acquired. Unfortunately, I can't do that. I am getting the data from a digital high speed power meter and it is read in from a buffer as a huge string that I then change into an array of data. I need to do a moving average on the data very bad and the indexing is driving me crazy. I can't figure it out. Assume that my data array is 100 elements and I want to do a moving average of 5: 0,1,2,3,4 elements are averaged and become element zero of a new array.... 1,2,3,4,5 are averaged and becomes element 1 of the new array. I would end up with a 1D new
array of 96 elements in the above example. Hope that is clear enough. Thanks in advance for any help you guys can give.

Frank
0 Kudos
Message 1 of 7
(5,702 Views)
I'm not sure there is a standardized way to do this (?)..

You could e.g. allow the window to grow at the start (if you are averaging with n previous measurements) or shrink at the end (if averaging with nect n measurements)...that way the number of elements stay the same.

if you average with the 4 previous the start then becomes (indexes of values averaged):

0
0,1
0,1,2
0,1,2,3
0,1,2,3,4
1,2,3,4,5
2,3,4,5,6
...

OR swap averaging direction when you start/come to the end...if e.g. you average with the 4 previous measurements you start by averaging like this:

0,1,2,3,4
0,1,2,3,4
0,1,2,3,4
0,1,2,3,4
0,1,2,3,4
1,2,3,4,5
2,3,4,5,6
....

Another option would be to wrap the array; averaging the start with the end.
0 Kudos
Message 2 of 7
(5,702 Views)
Find attached a sample vi. I'm sure there will be some other methods.
0 Kudos
Message 3 of 7
(5,701 Views)
Thanks, I have the moving average now working with one problem. The powers that be like it but are concerned that when viewing the plot, the obvious difference in data points plotted between the raw and avg'd data will be problematic. That being said, I am now trying to get the rotate array function to work in conjunction with the moving average routine. I have tried but I always end up with 20 empty elements ( the length of the moving average ) I have tried all I could think of. Any ideas???

Thanks
0 Kudos
Message 4 of 7
(5,701 Views)
Solving the problem of reduction in number of points can as I mentioned in an earlier answer be solved in a number of ways...you could pad the end or start with a repetition of the last whole window, or you can make the window gradually grow to its full size. The latter is illustrated in the attached VI...
0 Kudos
Message 5 of 7
(5,701 Views)
Also notice that adding the elements and dividing them by the known window size is much faster than using the mean function...
0 Kudos
Message 6 of 7
(5,701 Views)

Found this topic a while back, and came to the vi's posted here recently.

 

Is it possible to easily "pad" the output array in the first vi posted?  I think this would be easy to do, but I am having a problem figuring it out how to do that.  My input number may vary for division (averaging) (i.e. 5 or could be 3 or whatever).  I understand how to "pad" for a selected number I have, I'm just looking to have a fix in all possible numbers I guess.

 

I believe the first vi posted fits my needs a little better, hence why I am choosing to use that.

 

Thanks in advance for any advice or examples (LV 7.0).

 

 

 

Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 7 of 7
(5,083 Views)