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 Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by