function [mu, sigma] = background(y, UseSignificance, s);
% function [mu, sigma] = background(y, UseSignificance, s)
%
% calculates mean and standard deviation values of the given signal
% based on the signal before the pulse. If significance is not set, it is calculated.
%
% <y> is given signal in 1D array format.
% <UseSignificance> is a switch: 0 is for calculation significance function.
% <s> is significance function of the signal.
% <mu> is the mean value of the background.
% <sigma> is the standard deviation of the background.
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Current state of the project and change history.
%
%	Created by:	Alexander Vostrikov
%	Created on:	07/08/2011
%
%	Version: 1.1
%	Modified by:	Alexander Vostrikov
%	Edited on:	07/13/2011
%	 (a)	Asks for a significance function as an input parameter, but can calculate
%		it if necessary.
%	 (b)	Version 1.1 of SignificanceCut function is used.
%
% List of Previous Versions:
%
%	Version: 1.0
%	Modified by:	Alexander Vostrikov
%	Edited on:	07/12/2011
%	 (a)	Version 1.0 of SignificanceCut function is used.
%
% If you type 'help background' on the Matlab command window, you will be
% able to see this help documentation.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% beginning of code %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if UseSignificance == 0
	s = significance(y);
end

i = SignificanceCut(s, 3.0) - 1;
mu = mean(y(1:i));
sigma = std(y(1:i));

end

