LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Function that returns the maximum values of an array

Hi !!!

I have data from the peak detector function, two arrays - locations and amplitudes. After drawing the XY graph looks like this. In the picture we have "hills". I need to find the maximum value of each hill. I can't create a function that returns arrays with the location of the maximum value of each hill. It may be helpful to know that each hill is separated from each other by about 8,000 locations- there is a large distance between the hills, in my opinion, this will create a condition for whether we are in the first or next hill. Please help.

 

0 Kudos
Message 1 of 9
(3,562 Views)

What have you tried so far and what problems did you have with that attempt?

 

A simple approach would be to first separate this into two problems. First separate the two arrays into separate "hills" and then find the maximum of each array subset. There is an Array Max & Min function which could help you with the second part but the first will depend a bit on what you are expecting the data to look like. In the simplest case you could just iterate from element to element in the location array and split when the location between two indeces exceeds some value.

Matt J | National Instruments | CLA
0 Kudos
Message 2 of 9
(3,540 Views)

Did you search for Peak Detector?

 

Signal Processing >>  Signal Operation palette.

 

It helps if you attach an actual VI with data saved to see what you've tried and allows us to play with it to give you a more precise answer.

0 Kudos
Message 3 of 9
(3,536 Views)

Why not just go through the Peak Detector VI again?  It should be some simple math to convert from the decimated index to the expanded index.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 9
(3,532 Views)

I tried to present the main problem as simply as possible, so I made a small description. The array I gave is simple and short, if the program runs on this array, it will also work on mine, which is large. It seems to me that it's easier to create an array program on such a simple one. My table / graph is not really perfect (look photo ad.1), if it was smooth I would use the peak detector. This is the reason why I cannot use the peak detector because the function gives a lot of points. (Look photo ad.2). I cannot increase the number of points to calculate interpolation - this is a imposed condition. I must check each hill point by point and indicate the maximum point in each "hill" (look phota ad.3). I tried to create functions, but my function threw me the maximum one maximum value out of all points.

 

0 Kudos
Message 5 of 9
(3,501 Views)

One simple algorithm, assuming the peaks are "roughly" 4000 samples apart, using a recursive algorithm, and assuming you don't need the original indexes but just the peak values:

 

-Find the max value of the array and store both the value and its index (maxIndex)

-Split the original array at (index - 2000), then delete the first 4000 points of the second array

-Check each subarray: if they have less than 4000 points, discard it. If it has more than 4000 points, send it back into the same function.

 

If you need to know both the max values AND their locations, then you can use the same algorithm but keep track of the original index locations. If that gets too complicated, create a new cluster array of [index,value] where index is the original index and value is the original value. As you delete elements from that array, you just take the first value from the cluster pair, and don't have to keep track of each individual index.

 

You could do that, but I suspect playing around with the Width parameter on Peak Detect.vi could do it for you.

0 Kudos
Message 6 of 9
(3,474 Views)

@czesio44 wrote:

I cannot use the peak detector because the function gives a lot of points (look photo ad.1)

 

reagrding the peakdetector.vi:

have you tried values - different than the default - for width and/or threshold?

 

you may want to attach your data example as a .vi containing an array constant

0 Kudos
Message 7 of 9
(3,381 Views)

Or search the solutions already provided ...

Here is one

Here is another

put your data in and play with threshold and width

 

Shamelessly pointing to my own solutions 😄

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 8 of 9
(3,363 Views)

@Henrik_Volkers wrote:

Shamelessly pointing to my own solutions 😄


you are welcome 😉

0 Kudos
Message 9 of 9
(3,317 Views)