11"""
22This module performs operations associated with calculating the Allan variance.
33
4+ Adapted from allantools https://github.com/aewallin/allantools
45"""
56
67import numpy as np
78import scipy
89
910def m_generator (N ,taus = 'octave' ):
11+ """
12+ Generates averaging factor for calculating Allan variance.
13+
14+ Parameters
15+ ----------
16+ N : int
17+ Number of points in trajectory
18+ taus : str, optional
19+ Type of sampling, by default 'octave'
20+
21+ Returns
22+ -------
23+ m : np.array
24+ Averaging factor.
25+ """
1026 assert taus in ['all' ,'octave' ,'decade' ], "taus must be either all, octave, or decade."
1127 if taus == 'all' :
1228 # all-tau sampling not particularly useful but why not?
@@ -47,16 +63,14 @@ def avar(data,rate = 1.0,taus = 'octave', overlapping = True, edf = 'approx'):
4763
4864 Returns
4965 -------
66+ (taus,edfs,oavs) : tuple
67+ Array of computed values.
5068 taus : array
5169 Observation times.
5270 edfs : array
5371 Equivalent degrees of freedom.
5472 oavs : array
5573 Allan variance.
56-
57- Notes
58- -----
59- Adapted from Allantools
6074 """
6175 assert type (overlapping ) == bool , 'overlapping keyword argument should be a boolean.'
6276 assert edf in ['approx' ,'real' ], 'edf keyword argument should be approx or real.'
@@ -110,10 +124,17 @@ def totvar(data, rate=1.0, taus='octave',edf = 'approx'):
110124 The sampling rate for phase or frequency, in Hz
111125 taus: np.array
112126 Array of tau values for which to compute measurement
113-
114- Notes
115- -----
116- Adapted from Allantools
127+
128+ Returns
129+ -------
130+ (taus,edfs,tvars): tuple
131+ Arrays of compute values.
132+ taus : np.array
133+ Observation times.
134+ edfs : np.array
135+ Equivalent degrees of freedom.
136+ tvars : np.array
137+ Total variances.
117138 """
118139 rate = float (rate )
119140 data = np .asarray (data ) # make sure data is an array, not a series or list
@@ -204,6 +225,13 @@ def noise_id(x,af, dmin = 0, dmax = 2):
204225 alpha : float
205226 float power-law noise
206227
228+ References
229+ ----------
230+ Power law noise identification using the lag 1 autocorrelation
231+ Riley,W.J. et al.
232+ 18th European Frequency and Time Forum (EFTF 2004)
233+ https://ieeexplore.ieee.org/document/5075021
234+
207235 """
208236 # Split time series into average positions of nonoverlapping bins
209237 N = len (x )
@@ -252,21 +280,11 @@ def edf_greenhall(alpha, d, m, N,
252280 -------
253281 edf: float
254282 Equivalent degrees of freedom
283+ References
284+ ----------
255285 Greenhall, Riley, 2004
256286 https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/20050061319.pdf
257287 UNCERTAINTY OF STABILITY VARIANCES BASED ON FINITE DIFFERENCES
258- Notes
259- -----
260- Adapted from allantools https://github.com/aewallin/allantools
261-
262- Used for the following deviations
263- (see http://www.wriley.com/CI2.pdf page 8)
264- adev()
265- oadev()
266- mdev()
267- tdev()
268- hdev()
269- ohdev()
270288 """
271289
272290 if modified :
@@ -418,8 +436,7 @@ def greenhall_sz(t, F, alpha, d):
418436 assert (0 ) # ERROR
419437
420438def greenhall_sx (t , F , alpha ):
421- """ Eqn (8) from Greenhall2004
422- """
439+ """ Eqn (8) from Greenhall2004 """
423440 if F == float ('inf' ):
424441 return greenhall_sw (t , alpha + 2 )
425442 a = 2 * greenhall_sw (t , alpha )
@@ -430,9 +447,7 @@ def greenhall_sx(t, F, alpha):
430447
431448
432449def greenhall_sw (t , alpha ):
433- """
434- Eqn (7) from Greenhall2004
435- """
450+ """ Eqn (7) from Greenhall2004 """
436451 alpha = int (alpha )
437452 if alpha == 2 :
438453 return - np .abs (t )
@@ -548,17 +563,17 @@ def edf_simple(N, m, alpha, pedantic = False):
548563 'rf' returns random walk frequency noise. alpha=-2
549564 If the input is not recognized, it defaults to idealized, uncorrelated
550565 noise with (N-1) degrees of freedom.
566+ Returns
567+ -------
568+ edf : float
569+ Equivalent degrees of freedom
551570 Notes
552571 -----
553572 S. Stein, Frequency and Time - Their Measurement and
554573 Characterization. Precision Frequency Control Vol 2, 1985, pp 191-416.
555574 http://tf.boulder.nist.gov/general/pdf/666.pdf
556575
557- Modified from allantools.
558- Returns
559- -------
560- edf : float
561- Equivalent degrees of freedom
576+
562577 """
563578
564579 N = float (N )
@@ -605,14 +620,15 @@ def edf_approx(N,mj):
605620
606621 Parameters
607622 ----------
608- N : [type]
609- [description]
610- mj : [type]
611- [description]
623+ N : int
624+ Number of bead trajectory points.
625+ mj : int
626+ Averaging factor
612627
613628 Returns
614629 -------
615- [type]
616- [description]
630+ edf : float
631+ Equivalent degrees of freedom
617632 """
618- return N // mj - 1
633+ edf = N // mj - 1
634+ return edf
0 commit comments