function plot_loctimeseg( loctimeseg, linestyle )

% function plot_loctimeseg( loctimeseg, linestyle )
%
% Draw a "loctimeseg" object, as produced for example by
% "construct_raw_loctimeseg.m" and "compute_smooth_loctimeseg.m".
%
%
% loctimeseg: an object defining segmentation of concurrent speakers, IN TERMS OF LOCATIONS.
%  Fields are:
% - loctimeseg.nChannels:  an integer defining the number of LOCATIONS.
% - loctimeseg.azList:     vector of nChannels azimuth locations (float, radians).
% - loctimeseg.startTime:  a float, in seconds, beginning of the segmentation.
% - loctimeseg.endTime:    a float, in seconds, end of the segmentation.
% - loctimeseg.seg:        a list of nChannels matrices. Each matrix defines
% the speech/non-speech segmentation for one speaker: each column is a segment.
%   - row 1 is start of the segment in seconds.
%   - row 2 is end of the segment in seconds.
%   - row 3 is 0 or 1. 0 means non-speech, 1 means speech.
%
%
% By Guillaume Lathoud 2006 - lathoud@idiap.ch


  if nargin < 1
    error( [ mfilename '.plot_loctimeseg() needs at least 1 input argument.' ] );
  end

  if ~exist( 'linestyle', 'var' )
    linestyle = 'b-';
  end

  % For each location

  for a = 1:loctimeseg.nChannels
    
    % Trace the "silence" line for this location
    
    plot( [ loctimeseg.startTime, loctimeseg.endTime ], [ a a ], 'color', [0.7 0.7 0.7] );
    
    % For each segment

    seg  = loctimeseg.seg{ a };
    nseg = size( seg, 2 );

    for b = 1:nseg

      % Trace one silence or speech segment

      plot( seg( [ 1 2 ], b ), a + seg( [ 3 3 ], b ) / 2, linestyle );
      hold on;
      
      % If not the last segment, trace the change to the next segment
      
      if b < nseg
	plot( [ seg( 2, b ) seg( 1, b+1 ) ], a + seg( 3, b:b+1 ) / 2, linestyle );
      end
    
    end

  end

  axis( [ loctimeseg.startTime loctimeseg.endTime 0 loctimeseg.nChannels+1 ] );

  set( gca, 'ytick', 1:loctimeseg.nChannels, 'yticklabel', round( loctimeseg.azList / pi * 180 ) );
  
  xlabel( 'time in seconds' );
  ylabel( 'azimuth in degrees' );
  