Plot prominences coming from findpeaks

Using this example, I can get a nice plot that contains the peaks and the prominences (and the widths too which I don't need):
findpeaks(X,'MinPeakProminence',0.05,'Annotate','extents')
However, I need the peaks and prominences plotted in a different plot that has different axes, other plots and better colors, so I plot them manually with a hold on as:
[pks,locs,~,p] = findpeaks(X,'MinPeakProminence',0.05,'Annotate','extents');
my_plot(X,time) %i have my own plotting function for this, which has a bunch of plot-beautifying stuff
hold on
scatter(time(locs),pks,20,'k','filled','v')
hold off
But I have no idea how to plot the prominences, since the prominence data p is a single number, I do not know where to start the line and where to finish it.

2 commentaires

dpb
dpb le 13 Juil 2022
'Pends on what you want the plot to be -- the 'annotate' option draws the prominence as the vertical line from the associated peak less the prominence value. That's it. For each peak, the y vector is [pk(i), pk(i)-p(i)]
The other thing the builtin plotting function does is to draw the horizontal line at pk(i)-p(i)/2 -- that's the one that you have to interpolate the signal to find the crossing on the x axis to the left/right of the peak location.
Juliana
Juliana le 15 Juil 2022
Modifié(e) : Juliana le 15 Juil 2022
Thank you @dpb! Your comment helped me get the y1 and y2 lims for the lines and then I did:
y1 = pks-p;
y2 = pks;
%reshape matrices for plotting prominences
x = vertcat(locs',locs');
y = vertcat(y1',y2');
line(x, y,'Color','k')

Connectez-vous pour commenter.

Réponses (0)

Produits

Version

R2022a

Tags

Question posée :

le 13 Juil 2022

Modifié(e) :

le 15 Juil 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by