function [ind,peaks] = findpeaks(y)
% FINDPEAKS  Find peaks in real vector.
%       ind = findpeaks(y) finds the indices (ind) which are
%       local maxima in the sequence y.  
%
%       [ind,peaks] = findpeaks(y) returns the value of the peaks at 
%       these locations, i.e. peaks=y(ind);
%
%       Funksjonen ble funnet i Matlab Support av Eli Vatland, våren 1998
%

y = y(:)';

dy = diff(y);

ind = find( ([dy 0]<0) & ([0 dy]>=0) );

if y(end-1)<y(end)	
     ind = [ind length(y)];
end

if nargout > 1
     peaks = y(ind);
end
