MATLAB: Return curve peak coordinates – not just the peak

findpeakspeak

Hi,
I'm trying to get the whole curve where a peak belongs to, such as what I have badly drawn on the image using red colour. Is there a way to perform this please?
Thanks

Best Answer

I would do something like this:
x = [1:17]*10; % Create Data

y = [0 1 0 2 0 9 0 3 0 1 0 2 0 9 0 3 0]*0.25; % Create Data
[pks1,locs1] = findpeaks(y, x, 'MinPeakHeight',2);
[pks2,locs2] = findpeaks(-y, x);
pk1_start = locs2(find(locs2 < locs1(1), 1, 'last')); % Start Of First Peak
pk1_end = locs2(find(locs2 > locs1(1), 1, 'first')); % End Of First Peak
... then do the same for the second peak, ‘locs1(2)’. With the start- and end-points, you can define the entire peak.
This makes some assumptions about your data, since I do not have them to work with. You will probably have to experiment with this idea for it to work with your data.