allanvar

This module performs operations associated with calculating the Allan variance.

Adapted from allantools https://github.com/aewallin/allantools.

tweezepy.allanvar.avar(data, rate=1.0, taus='octave', overlapping=True, edf='approx')

Calculates the standard and overlapping Allan variance. Takes an array of bead positions. Returns the taus, edfs, and oavs.

\[\sigma^2_{AV}(\tau) = { 1 \over 2 (m \tau_s )^2 (N-2m+1) } \sum_{n=0}^{N-2m} ( {z}_{n+2m} - 2z_{n+1m} + z_{n} )^2\]

where \(z_1=0\), n=1,…,N, and

\[z_n = {1 \over m_k} \sum_{j=1}^{j-1} x_j\]

where \(\sigma^2_x(m\tau_s)\) is the Allan variance at an averaging time of \(\tau=m_k\tau_s\), and \(x_j\) is the time-series of bead positions, spaced by the measurement interval \(\tau_s\), with length \(N\).

Parameters
  • data (array-like) – 1-D array of bead positions in nm.

  • rate (float) – Frequency of acquisition in Hz.

Returns

  • (taus, edfs, oavs) (tuple) – Tuple of computed values.

  • taus (array) – Observation times.

  • edfs (array) – Equivalent degrees of freedom.

  • oavs (array) – Computed Allan variance for each tau value.

tweezepy.allanvar.edf_approx(N, mj)

Approximate edf based on the number of nonoverlapping bins.

Parameters
  • N (int) – Number of bead trajectory points.

  • mj (int) – Averaging factor

Returns

edf – Equivalent degrees of freedom

Return type

int

References

Power spectrum and Allan variance methods for calibrating single-molecule video-tracking instruments. Lansdorp, B.M. and Saleh, O.A. Review of Scientific Instruments (2012) https://doi.org/10.1063/1.3687431

tweezepy.allanvar.edf_greenhall(alpha, d, m, N, overlapping=False, modified=False, verbose=False)

Returns equivalent degrees of freedom

Parameters
  • alpha (int) – noise type, +2…-4

  • d (int) – 1 first-difference variance 2 Allan variance 3 Hadamard variance require alpha+2*d>1

  • m (int) – averaging factor tau = m*tau0 = m*(1/rate)

  • N (int) – number of phase observations (length of time-series)

  • overlapping (bool) – True for oadev, ohdev

  • modified (bool) – True for mdev, tdev

Returns

edf – Equivalent degrees of freedom

Return type

float

References

Greenhall, Riley, 2004 https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/20050061319.pdf UNCERTAINTY OF STABILITY VARIANCES BASED ON FINITE DIFFERENCES

tweezepy.allanvar.edf_simple(N, m, alpha, pedantic=False)

Equivalent degrees of freedom. Simple approximate formulae.

Parameters
  • N (int) – the number of phase samples

  • m (int) – averaging factor, tau = m * tau0

  • alpha (int) – exponent of f for the frequency PSD: ‘wp’ returns white phase noise. alpha=+2 ‘wf’ returns white frequency noise. alpha= 0 ‘fp’ returns flicker phase noise. alpha=+1 ‘ff’ returns flicker frequency noise. alpha=-1 ‘rf’ returns random walk frequency noise. alpha=-2 If the input is not recognized, it defaults to idealized, uncorrelated noise with (N-1) degrees of freedom.

Returns

edf – Equivalent degrees of freedom

Return type

float

References

S. Stein, Frequency and Time - Their Measurement and Characterization. Precision Frequency Control Vol 2, 1985, pp 191-416. http://tf.boulder.nist.gov/general/pdf/666.pdf

tweezepy.allanvar.edf_totdev(N, m, alpha)

Equivalent degrees of freedom for Total Deviation NIST SP1065 page 41, Table 7

tweezepy.allanvar.greenhall_BasicSum(J, M, S, F, alpha, d)

Eqn (10) from Greenhall2004

tweezepy.allanvar.greenhall_sw(t, alpha)

Eqn (7) from Greenhall2004

tweezepy.allanvar.greenhall_sx(t, F, alpha)

Eqn (8) from Greenhall2004

tweezepy.allanvar.greenhall_sz(t, F, alpha, d)

Eqn (9) from Greenhall2004

tweezepy.allanvar.greenhall_table1(alpha, d)

Table 1 from Greenhall 2004

tweezepy.allanvar.greenhall_table2(alpha, d)

Table 2 from Greenhall 2004

tweezepy.allanvar.greenhall_table3(alpha, d)

Table 3 from Greenhall 2004

tweezepy.allanvar.m_generator(N, taus='octave')

Generates averaging factor for calculating Allan variance.

Parameters
  • N (int) – Number of points in trajectory

  • taus (str, optional) – Type of sampling, by default ‘octave’

Returns

m – Averaging factor.

Return type

np.array

tweezepy.allanvar.noise_id(x, af, dmin=0, dmax=2)

Lag1 autocorrelation algorithm for determining powerlaw noise type.

Parameters
  • x (numpy.array) – trace

  • af (int) – averaging factor

  • dmin (int, optional) – minimum number of differentiations, by default 0

  • dmax (int, optional) – maximum number of differentiations, by default 2

Returns

  • (alpha_int,alpha) (tuple) – [description]

  • alpha_int (int) – integer power-law noise

  • alpha (float) – float power-law noise

References

Power law noise identification using the lag 1 autocorrelation Riley,W.J. et al. 18th European Frequency and Time Forum (EFTF 2004) https://ieeexplore.ieee.org/document/5075021

tweezepy.allanvar.totvar(data, rate=1.0, taus='octave', edf='approx')
Total variance.

Better confidence at long averages for Allan variance.

\[\sigma^2_{AV}( m\tau_s ) = { 1 \over 2 (m\tau_s)^2 (N-2) } \sum_{n=2}^{N-1} ( {x}^*_{n-m} - 2x^*_{j} + x^*_{n+m} )^2\]

where \(x^*_n\) is a new time-series of length \(3N-4\) derived from the original time-series \(x_n\) of length \(N\) by reflection at both ends.

Parameters
  • data (np.array) – Bead positions in nm.

  • rate (float) – The sampling rate for the bead positions in Hz.

  • taus (str or np.array) – Taus spacing, options are decade, octave, or all. Alternatively, an array of tau values can be given directly.

Returns

  • (taus,edfs,tvars) (tuple) – Arrays of compute values.

  • taus (np.array) – Observation times.

  • edfs (np.array) – Equivalent degrees of freedom.

  • tvars (np.array) – Total variances.

References

Total variance as an exact analysis of the sample variance Percival, D.B and Howe, D.A. Proccedings of the 1995 IEEE International Frequency Control Symposium https://doi.org/10.1109/FREQ.1995.483917