function PID2 = pid2(D,Options)
% Converts to PID2 data object

%   Author(s): B. Singh
%   Copyright 2015 The MathWorks, Inc.
if hasdelay(D)
    ctrlMsgUtils.error('Control:ltiobject:pidNoConversionWithTimeDelay')
elseif ~isequal(iosize(D),[1 2])
    ctrlMsgUtils.error('Control:ltiobject:pidOperations9')
end
Ts = D.Ts;  IF = 'F';  DF = 'F';  % default formulas
if nargin>1 && Ts~=0
    [IF,DF] = ltipack.piddata.getTargetFormulas('F','F',Options);
end
% Compute Kp,Ki,Kd,Tf, b, c with specified formulas
NUM1 = D.num{1};
DEN1 = D.den{1};
NUM2 = D.num{2};
DEN2 = D.den{2};

NUM1 = NUM1/DEN1(find(DEN1~=0,1,'first'));

NUM2 = NUM2/DEN2(find(DEN2~=0,1,'first'));

[Kp,Ki,Kd,Tf,b,c] = ltipack.piddata2.convert({NUM1,NUM2},{roots(DEN1),roots(DEN2)},Ts,IF,DF);
% Create output
PID2 = ltipack.piddataP2(Kp,Ki,Kd,Tf,b,c,Ts);
PID2.IFormula = IF;
PID2.DFormula = DF;
