Использование findpeaks
. На следующем рисунке и коде показаны некоторые примеры.
% Create some data
load sunspot.dat
data = sunspot(1:200,2)*4 + 180;
% Plot the data
plot(data, 'm'); hold on; grid on;
ylim([0,1000]);
% all local maxima
[pks, locs] = findpeaks(data);
plot(locs, pks, 'ro');
% all local minima -- the trick is to invert the data:
[pks, locs] = findpeaks(-data);
plot(locs, -pks, 'bo');
% local maxima greater than 500
[pks, locs] = findpeaks(data, 'MinPeakHeight', 500);
plot(locs, pks, 'r*');
% local minima less than 200
[pks, locs] = findpeaks(-data, 'MinPeakHeight', -200);
plot(locs, -pks, 'b*');
% local maxima less than 400 -- the trick is to apply treshold to the pks
[pks, locs] = findpeaks(data);
locs(pks > 400) = []; % delete unwanted data points
pks(pks > 400) = []; % delete unwanted data points
plot(locs, pks, 'kV', 'MarkerSize', 5);
legend({
'data'
'all local maxima points'
'all local minima points'
'maxima greater than 500'
'minima less than 200'
'local maxima less than 400'
});