function [thcount,thgap,doublehump] = findThresholds2(signal,threshold,~,tvect,dhumpTwidth)
    
    thgap=100000;

    [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
    

    direction=1;
    thcount=0;

    doublehump=0;
    
    howLarge = 0;
    flipFlop = 0;
    
    for j = 1:size1
        if( (signal(j) > threshold) && flipFlop == 0 )
            howLarge = howLarge + 1;
            flipFlop = 1;
        end
        if( (signal(j) < threshold) && (flipFlop == 1) )
            flipFlop = 0;
        end
    end
    
    thlocation = zeros(howLarge);
    
    for j=1:size1

        if( ( signal(j) > threshold ) && ( direction==1 ) )
            thcount = thcount+1;
            direction=-1;
            thlocation(thcount)=j;
            
            if(thcount==2)
                thgap=(thlocation(2)-thlocation(1));
            end
        
        end
        
        
        if( ( signal(j) < threshold ) && ( direction==-1 ) )
            direction=1;
            
            if((tvect(j)-tvect(thlocation(thcount)))>dhumpTwidth)
               doublehump=1; 
            end
            
        end
    end

end