function [thcount,thgap,twidth,edgeT] = findThresholds(signal,threshold,tvect)
    

    [size_a,size_b] = size(signal);
 
    if( (size_a>1) && (size_b>1) )
       
        error('Array is not a 1-D time series!! Cannot find max!');
        
    end
    
    size1 = size_a;
    if(size_b>size_a) 
        size1=size_b;
    end
    

    twidth=1;

    
     aboveThresh = ( signal(:) > threshold );
     belowThresh = ( signal(:) < threshold );
     
    newbelowThresh = zeros(size1,1);
    newbelowThresh(1)=0;
    newbelowThresh(2:size1) = belowThresh(1:(size1-1));
    
    isUpThresh = aboveThresh.*newbelowThresh;
    
     newbelowThresh = zeros(size1,1);
     newbelowThresh(size1) =0;
     newbelowThresh(1:(size1-1)) = belowThresh(2:size1);
     
     isDownThresh = aboveThresh.*newbelowThresh;
     
     upIndices = find( isUpThresh(:) == 1 );
     downIndices = find( isDownThresh(:) == 1 );  
    
    thcount = sum(isUpThresh);
    dcount=sum(isDownThresh);
    
    thgap=0;
    if(thcount>1)
        thgap=upIndices(2)-upIndices(1);
        if( (dcount>1) && (downIndices(1)<=upIndices(2)) && (upIndices(2)<=downIndices(2)) && ((downIndices(2)-downIndices(1))<10) )
            thgap=0;
        end
    end
        

    if(dcount>0)
       twidth=downIndices(1)-upIndices(1);
    end
   
    edgeT=-5555;
    if(thcount>1)

        edgeT = tvect(upIndices(1));
    end

end