LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I create an n-point running average VI?

Ok. I should have examined your VI more closely before posting. Ahhh yes, good call on not reinitializing those 128 points every call of the loop. For some reason having everything visual to me is making it hard to relate to what is going on pragmatically. I think I got it though. Defiantly should have come on the forums a lot earlier rather then twiddling my thumbs for the past few months :S . heh.
0 Kudos
Message 11 of 17
(6,391 Views)
Also don't forget that sometimes there is an express VI that does basically what you want (=smoothing). Just double-click it and select moving average with a rectangular window.
 
Of course you have a great selection of other filters, too.
Message 12 of 17
(6,384 Views)

I re-invented this wheel.  Mine only works on an array as a whole, and gives a centered moving average output.  By centered, I mean that A[i] out = average(A[i - N/2], A[i - N/2 + 1], ... , A[i + N/2 - 1], A[i + N/2]), where N is the number of points to average.  I couldn't figure out how to make the Express VI change its value of N programatically, so I'm using this one I wrote.

Labview 8.5

 

0 Kudos
Message 13 of 17
(5,990 Views)

I used NI's "Mean PtByPt.vi" for this purpose, but like all the other solutions you have to split multichannel data and you need an instance of the VI for every channel. You cannot use a For Loop for reentrant VIs, so the diagram will expand for every additional channel. I took the "N_Point_Running_AverageMOD.vi" and modified it to handle arrays of input data. So one single VI for all channels. I considered adapting "Mean PtByPt" to using arrays but found out that NI does the calculation of the mean value inside the VI without using "Mean.vi". Maybe it is a bit more effective this way. But to adapt to other functions like e.g.. Standard deviation it would be necessary to edit the corresponding PtByPt VI, while with the attached VI you only have to change to the correspondent VI from the Statistics palette.

0 Kudos
Message 14 of 17
(5,743 Views)

Here is a vi that implements a number of smoothing options, moving average being one of them.  A lossy queue is used to store the data.

0 Kudos
Message 15 of 17
(5,730 Views)

My jaw almost dropped to the ground when I saw Nickerbocker ask the question "How do I create an n-point running average VI?" What?! I've learned some really cool stuff from this guy in the past two years! What's he doing asking questions like this?!

 

Then I saw the original date. Sometimes necroposting is funny. Smiley Very Happy

Message 16 of 17
(5,713 Views)

Since one of my ancient posts above got kudoed recently, I want to make sure to mention that for a simple running average, the array does not need to be rotated. All we need is replace the oldest element in the fixed-size buffer. See also other, even more efficient alternatives mentioned in my presentation.

 

An "average" does not care about the order of elements, but other ptbypt algorithms of course might.

 

0 Kudos
Message 17 of 17
(2,539 Views)