function err = log_gauss_errfn(fitparams,x,y); % % function err = log_gauss_errfn(fitparams,x,y); % % Returns the error, err, between the z-gaussian function and the % input data. Assumes the input data is of the form where x is % the grid, and y is the Gaussian. % % Input variable fitparams should be of the following form: % % fitparams = [A, xo, sigma], % % where we are fitting to a gaussian of the form: % % log(y) = log(A*exp(-(x-xo)^2 / (2*sigma^2))) % = log(A) - (x-xo)^2 / (2*sigma^2); % % % Written by Miles A. Sundermeyer, 2/1/06 % parse fitparams A = fitparams(1); xo = fitparams(2); sigma = fitparams(3); % compute the function associated with the fit params logy = log(y); logyfit = log(A*exp(-(x-xo).^2 / (2*sigma^2))); vecscale = 3e+2; if(0) % plot this as a check figure(199) clf plot(x,logy,'bo'); hold on plot(x,exp(logyfit),'r-'); xlabel('x') ylabel('y') axis([min(x(:)) max(x(:)) min([min(y(:)) 0]) max(y(:))]) end % compute the error between the fitted and actual fields err = mean(abs([logy(:)-logyfit(:)])); %drawnow %pause(0.1)