From 11:00 PM CST Friday, Feb 14th - 6:30 PM CST Saturday, Feb 15th, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Spotting peaks and flat areas

I have an interesting problem, we are getting a farly accurate outlines from one of our machines that measures displacement on both sides of a sample,  We know that there are 3 peaks on each side of the sample and need to measure the width between the peaks, however the samples are are not guaranteed to enter straight or have consistent lengths.

On most samples it is pretty easy to distinguish the peaks so you can work backwards from there to find the widths using pythagoras to find accurate widths between peaks, however ~10% of the samples have very indistinct peaks which is causing an issue, with calculating the widths. The attached plot 1 is the ideal that we get similar to most of the time, however the sample in plot 2 is representative of the problematic ones. 


undefined


undefined


As you can see on plot 2 the middle peak of the right hand side is not actually a peak and so won't be found, does anyone have any suggestions for how to detect the flat region/psuedo-peak that is there. I have tried using a combination of the derivatives where any zero crossing of the first derivative is checked against the relevant second derivative value and if it is negative then the point is flagged as peak, but that only just improves upon using the LV built in peak detector.

 

Any suggestions are gladly appreciated.

 

Download All
0 Kudos
Message 1 of 4
(2,929 Views)

Hi,

 

A few suggestions:

1. Use thresholding on the first derivative to find the flatter area. In the flat area the first derivative should be a small number because the plot is almost flat. On both sides there is a jump of high value. Using a set of your data you could empirically find this threshold. You can perhaps add second derivative data to this to find areas where the first derivative changes slowly, depends on your data.

2. It's a horrible method I know, but in cases where your automated algorithm can't find the peak, ask the user to choose it for you via a mouse click or cursor.

 

Good luck,

Danielle

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
0 Kudos
Message 2 of 4
(2,901 Views)

The peak search function (which also can search valleys 🙂 ) with a coarse point length of 2/3 of the periode (or try 1/2) should do the job.

Read the help about this function, it applies a quadratic fit to find the peak .....

 

If you post a vi including the data (make current values default)  I shure you get better answers 😄

(No need to post the aquisition vis just copy the indicators with data into a new vi, make current (or all) values default , will do the job 😉

 

in hard cases try the derivate .... (I would use the Savatzky-Golay filter I posted here ... less prone to noise)

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 3 of 4
(2,894 Views)

Just in case anyone is wondering, I did eventually come up with a solution to my problem, rather then looking for the areas that looked like peaks using the human eye (a tool that is nearly impossible to replicate in code) I went along the approximation route after noting that when examining the measurements if we were missing a peak we were usally only missing a single position.

 

By finding the position of all of the other peaks, putting the peaks into 3 pairs and finding the averaged offset of the completed pairs it was possible to generate an average offset between the paired points, using the known peak of the pair it was the a matter of applying the offset to find an estimated peak location. 

 

So far it seems to be working reasonably well although if it ever comes up against a pair of missing peaks I am not sure how it will handle it.

 

 

0 Kudos
Message 4 of 4
(2,844 Views)