How to add time duration of peaks in plot

Hi
I have a a vector containing time duration of each peak duration
g = [0.8432 0.6010 0.2447 0.2274 0.1081 0.1025 0.0818 0.0800];
and I want to that duration figure in my signal plot as the figure below:
So,how can I do it please

Answers (2)

I am not certain what you want.
Try this —
x = linspace(0, 20, 250);
ctrv = rand(3,1)*18;
y = sum(exp(-(x-ctrv).^2./rand(3,1))); % Generate Gaussian Peaks With Random Widths & Locations
[pks,locs,wdth] = findpeaks(y, 'WidthReference','halfheight'); % Calculate Peak Locations & FWHM Values
figure
plot(x, y)
grid
text(x(locs), pks/2, compose('%.1f',wdth), 'Horiz','center', 'Vert','bottom') % Write The FWHM Values At The Appropriate Locations On The Plot
This writes the full-width-half-maximum values at the coordinates of those values. See the documentation on the text function for details. Make appropriate changes to work with your data.
.

4 Comments

thank you
when I excute your code I got an error:
"Array indices must be positive integers or logical values".
I want to calculate the time duration of each peak and plot it
bar(wdth);
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
@Abdelhakim Souidi — With respect to your earlier Comment, my code works correctly, as demonstrated. I have no idea what you are doing, so I cannot determine what the problem is with your using it.

Sign in to comment.

Not sure how you're defining the width but you can fall down each side of the peak (with a for loop) until you hit a certain level, like 0.5. Or do it like this:
props = regionprops(signal > 0.5, 'Area');
peakWidths = [props.Area]
Or you can fall down from the peak (on each side with a for loop) until the value no longer decreases.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Asked:

on 12 Jun 2022

Commented:

on 13 Jun 2022

Community Treasure Hunt

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

Start Hunting!