home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
nisttime.carsoncity.k12.mi.us
/
nisttime.carsoncity.k12.mi.us.tar
/
nisttime.carsoncity.k12.mi.us
/
pub
/
autolock
/
adev.c
next >
Wrap
C/C++ Source or Header
|
2003-12-09
|
2KB
|
48 lines
#include <math.h>
double adev(double y[],int n,int lag)
{
/*
this subroutine computes the approximate Allan
deviation of the frequency data in array y
(as produced by autolock, for example). There
are n points in the array, and the deviation is
computed for lag. The computed value is returned
through the function.
this subroutine assumes that the input data are
equally spaced in time, but it has no way of
checking that this is true.
the input array y represents the frequency averages
for a constant averaging time -- basically one unit
of lag. thus this subroutine is called with a value
of lag >= 1.
if the value of lag is > 1 then the definition of
adev requires frequency estimates that are made using
an averaging time of lag values. if the input array
contain times, then it is a simple matter to compute
the second difference of the input array using points
spaced lag apart. This can't be done for frequency
values however since the input values are always
computed as frequency estimates with unit lag.
*/
double ysum; /*running sum of freq. differences*/
double y1,y2; /*the average frequency over the first and second intervals*/
double yy; /*the difference y2 - y1*/
int npt; /*twice the number of points in ysum*/
int i;
int j;
if(lag > n/4) return(0); /*too big a lag for the array*/
if(lag <= 0) return(0); /*error */
ysum=0;
npt= 0;
for(i=0; i < (n-2*lag); i++) /*the index i points to the 1st point*/
{
y1=y2=0;
for(j=i; j< i+lag; j++) y1 += y[j];
for(j=i+lag; j< i+2*lag; j++) y2 += y[j];
yy= (y2 - y1)/lag;
ysum += yy*yy;
npt += 2; /*add 2 for every point - thus twice number of points*/
}
return(sqrt(ysum/npt));
}