LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Indexing problems

Solved!
Go to solution

I need to take an array and find the index values of where it changes from positive to negative. There will be two instances this happens, and I need to find the indices of these two events.

 

For context, the arrays will always follow the same behavior: starting positive, then dropping to negatives, returning to positive, and once again dropping to below zero where it will remain negative.

 

I'm thinking I need to nest a For Loop inside a While Loop conditioned to stop when the array value is less than or equal to 0 to get the first value, but finding the second index is where I am having trouble.

 

My only thought is to make a subarray with the index found in that nested loop (index1), then make a nested loop to see when it goes positive to find an index2-> subarray that, then nested loop to find the second time it drops below zero for index3.

 

My total number of values in the range I need would then be index2 + index3?

 

Please let me know if my description isn't clear and I can add a picture for more context.

I am wondering if I am complicating this process and would like to avoid loops with tens of thousands of iterations.

Even letting me know whether I am on the right track would be great - thanks in advance for the help!

0 Kudos
Message 1 of 7
(1,274 Views)

You can get it done a for loop pretty easily. Hopefully this will suffice until altenbach comes by with his zero loop solution 😄

 

The logic is that the conditional output terminal only outputs a value when the current value is negative, and the previous value is positive or zero.

 

Screenshot 2023-03-03 162113.png

Message 2 of 7
(1,272 Views)

Is this real-world data or is this algorithmically generated or otherwise 100% guaranteed to be clean data?

 

I'm asking because while the algorithm to detect sign changes isn't super hard, you may have edge in real-world cases where the data is close to zero, but then random noise makes it cross the zero line twice in quick succession, giving you bad calculations.

 

If this is real world data you might want to also consider adding a Hysteresis check.  This page has some diagrams showing what I mean:

https://www.ni.com/docs/en-US/bundle/labview-myrio-toolkit/page/myriohelp/myrio_hysteresis.html

 

Message 3 of 7
(1,266 Views)

@Kyle97330 wrote:

Is this real-world data or is this algorithmically generated or otherwise 100% guaranteed to be clean data?

 

I'm asking because while the algorithm to detect sign changes isn't super hard, you may have edge in real-world cases where the data is close to zero, but then random noise makes it cross the zero line twice in quick succession, giving you bad calculations.

 

If this is real world data you might want to also consider adding a Hysteresis check.  This page has some diagrams showing what I mean:

https://www.ni.com/docs/en-US/bundle/labview-myrio-toolkit/page/myriohelp/myrio_hysteresis.html

 


I recently ran into this issue where high frequency noise was causing exactly the hysteresis issue you are talking about.  We weren't expecting that much noise, so we had to increase the hysteresis value.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 4 of 7
(1,193 Views)

@UMBLaserLab wrote:

Please let me know if my description isn't clear and I can add a picture for more context.


No! pictures are pointless. If you like, attach your VI attempt and a typical datafile. What is the datatype (integer? DBL? Waveform? dynamic? etc.). How much noise is there?

 

Maybe all you need is something like zero crossing ptbypt.

 

Most likely, the real zero crossing is at a non-integer position. I would probably try to find the exact position using threshold array (example that you can modify to suit your needs).

Message 5 of 7
(1,172 Views)
Solution
Accepted by topic author UMBLaserLab

@altenbach wrote:
Maybe all you need is something like zero crossing ptbypt.

Here's how that could look like:

 

altenbach_1-1678036057189.png

 

 

 

 

Message 6 of 7
(1,169 Views)

Wow, I knew there would be something simple I was missing, and the PtByPt VIs were the key. Thanks for the replies, this was my first forum post and am impressed by the responsiveness of the LabView community. This is exactly what I needed, and thank you for pointing out the noise problem - something I didn't really think about. There is some noise in the minus-plus crossing, but luckily after review the indices I need will ALWAYS be the first and last plus-minus crossings - when before I assumed it would always be the first and second plus-minus crossing. I can just build an array of indices and use the first and final entries. The difference multiplied by my timestep is my total delta t.

Much appreciated!!

 

0 Kudos
Message 7 of 7
(1,125 Views)