MATLAB: Get the locations of the intercept points in the findpeaks function (with the ‘WidthReference’ line)

findpeaks

Hello, is there any chance of getting the intercept points between a peak and its 'WidthReference' line?
For example I have this data:
c = [0 0 0 1 2 5 7 21 21 21 21 21 7 6 5 2 3 2 0 1 0 12 15 0 4 2 10 10 10 10 3 1 1];
findpeaks(c,'SortStr','descend','MinPeakProminence',8,'Annotate','extents')
And I need to get the red points, as shown in the next figure:
The aim of this is to obtain the middle point of each peak (green points). My real data is a 600 elements vector, so it will be enough to round the X coordinate to the nearest integer.
Thank you in advance.

Best Answer

Finally I have found a solution for this problem after some messing around with the 'findpeaks' function. It is possible to obtain the intersection points only by adding 'wxPk' to the output parameters of the original function.
I have made a copy of the 'findpeaks' function and renamed it as 'findpeaks2', then I replaced the first line of code with:
function [Ypk,Xpk,Wpk,Ppk,wxPk] = findpeaks2(Yin,varargin)
For the example in the question:
c = [0 0 0 1 2 5 7 21 21 21 21 21 7 6 5 2 3 2 0 1 0 12 15 0 4 2 10 10 10 10 3 1 1];
[pks,locs,w,p,wxPk] = findpeaks2(c,'SortStr','descend','MinPeakProminence',8,'WidthReference','halfheight','Annotate','extents');
findpeaks(c,'SortStr','descend','MinPeakProminence',8,'Annotate','extents')
hold on
for i = 1:length(p)
scatter(wxPk(i,:),[pks(i)-p(i)/2,pks(i)-p(i)/2],'r') % Plot puntos intersección
scatter((wxPk(i,1)+wxPk(i,2))/2,pks(i)-p(i)/2,'g') % Plot punto medio
scatter((wxPk(i,1)+wxPk(i,2))/2,pks(i),'k','v') % Plot pico medio
end
Hope this helps someone!