% COLLAPSEX Checks whether the x vector is evenly sampled and then removes it
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: Checks whether the x vector is evenly sampled and then removes
%              it after setting the t0 field.
%
% CALL:        obj = collapseX(obj)
%
% INPUT:       obj - tsdata object
%
% OUTPUT:      obj - tsdata object
%
% VERSION:     $Id: collapseX.m,v 1.9 2011/06/30 16:24:12 ingo Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function varargout = collapseX(varargin)

  obj = varargin{1};

  %%% decide whether we modify the pz-object, or create a new one.
  obj = copy(obj, nargout);

  if ~isempty(obj.x)
    [fs, t0, uneven] = tsdata.fitfs(obj.x);
    if uneven
      obj.fs = fs;
    else
      % adjust T0
      obj.toffset = obj.toffset + obj.x(1)*1e3;
      % adjust Nsecs
      obj.nsecs = length(obj.y)/obj.fs;
      % remove X samples
      obj.x  = [];
    end
  end

  varargout{1} = obj;
end

