function [I status] = find_peak(signal)
% [I status] = find_peak(signal)
%
% Input Variables
%   signal - The Signal

% Output Variables
%   status- peak is min or max
%   I- the peaks of the signal
%
% Description
%   Finds the Peaks in the signal
% Created
%   8/23/2006, Mohamed A Mneimneh, Marquette University
%
% This software is released under the terms of the GNU General
% Public License (http://www.gnu.org/copyleft/gpl.html).
% Modified

count = 1;

for i = 1 : length(signal) 
    
    if ( i >2 && signal(i-2) > signal(i-1) && signal(i-1) < signal(i) )
        I(count) = i-1;
        status(count) = 0;
        count = count +1;
    elseif ( i >2 && signal(i-2) < signal(i-1) && signal(i-1) > signal(i) )
        I(count) = i-1;
        status(count) = 1;
        count = count +1;
    end

end