LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine change in slope

Attached is a chart which shows postition vs. time of a moving object detected by a laser displacement sensor. As you can see in the chart, the position has a sudden change in slope at a given point in time. I want to get the exact position (NOT time) at which there a sharp rise in the slope occurs.

 

What method can I use to get this exact position at which the sharp change in slope occurs?

 

The laser displacement sensor has a VI which takes 100 samples at 10kHz rate. The samples are averaged to get the positon. See attached example of the laser sensor vi.

 

I have general idea on how to approach this, however, I just wanted to understand the best practice in LabView. Woud determining at which position the 2nd dereviative is the maximum be the best approach? Also, because the sensor is noisy, how would I address the noise that would show up in the 2nd derevitave? Also, would I have to store the position vs. time data in an arrray first then calcullate the derevitative?

 

slope-change.png

laservi.png

0 Kudos
Message 1 of 8
(5,629 Views)

You are asking the right kinds of questions.

 

The second derivative is a useful tool for finding sudden changes in slope, but, as you are aware, noise can become an issue. Look at the Savitsky-Golay filter. It can be used to calculate derivatives with much less noise than the direct approach would give. Essentially it fits a polynomial to a segment of the data and then determines the derivatives from the coefficients of the polynomial.

 

You do need to accumulate the data into an array.  There are several ways to do this. The choice depends on how big the arrays will be, how much latency you can tolerate between the data acquisition and the analysis, and what else you may need to do with the data.

 

Possibly the simplest approach would be to use a property node for the chart to get the history data. That is an array automatically accumulated by the chart. The default length is 1024.  This can be changed from the pop-up menu for the chart.

 

You do not show a loop in your code image. Any program whihc does things repetitively should be enclosed in a loop. Do not use the Run Continuously button on the toolbar. That is there only for certain kinds of troubleshooting.  In a program like yours running that way may cause the express VI to configure and shut down the connection to the laser on every operation. This can be slow and inefficient and could even result in problems with the hardware.

 

Lynn

Message 2 of 8
(5,614 Views)

johnsold,

 

Thanks for the reply. Below is my block diagram for getting the 2nd derivative. However, I have further questions.

 

I am really unsure how to go about building the array that stores the postioin and 2nd derivative data. Even after building the array, how do I go about getting the exact position at which the sharp change in slope occurs?

 

In my program, the object starts moving down during a specfic state. When it is moving down, it may have different velocity throughout this state (as you can see in the uploaded diagram). However, I am only interested in the exact position which has a sharp change in veloclity.

 

 

derivative.png

slope-change.png

0 Kudos
Message 3 of 8
(5,582 Views)

I would suggest building an array with the second derivative data and using the Array Max/Min function to find the minimum value of the second derivative, or the highest negative rate of change of the slope. You can use the index of this element to index the position array and determine what position matches the location of the highest negative rate of change of the slope. I would also suggest taking the chart history through a property node, as this is the easiest method to retrieve that data.

0 Kudos
Message 4 of 8
(5,540 Views)

I implemented the suggested methods to determine at which position the sharp change in slope occurs. Manuliplating the array data and grabbing the most negative 2nd derivative was easier than I though. 

 

Now the issue is that the position at which the 2nd derivative is the most negative is inccorect. The calcuated postition is slightly delayed. See the images below. The yellow line is the position vs. time. The white line is the 2nd derivative vs. time. The logic behind the program I built works. It does give me the postition at the most negative 2nd derivative peak. However, it seems that the most negative 2nd derivative peak is occuring slightly delayed. 

 

What am I doing wrong? Should I be calculating the 3rd derivative instead? 

 

issue-delayed-accel.png

issue-delayed-accel-zoom.png

issue-delayed-accel-block.png

0 Kudos
Message 5 of 8
(5,512 Views)

isn't it delayed by the filtering? I think that applying a filter would move the peaks by a few points. What happens if you remove the S-G filter?

__________________
Engage! using LV2015
0 Kudos
Message 6 of 8
(5,490 Views)

please post a vi including one of your datasets (by making them default and sve the vi) or create a constant of your data copy it to a vi and post this...

 

that way we can try our ideas and post them 🙂

 

the S-G filter can do the diff    here I posted my version, try ty 10 sidepoints , 3 order and 2 diff 🙂

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 7 of 8
(5,479 Views)

I ended up fixing the delay.

 

I am storing the position and second derivative in an array. The peek of the second derivative will be delayed by 2 cycles relative to the position data in the array. The initial data point gives the position. In the next cycle, the velocity is calculated. The 2nd cycle, the derivative is calculated.

0 Kudos
Message 8 of 8
(5,329 Views)