Jump to content

Detect straight lines & their angle on a waveform


Ano Ano

Recommended Posts

Thank you for your prompt reply!

I created a curve (see attached file) that is made from a straight inclined line (0-190) a curve (190-812), another inclined straight line 813-987) and a third inclined straight line (988-1000). I made an effort and managed to locate when the slope changes but how can I tell which is the curved and which is the straight part of the plot? The second derivative does not show something useful.

Thank you in advance

 

Second derivative 2.vi

Differentiator and Smoother.2.vi

Savitsky-Golay Differentiator Core.vi

Edited by Ano Ano
Uploaded missing vi's
Link to comment

Your VI is missing a subVI so I cannot run it, but you will likely need to use the two derivatives together.  The zero crossings of the second derivative will give you the points of inflection as ShaunR pointed out.  Use these locations/indices to reference points on the original function and the first derivative.  You can likely filter out your segments by looking at the first derivative values and determine which points of inflection are important or are on your curved segement.  The value of the first derivative at that point will give you your slope for the tangent line.

Edited by Jordan Kuehn
Link to comment

Somewhere you will have to create threshold and you will have to decide what is strait for what you are doing. We can draw a line on the ground and have everyone agree that it is a strait line. However the Earth is a sphere, so the surface is curved therefore any line drawn on the ground cannot be strait. The line is therefore strait and not strait depending on your frame of reference.

Using the built-in derivative function may give you too much noise. You may have better luck using taking the slope of points some number of samples from each other. This works better for the sensor data I get.

Link to comment
1 hour ago, Tim_S said:

Somewhere you will have to create threshold and you will have to decide what is strait for what you are doing. We can draw a line on the ground and have everyone agree that it is a strait line. However the Earth is a sphere, so the surface is curved therefore any line drawn on the ground cannot be strait. The line is therefore strait and not strait depending on your frame of reference.

Using the built-in derivative function may give you too much noise. You may have better luck using taking the slope of points some number of samples from each other. This works better for the sensor data I get.

You don't need to threshold/ An inflection point is a change in sign of the d2y/d2t from positive to negative or negative to positive. Since you only need two points to draw a line, Just find the two points either side of the inflection (where they change sign) and draw your line through them.If you need a better estimate because your datapoints are a bit sparse then you can do a linear fit on a few points on either side of it.

Lets see who can come up with a "cool" way of detecting sign changes and extracting the points to fit :D

Edited by ShaunR
Link to comment

A very good way to take an N-order derivative of a noisy signal is the Savitski-Golay filter, which is in LabVIEW. Read up on it, you will see it is much better than the naive method of taking the derivative (the simple forward, backward, and central approximations)

  • Like 1
Link to comment
4 hours ago, ShaunR said:

You don't need to threshold/ An inflection point is a change in sign of the d2y/d2t from positive to negative or negative to positive.

With perfect data I would agree. With real-world data, not so much. I've had too many cases where the SNR is 3:1 for what trying to measure and all that little electrical noise creates inflection points even after running through filtering. (Had to explain that cheap sensors are not the place to save money on and bubblegum is not a good medium for splicing signal cables.)

5 hours ago, ShaunR said:

Lets see who can come up with a "cool" way of detecting sign changes and extracting the points to fit :D

Got some data in mind?

 

5 minutes ago, MarkCG said:

A very good way to take an N-order derivative of a noisy signal is the Savitski-Golay filter, which is in LabVIEW. Read up on it, you will see it is much better than the naive method of taking the derivative (the simple forward, backward, and central approximations)

I'll have to take a look at that. I've used a moving average filter with good success, which (quickly reading Wikipedia) looks to be a specialized case.

Link to comment
11 hours ago, MarkCG said:

A very good way to take an N-order derivative of a noisy signal is the Savitski-Golay filter, which is in LabVIEW. Read up on it, you will see it is much better than the naive method of taking the derivative (the simple forward, backward, and central approximations)

I can also recommend Savitski-Golay, which is basically just fitting to a Nth-order polynomial, and estimates multiple derivatives at once.  Apply some “straight-line” criteria such as all derivatives beyond the first being “small”.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.