load defined_Gaussian_peak_on_const_bg

plot(t,y,'.')
set(gca,'FontSize',14)
xlabel('time [s]')
ylabel('signal [arbitrary unit]')


% build design matrix
A = [ones(length(t),1)  exp(-((t-15)/6).^2)'];

[U,S,V] = svd(A,0);   % SVD of the design matrix
W = diag(1./diag(S)); % Note: we didn't check 
% for zero singular values
a = V*W*U'*y;         % our coefficients
[n m] = size(A);
redchisqu = sum((A*a-y).^2)/(n-m); % reduced
% Chi-squared
errmat = redchisqu*V*W.^2*V'; % covariance matrix


% results:
a
sa = sqrt(diag(errmat))