function [rBest, resnorm,residual] = fit_findRotAndShift(init_guess, xdata, ydata, lb,ub)

wt = wtlib_CenPreserve(1);

ydata = My_paddzero(My_stripzero(ydata,[size(ydata)-20]),size(ydata));

opt=optimset('TolFun',1e-7);
[rBest, resnorm,residual] = lsqcurvefit(@Fhelp, init_guess, xdata, ydata, lb, ub, opt);

% positive means anti-clockwise


function y=Fhelp(r,xdata)
    TT = r(1);
    cAngle =  TT  * pi / 180;
    rmat = [[cos(cAngle),sin(-1*cAngle)];[sin(cAngle), cos(cAngle)]];
    sp = wt.addpadding(xdata);
    sp = wt.applytransf2(sp,rmat);
    FFD = real(wt.strippadding(sp));
%     FFD = real(My_FourierShift(FFD,r(2),r(3)));

    FFD = My_paddzero(My_stripzero(FFD,[size(FFD)-20]),size(FFD));
    y = r(4)*FFD;
    

%     y = r(4)*abs(My_FourierShift(FFD,r(2),r(3)));
end
    
end