LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

relative min and max of xy-graph

Hello,

I am really stuck and I need some help solving this issue.

I have different graphs and I need to find the relative minimum and maximum for further calculations in my program.

With some data, it is quite easy because the absolute and relative points are identical, but not always.

 

So far the user needs to manually interfere to get correct values with the difficult data.

Does anyone have a solution on how to always find the relative minimum and maximum points of the graph automatically?

 

I tried some weird calculations but none of them worked for all cases.

 

I attached a sample vi.

(the graphs will always be different but I think they won´t get worse than the second one)

 

Best regards

Manuel

Download All
0 Kudos
Message 1 of 8
(1,766 Views)

Hi Manuel,

 

What about searching for sign changes in the derivation of your signal?

This way you can find relative min/max points. Once you know all relative min/max points you can easily filter for the interesting ones…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(1,762 Views)

Peak detector with well, tuned inputs should do what you need.

 

Does the sloping "background" have a mathematical description? Maybe it can be subtracted first.

 

What else do you know about the datasets? Is there exactly one local minimum and local maximum or could there be more than one each?

 

(Be aware that solutions that depend on derivatives are quite sensitive to noise and might require filtering.)

0 Kudos
Message 3 of 8
(1,720 Views)

I have done a similar task using cursors. The user drags a cursor near the peak, and when they let go the program tries to snap to the nearest local peak. When the plot cursor was released, I looked at something like 20% of the displayed plot and found the min or max within that window.

0 Kudos
Message 4 of 8
(1,718 Views)

Since your new and improved algorithm needs to work an all three datasets, the first thing would be to eliminate all that duplicate code, e.g. as follows. Now all you need to do is change one small code section and immediately test it on all inputs. Having to do the same changes in three different places is error prone and tedious.

 

 

altenbach_1-1615403532489.png

 

 

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

Thanks for the replies.

 

I tried searching for sign changes in the derivation of the signal. But because I don´t have a mathematical description of the signal I have trouble filtering the right points.

 

The Peak detector doesn´t give me reliable peaks and valleys. For example, the second signal doesn't show any peaks with the detector (see image).

 

Using the cursor to drag to the nearest peak is exactly what I am doing at the moment and trying to avoid. But I think I need to use this method as a backup to manually correct the calculation in case it is wrong.

 

And thanks for cleaning up my code, but I have hundreds of different signals and I just copied some of the bad ones as examples.

0 Kudos
Message 6 of 8
(1,674 Views)

@ManuelElze wrote:

And thanks for cleaning up my code, but I have hundreds of different signals and I just copied some of the bad ones as examples.


It is more an attempt at a better test harness. Ultimately, the final algorithm should work for all possible signals and you can use it to e.g. iterate over all available datasets (i.e. put the file read inside the loop). It is conceivable that some of the datasets that currently work might fail with the improved algorithm. Testing is always important.

0 Kudos
Message 7 of 8
(1,659 Views)

@ManuelElze wrote:

Using the cursor to drag to the nearest peak is exactly what I am doing at the moment and trying to avoid. But I think I need to use this method as a backup to manually correct the calculation in case it is wrong.


Your curves had so few features that fitting to a sufficiently high polynomial should give you very good initial estimates of the peaks and valleys. To refine, you can follow that up with a second or third order polynomial of the surrounding point range. See how far you get.

0 Kudos
Message 8 of 8
(1,657 Views)