function [PA, TA, KA]= timeseg2(signal, protocol, fs)
% segmentation and sorting of burst, vowel, occlusion timestamps
% in case of index output specify sampling frequency
   cycle_nr=size(protocol, 1)/3;
    pa_sort=logical(repmat([1 0 0], 1, cycle_nr));
    ta_sort=logical(repmat([0 1 0], 1, cycle_nr));
    ka_sort=logical(repmat([0 0 1], 1, cycle_nr));
    protocol=sort(reshape(protocol, 1, []));
    timestamps=uint32(protocol*fs);
    j=0;
    for i=1:3:(length(timestamps))
        j=j+1;
        if j==cycle_nr*3
            segments{j,1}=signal(timestamps(i):timestamps(i+1));
            segments{j,2}=signal(timestamps(i+1):timestamps(i+2));
            
        else
            segments{j,1}=signal(timestamps(i):timestamps(i+1));
            segments{j,2}=signal(timestamps(i+1):timestamps(i+2));
            
        end
    end
    
    PA=segments(pa_sort, :);
    TA=segments(ta_sort, :);
    KA=segments(ka_sort, :);
end