LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

zero crossing

I have made some changes to a bit of sample code posted here, which finds zero crossings of an input array. That code had some deficiencies which were at the time recognized, and others that had not been acknowledged that I've since found.

 

I have attached a VI this runs a few test cases, most of which fail with the original code. A few comments here serve to explain what I did, and open an interesting question or two:

1. If a zero crossing happens between the last two data points, the original code would not return a value. This is due to a peculiarity of the threshold 1-D array function, which returns the last index value if no zero crossing is found. This seems like strange beahavior, as other array search functions would return an index of -1 in such a case. However, because this functions can also take an array of x,y values as input (in which case it returns an interpolated Y value, rather than a fractional X index), it is unclear how else this might work. (There is no Y value that means "not found"). Anyway, the original code did not append the last-found value if its index (rounded up) was equal to the input array size.

2. The original code failed on any value of zero in the Y array, by entering an infinite loop.

3. The original code assumed the first value would not be zero and fails if it is (it was a known shortcoming).

4. I was not sure how to handle multiple consecutive zero values. Does each count as a zero crossing, or does only the first? I think only the first value counts, but struggled to find an elegant way to incorporate this, so the code now returns all zero values among the curve crossings.

5. The new version handles the case where the input array reaches, but does not cross zero, such as in (sin+1) at 270deg.

 

Enjoy!

 

_____________
Creator of the BundleMagic plugin for LabVIEW!
Download All
Message 1 of 4
(2,714 Views)

Good afternoon

While doing a research for an alternate solution to find all points where a function intersects the X-axis, came across the following VI:

http://www.ni.com/example/29206/en/

 

Please let me know if this example is helpful.

Puchkov

0 Kudos
Message 2 of 4
(2,657 Views)

Much thanks, littlesphaeroid!

 

I'm very new to LabView and was trying to write a VI that employs a zero crossing section in it.  I had borrowed a chunk of Altenbach's code - pretty good algorithm but had some known issues as has been pointed out.  I was tearing my hair out trying to reverse engineer it to understand how to fix some problems I was having - programming is not my forte, I'm more of a hardware guy - and your updated revision is excellent for my needs and saved me a lot of heartache and time.  I ran my signals and it performs perfectly!  I will still analyse it in more detail, but not under the same pressure!

0 Kudos
Message 3 of 4
(2,582 Views)

Very glad you found this useful. It took me quite a while to figure out all the test cases, but it seems pretty all purpose!

 

Click the Kudo button!

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 4 of 4
(2,558 Views)