how to draw a peak line

조회 수: 7 (최근 30일)
Luca Re
Luca Re 2024년 9월 28일
댓글: Star Strider 2024년 9월 29일
Hi, i've data and i want to draw a line that corresponds to the peaks (where there is a zero the previous value >0 must be pasted) (See black line painted)
Is there a function or graph type that does this to me?

채택된 답변

Star Strider
Star Strider 2024년 9월 29일
If you have the Signal Processing Toolbox, use the findpeaks function with an approopriate valuee for 'MinPeakProminence' so that it only detects certain peaks —
date = datetime(2022,01,01) : caldays(1) : datetime(2024,9,28);
t = day(date,'dayofyear');
data = cos(2*pi*t/28).*cos(2*pi*t/7)/10+rand(size(date))/10;
[pks,locs] = findpeaks(data, 'MinPeakProminence',0.15);
figure
plot(date, data, '-r','LineWidth',2)
hold on
plot(date(locs), pks, '-k', 'LineWidth',1)
hold off
grid
xlim('tight')
ylim([0 max(ylim)])
You will have to experiment wiith the 'MinPeakProminience' value. A good guess for a starting value is approximately half way between the shortest and tallest peaks, then adjust it as necessary.
It would be helpful to have your data.
  댓글 수: 2
Luca Re
Luca Re 2024년 9월 29일
thank you but i don't have this toolbox
Star Strider
Star Strider 2024년 9월 29일
My pleeasure!
O.K. Instead use:
Lvmn = islocalmax(data, 'MinProminence',0.15);
Changing my previous code to accommodate it —
date = datetime(2022,01,01) : caldays(1) : datetime(2024,9,28);
t = day(date,'dayofyear');
data = cos(2*pi*t/28).*cos(2*pi*t/7)/10+rand(size(date))/10;
Lvmn = islocalmax(data, 'MinProminence',0.15); % Returns Logical Veector
locs = find(Lvmn); % Not Specifically Necessary, Returns Numeric Indices Of Peaks
pks = data(Lvmn); % Necessary, Returns Peak Amplitude Values
figure
plot(date, data, '-r','LineWidth',2)
hold on
plot(date(locs), pks, '-k', 'LineWidth',1)
hold off
grid
xlim('tight')
ylim([0 max(ylim)])
Again, it may be necessary to experiment with the 'MinProminence' value to get the reesult you want.
.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2024년 9월 29일
mask = islocalmaximum(YourSignal);
peak_times = YourSignalTimes(mask);
peak_values = YourSignal(mask);
plot(peak_times, peak_values);

카테고리

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