how to draw a peak line
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Star Strider
le 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 commentaires
Star Strider
le 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.
.
Plus de réponses (1)
Walter Roberson
le 29 Sep 2024
mask = islocalmaximum(YourSignal);
peak_times = YourSignalTimes(mask);
peak_values = YourSignal(mask);
plot(peak_times, peak_values);
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!