function [riseTime,fallTime] = getRiseFall(signal,thresh,tinc)

% [riseTime,fallTime] = getRiseFall(signal,thresh,tinc)
%
% This function takes a signal vector,a CFthreshold value and time interval 
% between each data points, and generate the time taken to rise from the
% threshold to 90% of the maximum (risetime) and the time taken to fall
% from the 90% of the maximum to the threshold (falltime).
%
% Input parameters:
% signal: a vector containing the function data points.
% thresh: CFthreshold
% tinc : a scalar time interval between each data points.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Current state of the project and change history.
%
%	Created by:	M. Wetstein
%	Created on:	Unknown
%
%	Version: 1.1
%	Modified by: R. Obaid
%	Edited on:	07/08/2011
%	  (a)	Building it as function primitives
%
% If you type 'help getRiseFall' on the Matlab command window, you will be
% able to see the help documentation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% beginning of code %%%%%%%%%%%%%%%%%%%%%%%



len = size(signal);
[top, ind] = max(signal);

%the upperbound for risetime and falltime is 90% of the top
top=top*0.9;

countR=0;
countF=0;

for j = 1:ind
    if( signal(j) > thresh && signal(j) < top)
        countR=countR+1;
    elseif(signal(j)>top)
        break;
    end
end

riseTime=countR*tinc;

for j=ind:len(1)
     if ( signal(j) < top && signal(j)>thresh )
        countF=countF+1;
     elseif(signal(j)<thresh)
         break;
     end
end
 fallTime=countF*tinc;