function[Sig, Sig_Dif, Tau] = GenerateAllan(samp_data, log0, logM, delt_log,...
delt_file, NM, N )
%{
Generates Allan variance data from an array of data using a
samp_data :a 1 X N array of data
log0 :log base 10 of the shortest cluster time
logM :log base 10 of the longest cluster time
delt_log :number increments
N :number of data points
NM :number of points used...based on four samples being the
number of points in the shortest cluster.
delt_file :sample time of data
The log spacing of the cluster times is based on spacing the cluster time
evenly in log space. This results in an even number of points in the log-log plots of
the standard deviation versus correlation time. Makes it a lot easier to interpret the data.
Three parameters are assumed fixed by the calling program,
1) the largest cluster length is the interger number of the total points
divided by 4.
2) The number of samples in the first and smallest cluster is 2
and, thus the shortest correlation time is 2*delt_file.
3) The points (Points) are evenly spread over the entire cluster time range.
Thus
M=INT(N/4)
and
NM = M*4
Then
logM=log10(M*delt_file)
log0=log10(2*delt_file)
delt_log=(logM-log0)/Points
The input data, samp_data, must be at a fixed sample rate of 1/delt_file. Note that all the
may not be used.
The output is three single dimension arrays of data:
Sig...The square root of the Allan Variance
Tau...The correlation times, in seconds.
Sig_Dif...The cluster error estimate as a fraction
The calling program would then generate the Root Allan Variance plots with a script such as
figure;
loglog(TauAx(1,:), SigAx(1,:),'r-');
Reference:
An interesting paper that shows the math behind the Allan Variance method, how to interprete the
log-log plots and alos developes a recursive Allan variance algorithm is
"On The Application of Allan Variance Method for Ring Laser Gyro Performance Characterization"
by Lawrence C. Ng, October 15, 1993, Lawrence Livermore National Laboratory, UCRL-ID-115695. The paper is
availabel at:
http://www.osti.gov/energycitations/product.biblio.jsp?osti_id=10196087
%}
Cdata = zeros(1,N);
K= 0; %/* cluster index */
%{
This setup will give a linear distribution of cluster lengths on
the log plots. There will be Points correlation times evaluated.
%}
for logT=log0:delt_log:logM
L = int32 ( ( 10.0^logT ) / delt_file ) ;
K=K+1;
CI = 0; %/* cluster index for cluster K */
% increment through data set by cluster length, j is first point of cluster */
j=1;
while j < NM-L
CI=CI+1;
Cdata(1,CI)=0; % initialize sum over cluster */
for i=j:(j+L-1)
Cdata(1,CI)=Cdata(1,CI)+samp_data(1,i); % sum over cluster CI */
end
Cdata(1,CI)=Cdata(1,CI)/double(L); % average value */
j=j+L;
end
% Form adjoining cluster differences and variance. */
dif_sum2=0;
sum=0;
for i=2:CI
% difference squared */
diff=Cdata(1,i)-Cdata(1,i-1);
dif_sum2 = dif_sum2 + (diff^2);
sum=sum+1;
end
Sig(1,K) = sqrt(dif_sum2/(sum-1));
Tau(1,K) = L*delt_file;
Sig_Dif(1,K) = 1.0/sqrt(double(2*(NM/L -1))); %cluster error estimate as a fraction
end