AllanDeviation.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
44 #ifndef GNSSTK_ALLANDEVIATION_HPP
45 #define GNSSTK_ALLANDEVIATION_HPP
46 
47 #include <vector>
48 #include <cmath>
49 #include <ostream>
50 
51 #include "Exception.hpp"
52 
53 namespace gnsstk
54 {
56 
57 
58 
61  {
62  public:
66  AllanDeviation(std::vector<double>& phase, double tau0)
67  : N(phase.size()-1), numGaps(0)
68  {
69  if(N < 1 )
70  {
71  Exception e("Need more than 2 point to compute a meaningful allan variance.");
72  GNSSTK_THROW(e);
73  }
74 
75  // Actual Overlapping Allan Deviation Calculation is done here
76  // The Overlapping Allan Deviation is calculated as follows
77  // Sigma^2(Tau) = 1 / (2*(N-2*m)*Tau^2) * Sum(X[i+2*m]-2*X[i+m]+X[i], i=1, i=N-2*m)
78  // Where Tau is the averaging time, N is the total number of points, and Tau = m*Tau0
79  // Where Tau0 is the basic measurement interval
80  double sum, sigma;
81  for(int m = 1; m <= (N-1)/2; m++)
82  {
83  double tau = m*tau0;
84  sigma = 0;
85 
86  for(int i = 0; i < (N-2*m); i++)
87  {
88  sum = 0;
89  if((phase[i+2*m]==0 || phase[i+m]==0 || phase[i]==0)
90  && i!=0 && i!=(N-2*m-1))
91  numGaps++;
92  else
93  sum = phase[i+2*m] - 2*phase[i+m] + phase[i];
94  sigma += sum * sum;
95  }
96 
97  sigma = sigma / (2.0*((double)N-(double)numGaps-0-2.0*(double)m)*tau*tau);
98  sigma = ::sqrt(sigma);
99  deviation.push_back(sigma);
100  time.push_back(tau);
101  }
102  }
103 
104  void dump(std::ostream& s = std::cout) const noexcept
105  {
106  std::vector<double>::const_iterator i=deviation.begin(),j=time.begin();
107  for (; i != deviation.end() && j != time.end(); i++,j++)
108  s << *j << " " << *i << std::endl;
109  };
110 
111  const int N;
112  std::vector<double> deviation, time;
113  int numGaps;
114  };
115 
116  std::ostream& operator<<(std::ostream& s, const AllanDeviation& a)
117  {
118  a.dump(s);
119  return s;
120  }
121 
122 } // namespace
123 
124 #endif
gnsstk::AllanDeviation::dump
void dump(std::ostream &s=std::cout) const noexcept
Definition: AllanDeviation.hpp:104
gnsstk::AllanDeviation::N
const int N
Definition: AllanDeviation.hpp:109
gnsstk::AllanDeviation::time
std::vector< double > time
Definition: AllanDeviation.hpp:112
gnsstk::AllanDeviation::numGaps
int numGaps
Definition: AllanDeviation.hpp:113
gnsstk::sum
T sum(const ConstVectorBase< T, BaseClass > &l)
Definition: VectorBaseOperators.hpp:84
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::AllanDeviation::AllanDeviation
AllanDeviation(std::vector< double > &phase, double tau0)
Definition: AllanDeviation.hpp:66
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::operator<<
std::ostream & operator<<(std::ostream &s, const ObsEpoch &oe) noexcept
Definition: ObsEpochMap.cpp:54
gnsstk::AllanDeviation::deviation
std::vector< double > deviation
Definition: AllanDeviation.hpp:112
gnsstk::AllanDeviation
Compute the overlapping Allan variance of the phase data provided.
Definition: AllanDeviation.hpp:60
Exception.hpp
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:38