AllanDeviation.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: AllanDeviation.hpp 1209 2008-04-22 03:45:34Z ocibu $"
00002 //============================================================================
00003 //
00004 //  This file is part of GPSTk, the GPS Toolkit.
00005 //
00006 //  The GPSTk is free software; you can redistribute it and/or modify
00007 //  it under the terms of the GNU Lesser General Public License as published
00008 //  by the Free Software Foundation; either version 2.1 of the License, or
00009 //  any later version.
00010 //
00011 //  The GPSTk is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU Lesser General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU Lesser General Public
00017 //  License along with GPSTk; if not, write to the Free Software Foundation,
00018 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //  
00020 //  Copyright 2004, The University of Texas at Austin
00021 //
00022 //============================================================================
00028 #ifndef GPSTK_ALLANDEVIATION_HPP
00029 #define GPSTK_ALLANDEVIATION_HPP
00030 
00031 #include <vector>
00032 #include <cmath>
00033 #include <ostream>
00034 
00035 #include "Exception.hpp"
00036 
00037 namespace gpstk
00038 {
00041 
00042    
00044    class AllanDeviation
00045    {
00046    public:
00047       AllanDeviation(std::vector<double>& phase, double tau0) throw(Exception)
00048          : N(phase.size()-1), numGaps(0)
00049       {
00050          if(N < 1 )
00051          {
00052             Exception e("Need more than 2 point to compute a meaningful allan variance.");
00053             GPSTK_THROW(e);
00054          }
00055 
00056          // Actual Overlapping Allan Deviation Calculation is done here
00057          // The Overlapping Allan Deviation is calculated as follows
00058          //  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)
00059          //  Where Tau is the averaging time, N is the total number of points, and Tau = m*Tau0
00060          //  Where Tau0 is the basic measurement interval       
00061          double sum, sigma;
00062          for(int m = 1; m <= (N-1)/2; m++)
00063          {
00064             double tau = m*tau0;
00065             sigma = 0;
00066             
00067             for(int i = 0; i < (N-2*m); i++)
00068             {
00069                sum = 0;
00070                if((phase[i+2*m]==0 ||  phase[i+m]==0 || phase[i]==0) 
00071                   && i!=0 && i!=(N-2*m-1))
00072                   numGaps++;
00073                else
00074                   sum = phase[i+2*m] - 2*phase[i+m] + phase[i];
00075                sigma += sum * sum;
00076             }
00077                 
00078             sigma = sigma / (2.0*((double)N-(double)numGaps-0-2.0*(double)m)*tau*tau);
00079             sigma = sqrt(sigma);
00080             deviation.push_back(sigma);
00081             time.push_back(tau);
00082          }
00083       }
00084 
00085       void dump(std::ostream& s = std::cout) const throw()
00086       {
00087          std::vector<double>::const_iterator i=deviation.begin(),j=time.begin();
00088          for (; i != deviation.end() && j != time.end(); i++,j++)
00089             s << *j << "  " << *i << std::endl;
00090       };
00091 
00092       const int N;
00093       std::vector<double> deviation, time;
00094       int numGaps;
00095    };
00096 
00097    std::ostream& operator<<(std::ostream& s, const AllanDeviation& a)
00098    {
00099       a.dump(s);
00100       return s;
00101    }
00102 
00103 }  // namespace
00104 
00105 #endif

Generated on Thu Jul 29 03:30:50 2010 for GPS ToolKit Software Library by  doxygen 1.3.9.1