function sys = process_model(k,theta,tau1,tau2)
% PROCESS_MODEL  Returns a first- or second-order time delay model.
%
% SYS = PROCESS_MODEL(K,THETA,TAU1,TAU2) returns a first- or
% second-order time delay model of the general form:
%
%                 k
% SYS = --------------------- exp(-theta*s)
%       (tau1*s+1) (tau2*s+1)
%
% If either (but not both) tau1 or tau2 is 0, then the result is a
% first-order model, where tau is the remaining finite time-constant:
%
%           k
% SYS = --------- exp(-theta*s)
%       (tau*s+1)
%
% If either (but not both) tau1 or tau2 is Inf, then the result is an
% integrating model, where tau is the remaining finite time-constant:
%
%            k
% SYS = ----------- exp(-theta*s)
%       s (tau*s+1)
%
% If both tau1 and tau2 are Inf, then the result is a double
% integrating model:
%
%         k
% SYS = ----- exp(-theta*s)
%        s^2
%
% See also SIMC_REDUCE.

% Author(s): Bora Eryilmaz, The MathWorks, Inc.

ni = nargin;
if (ni < 1), k = 1; end
if (ni < 2), theta = 0; end
if (ni < 3), tau1 = 0; end
if (ni < 4), tau2 = 0; end

if ~isinf(tau1)
  if ~isinf(tau2)
    % Denominator: (tau1*s+1)*(tau2*s+1), tau1 or tau2 can be zero.
    sys = zpk( tf(k, [tau1*tau2 tau1+tau2 1], 'ioDelay', theta) );
  else
    % Denominator: (tau1*s+1)*s, tau1 can be zero.
    sys = zpk( tf(k, [tau1 1 0], 'ioDelay', theta) );
  end
else
  if ~isinf(tau2)
    % Denominator: s*(tau2*s+1), tau2 can be zero.
    sys = zpk( tf(k, [tau2 1 0], 'ioDelay', theta) );
  else
    % Denominator: s^2
    sys = zpk([], [0 0], k, 'ioDelay', theta);
  end
end
set(sys, 'DisplayFormat', 'time');
end
