function seg = remove_sil_from_seg( in_seg, sil_min_dur_sec )

  % Check input arguments
  
  if nargin < 2
    error( 'remove_sil_from_seg: needs two input arguments !' );
  end
  
  if nargout < 1
    error( 'remove_sil_from_seg: needs one output argument !' );
  end
  
  if ~isnumeric( in_seg )
    error( 'remove_sil_from_seg: needs a 3xN matrix of TIME VALUES AND SPEECH/SILENCE INDICATORS for "in_seg" input argument !' );    
  end
  
  seg = in_seg;
  
  if isempty( in_seg )
    if ~strcmp( warning, 'off' )
      disp( 'remove_sil_from_seg: WARNING! empty input argument "in_seg".' );
    end
    return;
  end
    
  siz = size( in_seg );
  if siz( 1 ) ~= 3
    error( 'remove_sil_from_seg: needs a 3xN matrix of TIME VALUES AND SPEECH/SILENCE INDICATORS for "in_seg" input argument !' );    
  end
  
  %%%
  
  tmp = seg(2,:) - seg(1,:);
  
  % Remove first and last segments
  tmp( 1 ) = NaN;
  tmp( end ) = NaN;
  
  % Remove active segments
  tmp( find( seg( 3,: ) ) ) = NaN;
  
  % Store silences' durations
  sil_dur = tmp;
  
  % Find silence with duration < sil_min_dur_sec
  ind = sort( find( sil_dur < sil_min_dur_sec ) );
  
  for b = fliplr( ind )
    
    % Sanity check: check we have speech before and after
    if ~all( seg(3, [b-1 b+1]) )
      error( 'remove_sil_from_seg: cannot remove silence! Inconsistency.' );
    end
    
    % Remove this silence from the segmentation
    speech_start = seg( 1, b-1 );
    speech_end   = seg( 2, b+1 );
    seg = [ seg(:,1:b-2), [ speech_start; speech_end; 1 ], seg( :, b+2:end ) ];
    
  end
  