function [gc kc ti] =  shams_tuning(kc0,y,r,t)

% ------------------------------------------------------------%
%                                                             %
%           Function for Determining the Shams                %
%   Tuning Parameters from Closed-Loop Step Change Responce   %
%                                                             %
% Stepchange must occure after t=0                            %
%                       written by: Chriss Grimholt 19/10-10  %
% ----------------------------------------------------------- %


dyinf = y(end)-y(1);

[rs rs_i] = max(r);

dr = rs-r(1);

[yp yp_i] = findpeaks(y);

dyp = yp(1)-y(1);

typ = t(yp_i(1))-t(rs_i(1));

b = dyinf/dr;

S = (dyp-dyinf)/dyinf;

A = 1.152*S^2-1.607*S+1;

kc = A * kc0;

ti =  min(0.86*A*abs(b/(b-1))*typ, 2.44*typ);

gc = controller(1,kc,ti);

end
