function [theWaves,RTFWHMbadwaves] = RTFWHMcut(theWaves,Vmaxs,tinc,time,thresholdPercent,fwhmMin,fwhmMax,riseTimeMin,riseTimeMax)


    [~,p,~] = size(theWaves);
    riseTimes=zeros(p,1);
    FWHMs=zeros(p,1);
    passes=zeros(p,1);
    for j=1:p
        riseTimes(j) = getRiseTime(theWaves(:,j,2),thresholdPercent*Vmaxs(j,2),tinc);
        [~,~,twidth,~] = findThresholds(theWaves(:,j,2),.5*max(theWaves(:,j,2)),time);
        FWHMs(j) = twidth*tinc;
        
        if ( (riseTimes(j) < riseTimeMax) && (FWHMs(j) > fwhmMin) && (riseTimes(j) > riseTimeMin) && (FWHMs(j) < fwhmMax) )
            passes(j) = 1;
        end
    end
    
    theWaves1=theWaves(:,logical(passes),1);
    theWaves2=theWaves(:,logical(passes),2);
    theWaves3=theWaves(:,logical(passes),3);
    theWaves4=theWaves(:,logical(passes),4);
    
    % waves that have too long a rise time or FWHM go into RTFWHMbadwaves
    badwaves1=theWaves(:,~logical(passes),1);
    badwaves2=theWaves(:,~logical(passes),2);
    badwaves3=theWaves(:,~logical(passes),3);
    badwaves4=theWaves(:,~logical(passes),4);    
    
    clear theWaves;
    
    theWaves(:,:,1) = theWaves1;
    RTFWHMbadwaves(:,:,1) = badwaves1;
    clear theWaves1;
    clear badwaves1;
    theWaves(:,:,2) = theWaves2;
    RTFWHMbadwaves(:,:,2) = badwaves2;
    clear theWaves2;
    clear badwaves2;
    theWaves(:,:,3) = theWaves3;
    RTFWHMbadwaves(:,:,3) = badwaves3;
    clear theWaves3;
    clear badwaves3;
    theWaves(:,:,4) = theWaves4;
    RTFWHMbadwaves(:,:,4) = badwaves4;
    clear theWaves4;
    clear badwaves4;