0

I have some data, that basically looks like a sine wave. I run that through the peak detection function to find the peaks and mins of the data:

[Maxima,MaxIdx] = findpeaks(Peak,'MinPeakHeight',mean(Peak),'MinPeakDistance',10);
Mins=1.01*max(Peak)-Peak;
[Minima,MinIdx] = findpeaks(Mins,'MinPeakHeight',mean(Mins),'MinPeakDistance',10);
Minima = Peak(MinIdx);

What I would like to do is calculate the slope between each peak and trough, and then use that slope to calculate a time weighted average minimum value and see how that method compares to the minimum value. How would I go about this?


was asked to show some data:-

Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
J.Doe
  • 15
  • 8
  • Do you have to split the detection of Minima and Maxima? Can't you assume that a Minimum is just between two Maxima. So you just have to check if the first value is larger or smaller than the second value. Assuming the first is a Peak the you will have Max, Min,Max,Min and so on. Then you can just call diff() of your peaks to get you y/Height differences, You then create a second array with the x-coordinated or time points of the maxima. i.e. newTime = time(peakIdx). Then call diff on that array. And then just use ./ operator ot calculate the slopes. – v.tralala Jul 24 '16 at 22:52
  • the peaks/mins are not consistent and if I use that assumption I miss a lot of the local peaks/mins. this inversion method always returns 99% of all peaks and mins with few errors. – J.Doe Jul 25 '16 at 12:30
  • Hm ok. Do you want the slope of two neighbouring peaks? or between peaks and minimum. can you just plot some data and upload a screenshot. Maybe it then becomes more clear. What you mean with "slope between each peak and trough" – v.tralala Jul 25 '16 at 22:06
  • @VietTran I added a picture to some data. Basically red is peak green min. So the downward slope of the curve is the slope I am looking for, and then the upward slope (but not necessary just a nice to have). I want to know if I averaged all of the data points on that curve from peak to min over time how weighted is that average? Is it less shallow at the top and more time is spent closer to the min so the average is lower because of that? – J.Doe Jul 25 '16 at 22:28
  • There is another question. What is the difference in your variables `Peak` and `Peakdata`? And are your detected minima between the maxima or do you have to sort them. Because in the first case you could just that slope `m = (y1-y2)/(x1-x2)`, where y are the values in the array Maxima/Minima and x are the according values on hte x-axi, which you didn't provided. But assuming it is called i.e. `time` then you will get the corresponding x-values by just calling `time(MaxIdx)` or `time(MinIdx)` – v.tralala Jul 25 '16 at 22:43
  • Sorry they are the same, I corrected the code. Yes X is time, .05 seconds apart. – J.Doe Jul 25 '16 at 22:51
  • In a sine wave, the slope is continually changing. So should you be calculating minimum, maximum, mean, median slope, or what? – Ben Voigt Jul 25 '16 at 22:54
  • @BenVoigt well that is why I wanted to get a weighted average, since the slope does change. So as the rate of change...uh.. changes, I want to weight my averaging of the Y value appropriately where a faster rate has less weight (since less time is spent at those values). It is sort of like a smoothing function now that I think about it. What gradient of slope partitioning I would need for an accurate weight I am not sure of though. Do you think just the mean slope would be sufficient though? – J.Doe Jul 26 '16 at 00:21
  • Mean slope is the straight line connecting peak to trough. – Ben Voigt Jul 26 '16 at 00:23
  • Yes but if the slope is normally distributed between the two it would be a good representation of the overall slope no? I am not sure if that is the case here. I feel like if I did a segmentation I would get a more accurate weighting. – J.Doe Jul 26 '16 at 00:33

0 Answers0