10-22-2009 11:41 AM
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
10-22-2009 11:45 AM
10-22-2009 01:11 PM
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
10-23-2009 04:26 AM
Hi,
Anyone could help me to solve this problem?
Thanks
Senthil
10-23-2009 08:55 AM
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
10-23-2009 09:19 AM
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
10-23-2009 11:30 AM
Hi,
Anyone have ideas for solving my problem?
10-23-2009 03:30 PM
Hi all,
I still working on this problem could not able to resolve. Could anyone suggest me a solution?
Thanks in advance
Senthil
10-23-2009 03:43 PM
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
- 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!
10-23-2009 04:57 PM