LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Averaging

Dear Members,
   I am using Labview 8.2 version and a newbie to Labview programming.  I am developing a sub-vi for averaging a data output of a
signal.  DAQ rate is every 10 sec.  I need to develop a sub vi which will average cumulatively all data till first 20 min duration from start of program
i.e.., X1+X2/2, X1+X2+X3/3...X1+...X20min/n. After 20 min I need to calculate difference between current data value and average of
all data values till last 20 min duration. Suppose if X21 is current value at 21 min, I need calculate difference as X21 - [ (X20+....X1)/no of values].
say for 22 min, X22 - [ (X20+....X2)/no of values].  Hence I need only average of latest 20 min duration values omitting the current value and get deducted from current value.
I attached the developed sub-VI here.  The problem is if I initialize the shift register with zero array, each time sub-VI calls it while execution and I could not get
previous values. If I do not initialize it adds up current value to previous values of past experiments too and array size was too big.
Is there any simple solution to overcome this difficulty and also I wish the array buildup could not dump CPU memory.

Thanks

Senthil

Download All
0 Kudos
Message 1 of 15
(3,628 Views)
you may be able to use the elapsed Time express vi to do this.
Harold Timmis
htimmis@fit.edu
Orlando,Fl
*Kudos always welcome:)
0 Kudos
Message 2 of 15
(3,624 Views)

Hi Harold,

  Thanks for the reply. Could you able to explain it with my attached VI version? I have used case structure to switch over after expiry of 20 min duration.

 

Senthil

 

 

0 Kudos
Message 3 of 15
(3,592 Views)

Hi,

  Anyone could help me to solve this problem?

 

Thanks

 

Senthil

0 Kudos
Message 4 of 15
(3,555 Views)

Hello, Senthil

Are you sure that you need all the values in the array? For if not, there is one easy way out:

 

Iteration  Current value Average                the Delta you want to know

0           0            0 

1          X1            X1 = A1                X1 - 0

2          X2            (X1 + X2)/2 = A2       A1 - X2

3          X3            (A2*2 + X3)/3 = A3     A2 - X3

4          X4            (A3 *3+ X4)/4 = A4     A3 - X4

and so on.

 

The numbers behind the A is only for clarification. Don't mistake it as an index to an array. 

No matter how many iterations run, you will always get one value in A that is the correct (artihmetic) average over the last n-1 values.

The one double variable A needs to be initialized with 0. 

I did not vi-ize this, but I'll do that if you need that .

Regards

Michael 

 

0 Kudos
Message 5 of 15
(3,546 Views)

Hi Michael,

  Thanks for your response. I wish to do only cumulative average i.e. (X1+X2)/2, (X1+X2+X3)/3 (0r) A2+X3/3. Hence I used a 'for loop' with a shift register in VI (see attachment on my previous post). The program need to run in this mode till first 20 min after start time. After that I need sort out current value sepeartely and cumulative average of all data points those logged 20 min before the current value. Say the current value is on 30 min, I need to do cumulative avaerage of all data points at correspondings instants of 29 min to 9 min. Datapoints of 0 - 8 min need to be untouched. This need to go on still I stop the program taking average of 20 min data accordingly.

 

My problem is

 

(1) I dont know my developed VI is good enough (or) simple to perform my above requirement. I need useful sugggestions to modify it.

 

(2) I tried executing my VI and I observed that shift register is getting initialised to zero at each execution. So I will be losing all the previous data.

    If I do not iniitialize it I am getting old datas appended from previous experimental runs. So I can't get real average for current experiment.

 

Regards,
Senthil

 

0 Kudos
Message 6 of 15
(3,539 Views)

Hi,

 Anyone have ideas for solving my problem?

0 Kudos
Message 7 of 15
(3,519 Views)

Hi all,

  I still working on this problem could not able to resolve. Could anyone suggest me a solution?

 

Thanks in advance

 

Senthil

0 Kudos
Message 8 of 15
(3,511 Views)

Hi Senthil,

 

why do you bump yourt thread again and again? You were already told how to solve your problem by Michael in message 5…

 

Some notes on your attachment from message 1:

- please use AutoCleanup (the brush in the block panel menu) before posting Smiley Wink

- why do you use a FOR loop set to run only once? The only reason I see is the shift register - use a feedback node instead!

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 15
(3,507 Views)

edited after timeout:

-Why do you use that second shiftregister, that only keeps the same value as the iteration count???

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 15
(3,496 Views)