% method of class @signal
%
% returns the height and lows in locations and time of all local maxima in the signal
% in case of continuus maxima, the last value of the series is taken
% 
%   INPUT VALUES:
%  
%   RETURN VALUE:
%
% 
% (c) 2003-2008, University of Cambridge, Medical Research Council 
% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
% http://www.pdn.cam.ac.uk/cnbh/aim2006
% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
% $Revision: 585 $

function [maxpos,minpos,maxs,mins]=getminmax(sig)
% usage: [maxpos,minpos,maxs,mins]=getminmax(sig)


werte=getdata(sig);
werte=werte';

% find all maxima
% mit NULL!!
maxpos = find((werte >= [0 werte(1:end-1)]) & (werte > [werte(2:end) 0]));
maxs=werte(maxpos);

% find all minima
minpos = find((werte < [inf werte(1:end-1)]) & (werte <= [werte(2:end) inf]));
mins=werte(minpos);

maxpos=bin2time(sig,maxpos);
minpos=bin2time(sig,minpos);