LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect peaks on a curve

Solved!
Go to solution
Solution
Accepted by topic author edmonton

@edmonton wrote:

Hi Henric,

 

Thank you for your kindly helps.

I have been using Labview since version 6.0, however, I just used it occasional when a project required, so I am not a very experienced user. Could you please help me to understand your way of solving my problem. I searched NI web for  related info, however, still need further learning from you. I post part of your code here for a reference.

 

edmonton_0-1611166047286.png

 

 

1.  On the right edge of the for loop, you bundled auto-index with a Boolean (peak found?). How were the two parameters bundled together, how the bundle pass values during iteration?

rigth click on the loop output and you can choose different options how the output behave. RTFH

 

2. You used the same value for the first order derivative's inputs (x and initial condition), Could you please explain the idea behand it?

avoiding the initial peak, since the fisrt real value is different to 0. reading help helps 😉

 

3. You used peak search offset, the reason and how  the value -20 was chosen?

linke the pulse search width ... choosen by looking at your data. to have some points before the pulse starts...

 

I make a correction here as I mentioned that you used an array for loop iteration N, I noticed that it was my mistake. The array index was just behand the N, I moved the index down a bit to separate them.   

 

As I said Q&D 😄

 

Best regards,

Gu

 

 


 

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 ǝɥʇ'


Message 11 of 20
(1,420 Views)

Hi Henric,

 

I have learnt a lot from your codes. 

I am just wondering if there is a way to separate the peaks from the raw curve so that the raw curve doesn't show up the peaks or display three curves: raw with peaks, peaks, raw without peaks. I played around using lowpass filter, but could not get it.

 

Regards,

Gu

 

0 Kudos
Message 12 of 20
(1,404 Views)
Solution
Accepted by topic author edmonton

here is a first step:

 

I used the 1. derivative since it's about the same as a 1. order highpass 😉

Based on the asumption, that you can make an educated guess about the pulse length (15 samples)

sitting on your baseline (raw without peaks) ,

after the first peak detection based on derivative and half the pulselength , make a second peak search on the raw data (at least half pulse lengths samples later, you have a good guess for the peak value and a good threshold would be the half between the raw data at peak index and index - (pulselength/2) )

Now you have a good guess of the center of the peak. take the first and the last value (+ and - half peaklength)  replace it with a line ( see my code) and subtract it. Result is the pure pulse (in my example the length is 4 times the pulse length ) ..

That pulse can be substracted from the raw data ... 

 

Now it's your homework 😄

 

Peak detection mod 3.vi.png

 

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 ǝɥʇ'


Message 13 of 20
(1,396 Views)

Here's a method that just uses the raw data and compares adjacent points. 

It seems to work well with your data, though it isn't perfect in all situations.

 

20210121_Peak_detection_mod_3_cds.png

 

 

Craig

Message 14 of 20
(1,386 Views)

Hi Henric,

 

It is a good way of doing it. I did the homework and got raw curve excluding peaks. 

 

Thank you again!!! your sample codes are really helpful to me.

 

Gu

0 Kudos
Message 15 of 20
(1,376 Views)

Hi  Cstorey,

 

Could I trouble you to convert the vi into Labviw 2015 and upload it again as my one can not open the files of newer versions.

 

Thanks, 

Gu 

 

0 Kudos
Message 16 of 20
(1,374 Views)
Solution
Accepted by topic author edmonton

Here's the code saved for version 2015. (compressed with 7zip)

Craig

Message 17 of 20
(1,366 Views)

Hi Craig,

 

It requires XY array input and is good for post data processing.

I need live stream processing point by point. I am not sure if I can convert it to a point-by-point VI. Of course, I can create a rolling array with a specified length, e.g. 50,  and then feed it to the VI. 

 

Thank you for your nice help!

Gu

0 Kudos
Message 18 of 20
(1,356 Views)

Hi Henric,

 

I obtained raw curve with and without peaks following your ideal. However,  I ran into a new issue when I combine the ramp pattern with the live stream peak detection. Could I trouble you again to help me with the issue?

 

The point-by-point peak detector VI outputs a "True" when a peak is found. I realize that it stops at the center of each peak rather than at the end of each full peak.  I found it by change the for loop to a conditional loop and set the loop to stop when the first peak is found.  

 

The problem is that the ramp pattern VI can not work properly. The ramp includes the first half peak rather than its base. I played around for 2 days and was not able to solve it.

 

I would like the live data to run some more points so that the second half peak can be included plus a extended base. Assuming a peak has 20 points in the center, 10 points front base and 10 point post base, totaling 40 points for a whole peak. I would like the peak detector to output a "true" when the running data to reach the last point of the 40 points, then the 40 data points can be used for ramp pattern. The Raw data without peaks can be obtained by replacing the raw data with the ramp pattern VI's output.    

 

Here below included is my code. 

 

Best regards,

Gu

edmonton_0-1611440662754.png

 

0 Kudos
Message 19 of 20
(1,337 Views)

Hi There,

 

I just solved the problem.  Please ignore the previous post. 

 

Best regards,

Gu

 

 

0 Kudos
Message 20 of 20
(1,322 Views)