LabVIEW

cancel
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
(1,327 Views)

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.)

0 Kudos
Message 12 of 20
(1,322 Views)

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

0 Kudos
Message 13 of 20
(1,320 Views)

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!

0 Kudos
Message 14 of 20
(1,317 Views)

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
(1,309 Views)

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
(1,303 Views)

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
(1,299 Views)

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

0 Kudos
Message 18 of 20
(1,297 Views)

Also don't forget about the conditional tunnel.

0 Kudos
Message 19 of 20
(1,286 Views)

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
(1,271 Views)