| Contents | Index |
pks = findpeaks(data)
[pks,locs]
= findpeaks(data)
[...] = findpeaks(data,'Name',value)
pks = findpeaks(data) returns local maxima or peaks, pks, in the input data. data requires a row or column vector with real-valued elements with a minimum length of three. findpeaks compares each element of data to its neighboring values. If an element of data is larger than both of its neighbors or equals Inf, the element is a local peak. If there are no local maxima, pks is an empty vector.
[pks,locs] = findpeaks(data) returns the indices of the local peaks.
[...] = findpeaks(data,'Name',value) accepts one or more comma-separated name/value pairs. Specify 'Name' inside single quotes. 'Name' is not case sensitive.
Find peaks in a vector:
data = [2 12 4 6 9 4 3 1 19 7]; pks=findpeaks(data); % returns the 1x3 vector [12 9 19];
Find peaks separated by more than three elements and return their locations:
data = [2 12 4 6 9 4 3 1 19 7]; [pks,locs]=findpeaks(data,'minpeakdistance',3); % returns pks=[12 19] % locs=[2 9]
Create a signal with 11 peaks. Find each peak and mark the peaks in a plot:
x = linspace(0,1,1024);
Pos = [0.1 0.13 0.15 0.23 0.25 0.40 ...
0.44 0.65 0.76 0.78 0.81];
Hgt = [ 4 5 3 4 5 4.2 2.1 4.3 3.1 5.1 4.2];
Wdt = [.005 .005 .006 .01 .01 .03 .01 .01 .005 .008 .005];
PeakSig = zeros(size(x));
for n =1:length(Pos)
PeakSig = ...
PeakSig + Hgt(n)./( 1 + abs((x - Pos(n))./Wdt(n))).^4;
end
% find peaks with defaults
[pks,locs] = findpeaks(PeakSig);
plot(x,PeakSig); hold on;
% offset values of peak heights for plotting
plot(x(locs),pks+0.05,'k^','markerfacecolor',[1 0 0]);


Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |