How to add time duration of peaks in plot

조회 수: 2 (최근 30일)
Abdelhakim Souidi
Abdelhakim Souidi 2022년 6월 12일
댓글: Star Strider 2022년 6월 13일
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에서 Descriptive Statistics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by