function [val1,val2] = auto_tune(arr1,arr2,x3,x4,string)
    try
    x1=arr1(1);
    x2=arr2(length(arr2));
    init_temp=x1;
    fin_temp=arr1(length(arr1));

    
    y=smoothing(smoothing(arr1));
    time=arr2;
    ypp=diff(y,2);

    t_inflection=fzero(@(T) interp1(time(2:end-1),ypp,T,'linear','extrap'),0);
    y_inflection=interp1(time,y,t_inflection,'linear');
 
    
    min=9999;
    xx=0;
    for i=1:length(arr1)
        if(abs(y_inflection-arr1(i))<min)
            min=abs(y_inflection-arr1(i));
            min_y=arr1(i);
            min_t=arr2(i); 
            xx=i+1;
        end
    end
    pt_y=arr1(xx);
    pt_t=arr2(xx);
    slope=(min_y-pt_y)/(min_t-pt_t);
    T2=min_t+((init_temp-min_y)/slope);
    T1=(min_t+((fin_temp-min_y)/slope))-T2;
    y_vertical=[(x1-10):1:x4];
    x_vertical_1= T2.*(ones(length(y_vertical),1));
    x_vertical_2= (T1+T2).*(ones(length(y_vertical),1));
    txt1=sprintf('T2: %.1f sec',T2);
    txt2=sprintf('T1: %.1f sec',T1);
    figure(1);
    title(string);
    a=[1:1:x3];
    b=(min_y+(a-min_t)*slope);
    axis([0 x3 (x1-10) x4]);
    hold on;
    plot(x_vertical_1,y_vertical,'--r');
    hold on;
    plot(x_vertical_2,y_vertical,'--r');
    hold on;
    text(((T1/2)-30),(fin_temp+5),txt2);
    hold on;
    plot(min_t,min_y,'*r');
    hold on;
    plot(a,b);
    hold on;
    text((T2+10),(init_temp-5),txt1);
    hold on;
    val1=T2;
    val2=T1;
    
    catch
         error('Error auto_tuning - Sample size too small - Run open-loop longer');
        
   end
    
    
end