function [Delay,fiod] = discretizeDelay(Delay,Ts)
% Extracts discrete delays for discretization purposes.
%
%   [DELAYD,FIOD] = DISCRETIZEDELAY(DELAYC,TS) extracts the
%   discrete input, output, and I/O delays when discretizing
%   the continuous delays DELAYC with sampling interval Ts.
%   The structure DELAYD contains the integer-valued discrete
%   delays and FIOD is the matrix of residual normalized
%   fractional delays (all lumped together as I/O delays).

% Copyright 1986-2014 The MathWorks, Inc.

% Add static method to be included for compiler
%#function ltipack.util.splitDelay

% Compute discrete input and output delays
[Delay.Input,fid] = ltipack.util.splitDelay(Delay.Input,Ts);
[Delay.Output,fod] = ltipack.util.splitDelay(Delay.Output,Ts);

% Lump residual fractional delays into continuous I/O delays and
% decompose I/O delays
[ny,nu] = size(Delay.IO);
niod = Delay.IO/Ts + fod(:,ones(1,nu)) + fid(:,ones(1,ny)).'; % normalized I/O delays
[Delay.IO,fiod] = ltipack.util.splitDelay(niod,1);