LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to find data point closest to x axis or find x intercept of non linear curve

Hello. I have a simple problem and I would like to find the best way to solve it. I have a set of data points, which crosses the x axis. However, no data point has the exact y value of y=0. (this is measured data, so it is possible but unlikely that the value will be exactly 0.0000)  I would like to use Labview to find the data point that is closest to the x axis, and then output the x coordinate of that data point. The data point closest to the x axis may be positive or negative in y; it will vary each time. The data is already in Labview as an array of x values and an array of y values.

 

Alternatively, would it be possible to select two data points - the one right above the x axis and the one right below the x axis, draw a line between these two points, and extract the x intercept of that line? This would give a more accurate value.

 

 

Attached is an example of what the data looks like. Thank you in advance. I am using Labview 2011.

0 Kudos
Message 1 of 6
(4,756 Views)

I think this is the VI you are after. It requires you to have the full development system though.

 

Zeros and Extrema of f(x) VI

http://zone.ni.com/reference/en-XX/help/371361H-01/gmath/zeroes_and_extrema_of_fx/

 

hope that helps

 

Matt

Matthew Trott
Applications Engineer
National Instruments UK
www.ni.com/ask
Message 2 of 6
(4,725 Views)

A simple solution would be to take the absolute values of Y, then use "Array Min & Max" to find the minimum.

If the data would be non-descending you could also use "Threshold 1D array". This would give you a fractional index, but it's unlikely your measured data will always be non-descending.

 

Message 3 of 6
(4,719 Views)

Hi WillB123

 

This is how I would go about it. 

I would search the 1D Y-array for the y=0, if it exsist then use the index array function with the obtained index and extract the corresponding x value from the X-array.

In the case where the y=0 does not exsist I would check the Y-array for values less than 0 this will end in a boolean array of the same size search that 1D array for the first false entry that entry will be the closest positive value to the x-axis. Decrementing the index of the false entry by 1 will result in the closest negative value to the x-axis.

Determining which one of these values are the closest to the x-axis I take the absolute value of the negative value and check if it is less than or equal to the positive value in the case where they are equal I let the negative value rule.

Given the points on each side of the x-axis you can determine the function of the straight line using simple algebra. Once you obtain the function for the straight line you set y=0 and solve for x to get the intersection with the x-axis.

I think maybe an interpolation method would give a better result than a straight line in terms of approximating the x-axis intersection value but I do not know how accurate your solution has to be.

 

/Sletten

Message 4 of 6
(4,713 Views)

@Sletten wrote:

 

In the case where the y=0 does not exsist I would check the Y-array for values less than 0 this will end in a boolean array of the same size search that 1D array for the first false entry that entry will be the closest positive value to the x-axis. 

 


You're assuming here that the data is non-descending. As I mentioned in my last post in that case "Threshold 1D array" is a ready solution.

 

Message 5 of 6
(4,709 Views)

thanks all.

0 Kudos
Message 6 of 6
(4,687 Views)