LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement running average

I'm a new Labview user and am blocked by what seems like a very simple
problem.

I want to do some data smoothing using a running average, and need to be
able to set the number of points to smooth from the panel. All the
examples I've found use shift registers, and thus the number of samples
is fixed by the number of stages programmed in the shift register. We may
also want to smooth over large numbers of data points.

What is an efficient way of doing this? Most of the simple ideas I've had
seem to run into cyclical problems.

Thanks,
Ned Simmons
0 Kudos
Message 1 of 5
(3,444 Views)
ned--
(from one LabVIEW newbie to another)
Perhaps if the data collection portion of your program were set within
a WHILE loop? I figured out an averaging method within a WHILE by simply
passing the previous iteration output value (initialized at zero) into
an addition function which included the present loop data value, and
then divided by the iteration value plus one. (n+1). the running sum of
all data values is also passed to the next loop iteration. Hope this
helps!
These early stages of learning LabVIEW have been perplexing for me at
times, too. Best of luck!

-Will Slade
Univ. of Minnesota, M.E.


Sent via Deja.com http://www.deja.com/
Before you buy.
0 Kudos
Message 2 of 5
(3,444 Views)
Hi Ned

To make a variable length running average you basically have to create a FIFO stack (or queue) and then sum all the elements in
the FIFO and divide by the length. The storage place for the array will be a register in a while loop. There are two ways to
implement a FIFO stack, the first is to shift the data in the stack and add data at the top, and the second is to use a pointer to
which increments down the stack until it gets to the bottom and then starts at the top again.

I have implemented both schemes. The data shift method is the most elegant but slowest (4.7uS/value). The pointer method is more
complicated but twice as fast (2.2uS/value). Both are written in pure G.

I've attached two examples that I have created. They have been sav
ed too LV 5.0 for the people who don't have LV 5.1.

Tim

PS the numbers were measured on win95, Celeron 300MHz, 32Mb Machine.
Doing a 5 point running average on 2^16 values.

Ned Simmons wrote:

> I'm a new Labview user and am blocked by what seems like a very simple
> problem.
>
> I want to do some data smoothing using a running average, and need to be
> able to set the number of points to smooth from the panel. All the
> examples I've found use shift registers, and thus the number of samples
> is fixed by the number of stages programmed in the shift register. We may
> also want to smooth over large numbers of data points.
>
> What is an efficient way of doing this? Most of the simple ideas I've had
> seem to run into cyclical problems.
>
> Thanks,
> Ned Simmons
>
>
Download All
Message 3 of 5
(3,444 Views)
The best way is to take your running average multiply by (Running average-1)
then add your current value and devide the whole thing by your running average...RAnew
= [RAold*(N-1)+new]/N. This way you can dynamically change you running average
size and not have to do any array manipulation. Obviously the running average
is only valid after a number of points have been taken equal to N. The same
is true after a change in N occurs.

neds@javanet.com (Ned Simmons) wrote:
>I'm a new Labview user and am blocked by what seems like a very simple >problem.>>I
want to do some data smoothing using a running average, and need to be >able
to set the number of points to smooth from the panel. All the >examples I've
found use shift registers, and thus the number of samples >is fixe
d by the
number of stages programmed in the shift register. We may >also want to smooth
over large numbers of data points.>>What is an efficient way of doing this?
Most of the simple ideas I've had >seem to run into cyclical problems.>>Thanks,>Ned
Simmons>>>>
0 Kudos
Message 4 of 5
(3,444 Views)
I am sorry to be replying so late, but I was away from the office for a bit.

The formula [RAold*(N-1)+new]/N will not give you a running average. For
example, say your block size (N) is 5 and your first 5 values are 1, 100,
100, 100, 100. The first valid running average value (RA) is 80.2. In a
true running average, the "bad" first point will drop off in the next
interation. If the next value (new) is also 100, then the true running
average is now 100. If you use the formula given, the value would be 84.16;
which is wrong.

I would recommend one of the VIs that Mr. Streeter submitted.

I hope that this helps,
Bob Young


"Jim Kring" wrote in message
news:395bcbf4@newsgroups.ni.com...
>
> The best way is to take your running average mul
tiply by (Running
average-1)
> then add your current value and devide the whole thing by your running
average...RAnew
> = [RAold*(N-1)+new]/N. This way you can dynamically change you running
average
> size and not have to do any array manipulation. Obviously the running
average
> is only valid after a number of points have been taken equal to N. The
same
> is true after a change in N occurs.
>
> neds@javanet.com (Ned Simmons) wrote:
> >I'm a new Labview user and am blocked by what seems like a very simple
>problem.>>I
> want to do some data smoothing using a running average, and need to be
>able
> to set the number of points to smooth from the panel. All the >examples
I've
> found use shift registers, and thus the number of samples >is fixed by the
> number of stages programmed in the shift register. We may >also want to
smooth
> over large numbers of data points.>>What is an efficient way of doing
this?
> Most of the simple ideas I've had >seem to run into cyclical
problems.>>Thank
s,>Ned
> Simmons>>>>
0 Kudos
Message 5 of 5
(3,444 Views)