how to draw a peak line
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Luca Re
am 28 Sep. 2024
Kommentiert: Star Strider
am 29 Sep. 2024
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 Kommentare
Akzeptierte Antwort
Star Strider
am 29 Sep. 2024
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 Kommentare
Star Strider
am 29 Sep. 2024
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.
.
Weitere Antworten (1)
Walter Roberson
am 29 Sep. 2024
mask = islocalmaximum(YourSignal);
peak_times = YourSignalTimes(mask);
peak_values = YourSignal(mask);
plot(peak_times, peak_values);
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!