function [t0] = CFDtiming(y, t, fraction, UseSignificance, s, UseMean, mu);
% function [t0] = CFDtiming(y, t, fraction, UseSignificance, s, UseMean, mu)
%
% finds the position of the first pulse using constant fraction determinant procedure.
%
% is the given signal in 1D array format.
% is time axis in 1D array format.
% is the level of threshold in terms of the pulse amplitude.
% is a switch: 0 is for calculation significance function.
% ~~ is significance function of the signal.
% is a switch: 0 is for calculating the signal mean value.
% is the mean value of the signal.
% is time of the pulse.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Current state of the project and change history.
%
% Created by: Alexander Vostrikov
% Created on: 07/11/2011
%
% Version: 1.1
% Modified by: Alexander Vostrikov
% Edited on: 07/13/2011
% (a) Significance function and mean value of the signal can be set without
% calculation.
%
% List of Previous Versions:
%
% Version: 1.0
% Modified by: Alexander Vostrikov
% Edited on: 07/12/2011
%
% If you type 'help CFDtiming' on the Matlab command window, you will be
% able to see this help documentation.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% beginning of code %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if UseSignificance == 0
s = significance(y);
UseSignificance = 1;
end
if UseMean == 0
[mu, sigma] = background(y, UseSignificance, s);
end
a = SignificanceCut(s, 6.0);
b = a;
while y(a) > mu
a--;
end
while y(b) > mu
b++;
end
threshold = fraction * (max(y(a:b)) - mu) + mu;
t0 = t(find(y(a:b) > threshold)(1) + a - 1);
end
~~