% function for simc tuning
% input: 1st order model + tuning parameter
% returns: simc tuning paramer for a PI controller on the form gc = K + I/s

function [tuning, gc] = simcImp(gp,tc)

% determining the model

t = gp.den{1}(1);
d = totaldelay(gp);
g = gp.num{1}(end);
z = zero(gp);
p = pole(gp);

if nargin == 1
    tc = d;
end

if length(gp.den{1}) > 2
    disp('model order to high')
    return
elseif isempty(z) == 0
    disp('model cannot contain zeros')
    return
end

if p == 0 % integrating process
    K = (t)/(g*(d+tc));
    I = K/(4*(tc+d));
elseif isempty(p)==1; % pure delay process
     K = ((d/3)/g)/(tc+d);
     I = K/(d/3);
else
    K = 1/g*(t+d/3)/(tc+d);
    I = K/min(t+d/3,4*(tc+d));
end
   

tuning = [K;I]
gc = controller(K,I);

return