Quantcast
Channel: LabVIEW topics
Viewing all articles
Browse latest Browse all 66657

zero crossing

$
0
0

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!

 


Viewing all articles
Browse latest Browse all 66657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>