From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need to average numbers

How can you make a running average of numbers.  I have tried using both  the mean and also the example that uses a while loop and registers.

 An example of what I am trying to do is a sine wave generator was set up and a random number from .001 to 1  generator was set up  to add to the incoming sine wave.  This has a wait until 250ms so that the wave dances up an down.  But the phase stays the same.  For example the peak goes up and down but the  x  location of the peak does not change.  I have picked off the top most data points and I would like to get the average of these changing y values   I thought making a wave from it and using mean would do it but it hasn't worked.  The mean changes with the new wave.  Any ideas

I have sent an attachment of something I have tried.

Thanks for any help
R Tucker
0 Kudos
Message 1 of 6
(2,392 Views)
your subVI aveme.vi is missing, please attach it too.
 
Your main VI makes little sense. You have a while loop without any purpose.
To get elements of an array, use "index array"! There is no need to first extract single-element subsets followed by "WDY get y value". 😉
Why is there no main while loop? Are you running this using continuous run mode?
0 Kudos
Message 2 of 6
(2,390 Views)
Here is the missing sub VI sorry
Thank you
Randall Tucker
0 Kudos
Message 3 of 6
(2,373 Views)
You need to remove all wires leading to the shift register on the left side of the FOR loop.  Only a VI with uninitialized shift register can retain history data between calls.

(With every call, you are currently  initializeing all shift registers with the same value and thus you only get current the input value back at each call)

You also need to set the loop count to 1. There is no need to run it 1000 times, it would actually again break the intended function).
 
Also: Since you are calling this VI in several locations, you need to make it reentrant, else you are mixing numbers from different data threads.

Message Edited by altenbach on 09-13-2005 01:11 PM

0 Kudos
Message 4 of 6
(2,371 Views)

Altenbach

Sorry for the confusion.

 

In the test system I am working on I have a stable wave that drifts very little.  Running in the continuous mode I need to measure the time from the start until I have a zero crossing on a wave. I would like to increase the accuracy of the time measurement over what is available on the board.

 

 The wave looks like a sine wave that a small amount of noise    The location of the peak remains in the same position in time but just moves up and down.  I thought I could "pick off" the data points on each side of the rough crossing.  Next, I would curve fit a line through a group of them to produce an equation of  the line y=m*x+b to find  zero crossing  to a greater accuracy than the card could support.  

 


This is why I am trying to average these points.  You may know a much better way.  I appreciate you help

 


Thanks

RTucker.

0 Kudos
Message 5 of 6
(2,359 Views)

Altenbach

I will remove all the wires leading to the shift register on the left side of the for loop.  I couldn’t figure why it wasn’t retaining the history.

 

I also will set the loop count to 1 so that it retains information and does not keep removing it.

How do I make the VI reentrant?  So I do not mix different data threads.

 

I appreciate your help.

 

RTucker.

0 Kudos
Message 6 of 6
(2,354 Views)