How to add time duration of peaks in plot

4 次查看(过去 30 天)
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

回答(2 个)

Star Strider
Star Strider 2022-6-13
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 个评论
Image Analyst
Image Analyst 2022-6-13
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:
Star Strider
Star Strider 2022-6-13
@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.

请先登录,再进行评论。


Image Analyst
Image Analyst 2022-6-12
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.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by