LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Linear interpolation between two points

Hi...I have a problem.
I want to know the zero crossings of a sine.
I realize that I have a crossing for 0 when multiplying a sample to the sample after I get a negative value, i.e. when
 
                                                                                                                 x1*x2<0
I post an image.
But now I want to determine the exact crossing point,ie the point where the sine crosses the axis of time.
I think to solve the problem in this way: i calculate the straight line passing through the two points, x1 and x2 and then i determine the intersection of this straight line with the axis of time.
I do not know how to implement this in Labview.
Can somebody help me?
 
0 Kudos
Message 1 of 6
(6,182 Views)
You could do a linear fit from the mathematics pallete.  Feed in a 1-D array of 2-elements for Y and a 1-D array of 2-elements for X.  But feed the X array into Y and the Y array into X so that when you get the intercept, it will give you the intercept of the X axis.
0 Kudos
Message 2 of 6
(6,161 Views)

Dear Pietro,

Actually you can simply compute it.
Let's do some math together.

Following your picture you can say.

x2=x1+m*dt where dt is 1/sample_rate

0=x1+m*tau where tau si what you are looking for.

It's quite simple to get

m=(x2-x1)/dt Plese note in your example m<0

tau= -x1/m   Plese note, since x1>0 and m<0   tau >0 as expected.
You can further simplify it in tau=-dt*(x1/(x2-x1)) in this last equation everything is known.

Best regards.

 

 

FiloP
It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong.
Richard P. Feynman
0 Kudos
Message 3 of 6
(6,123 Views)
If your data is noisy, use the linear fit with several points on each side of the zero. This will smooth or average the noise, possibly giving a better result. Using just two points leaves the calculation vulnerable to errors if one (or both) of the points is not on the sine curve due to noise.

Lynn
0 Kudos
Message 4 of 6
(6,106 Views)
Another suggestion,

once you get the linear fit working as suggested, paste some of the data points into Excel and use the intercept() function to verify the answer you get from LabVIEW is the correct one!
(Note: be careful over what data range you take your estimation, as a sine wave is only 1:1 linear for small angles (i.e. sin(alpha)  approx= alpha )
0 Kudos
Message 5 of 6
(6,100 Views)


@pietrovl1 wrote:
But now I want to determine the exact crossing point,ie the point where the sine crosses the axis of time.

Well, linear interpolation will not give you any "exact" crossing point (your words!), especially if you have limited samples per period, because a sine is NOT a straight line. 😉 If you only have a single frequency in your data, you could just try to determine the phase of it, e.g. with a Fourier transform. This will give you all zero crossings at once with a little math. ;).

Can you attach a small sample VI containing typical data?

0 Kudos
Message 6 of 6
(6,084 Views)