function [Ad,Bd,Cd] = c2dd(Ac,Bc,Cc,Ts,tau)
%C2DD Computes discrete-time model with computational delay
%
% Usage:  [Ad,Bd,Cd] = c2dd(Ac,Bc,Cc,Ts,tau)
%
% Computes discrete-time state space realisation for system with 
% computation delay.
% Inputs: Ac,Bc,Cc: `A',`B','C' matrices of continuous-time model
%               Ts: Sampling interval
%              tau: Computational delay
% Outputs: Ad,Bd,Bd: `A',`B','C' matrices of discrete-time model
%
% 'D' matrix assumed to be zero.

% Written by J.M.Maciejowski, 25.9.98.
% Reference: `Predictive control with constraints', section
%            on `Computational delays'.

[nstates,ninputs] = size(Bc);
noutputs = size(Cc,1);

if Ts < tau,
  error('tau greater than Ts')
end

[Ad,dummy] = c2d(Ac,Bc,Ts);  % (1,1) block of Ad computed

[A1,B1] = c2d(Ac,Bc,tau);
[A2,B2] = c2d(Ac,Bc,Ts-tau); % B2 computed
B1 = A2*B1;                  % B1 computed

Ad = [Ad, B1; zeros(ninputs,nstates+ninputs)];
Bd = [B2; eye(ninputs)];
Cd = [Cc,zeros(noutputs,ninputs)];
