how to draw a peak line
7 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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 个评论
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
2024-9-29
mask = islocalmaximum(YourSignal);
peak_times = YourSignalTimes(mask);
peak_values = YourSignal(mask);
plot(peak_times, peak_values);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!