01-07-2020 01:27 PM
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.
01-07-2020 01:39 PM
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.
01-07-2020 01:40 PM - edited 01-07-2020 01:41 PM
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.
01-07-2020 01:42 PM
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.
01-07-2020 02:35 PM
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.
01-07-2020 03:19 PM
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.
01-08-2020 04:46 AM - edited 01-08-2020 04:49 AM
@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
01-08-2020 06:33 AM - edited 01-08-2020 06:39 AM
Or search the solutions already provided ...
put your data in and play with threshold and width
Shamelessly pointing to my own solutions 😄
01-08-2020 11:27 AM
@Henrik_Volkers wrote:
Shamelessly pointing to my own solutions 😄
you are welcome 😉