Showing results for 
Search instead for 
Did you mean: 

Array processing

In the attached file, I need to detect a threshold around 0.5 in both signals then find the difference time between in all happening time in which threshold is met. In the example, two points are such as that. One of them is around the 10s and the other is around 130s. But my code detects just the last one (around 130s).

0 Kudos
Message 11 of 20

After looking at your code for five seconds, it is peppered with race conditions and your results are unpredictable. In the second frame, the local variables is read way before the indicator gets updated with new values, because the inner FOR loops and the case structure execute in parallel.


As for the task, I am sure you could do it with 5% of the current code using a single loop. Try it.


(Your first inner FOR loops do absolutely nothing. What is their purpose? Your second FOR loops are pretty pointless. You need to iterate n-1 times, because else you run out of elements in the last iteration. Index array is resizeable, you only need once instance. There is the "in range and coerce function", try it). Your indicators get updated as many times as the boolean turns true and only the last value is available after the loops complete. Your sequence structure serves no purpose. Why is there an outer while loop? You are spinning it as fast as the computer allowws, recalculating the same over and over, burning 100% of a CPU code yielding nothing new ever.)

LabVIEW Champion. It all comes together in GCentral GCentral
0 Kudos
Message 12 of 20

I changed it but it does not work. You can see in the attached file.

0 Kudos
Message 13 of 20

Read the rest of my message above. Now you placed it inside the FOR loop, but there is sitll no way to tell if the local variable gets read before or after its indicator gets updated. Again, all you see at the end is the last update from some random calculation. Think dataflow!


You need to get rid of the local variables!

LabVIEW Champion. It all comes together in GCentral GCentral
0 Kudos
Message 14 of 20

There is also a function called threshold detector which will do mcuh of what the For Loops in the 2nd frame are doing.

0 Kudos
Message 15 of 20

Thank you for your help. I think it works now but I am so eager to make it better. How is that now? 


0 Kudos
Message 16 of 20

A bit better.  But can still be improved based on Altenbach's comments and mine.


I cleaned up your code.


But it looks like your code can be replaced by the Threshold Detector.  Two subVI's Done!

0 Kudos
Message 17 of 20

Thanks. But why Threshold Detector gives index one number less than my program? My code is still wrong?

0 Kudos
Message 18 of 20

Also don't forget about the conditional tunnel.

LabVIEW Champion. It all comes together in GCentral GCentral
0 Kudos
Message 19 of 20

Your code is wrong.  You started out with i=0 in the first iteration  and compared i with i-1.  When i is 0, i-1 = -1.  There is no such thing as an array index of -1. 


So working in the loop, you need to start at 0 and look ahead to i+1.   When true, the code is returning i.

The Threshold detector is probably set up to (can't tell, the algorithm is hidden in a dll), to give the first index that is after the crossing.


To make them give identical results, you can easily do a +1 on the array of indices.

0 Kudos
Message 20 of 20