PCSmoother.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: PCSmoother.cpp 1325 2008-07-29 14:33:43Z architest $"
00002 
00009 //============================================================================
00010 //
00011 //  This file is part of GPSTk, the GPS Toolkit.
00012 //
00013 //  The GPSTk is free software; you can redistribute it and/or modify
00014 //  it under the terms of the GNU Lesser General Public License as published
00015 //  by the Free Software Foundation; either version 2.1 of the License, or
00016 //  any later version.
00017 //
00018 //  The GPSTk is distributed in the hope that it will be useful,
00019 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 //  GNU Lesser General Public License for more details.
00022 //
00023 //  You should have received a copy of the GNU Lesser General Public
00024 //  License along with GPSTk; if not, write to the Free Software Foundation,
00025 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 //
00027 //  Dagoberto Salazar - gAGE ( http:// www.gage.es ). 2007, 2008
00028 //
00029 //============================================================================
00030 
00031 
00032 #include "PCSmoother.hpp"
00033 
00034 
00035 namespace gpstk
00036 {
00037 
00038       // Index initially assigned to this class
00039    int PCSmoother::classIndex = 2450000;
00040 
00041 
00042       // Returns an index identifying this object.
00043    int PCSmoother::getIndex() const
00044    { return index; }
00045 
00046 
00047       // Returns a string identifying this object.
00048    std::string PCSmoother::getClassName() const
00049    { return "PCSmoother"; }
00050 
00051 
00052 
00053       /* Returns a satTypeValueMap object, adding the new data generated
00054        * when calling this object.
00055        *
00056        * @param gData     Data object holding the data.
00057        */
00058    satTypeValueMap& PCSmoother::Process(satTypeValueMap& gData)
00059       throw(ProcessingException)
00060    {
00061 
00062       try
00063       {
00064 
00065          double codeObs(0.0);
00066          double phaseObs(0.0);
00067          double flagObs1(0.0);
00068          double flagObs2(0.0);
00069 
00070          SatIDSet satRejectedSet;
00071 
00072             // Loop through all satellites
00073          satTypeValueMap::iterator it;
00074          for (it = gData.begin(); it != gData.end(); ++it)
00075          {
00076 
00077             try
00078             {
00079 
00080                   // Try to extract the values
00081                codeObs  = (*it).second(codeType);
00082                phaseObs = (*it).second(phaseType);
00083 
00084             }
00085             catch(...)
00086             {
00087 
00088                   // If some value is missing, then schedule this satellite
00089                   // for removal
00090                satRejectedSet.insert( (*it).first );
00091 
00092                continue;
00093 
00094             }
00095 
00096             try
00097             {
00098 
00099                   // Try to get the first cycle slip flag
00100                flagObs1  = (*it).second(csFlag1);
00101 
00102             }
00103             catch(...)
00104             {
00105 
00106                   // If flag #1 is not found, no cycle slip is assumed
00107                   // You REALLY want to have BOTH CS flags properly set
00108                flagObs1 = 0.0;
00109 
00110             }
00111 
00112             try
00113             {
00114 
00115                   // Try to get the second cycle slip flag
00116                flagObs2  = (*it).second(csFlag2);
00117 
00118             }
00119             catch(...)
00120             {
00121 
00122                   // If flag #2 is not found, no cycle slip is assumed
00123                   // You REALLY want to have BOTH CS flags properly set
00124                flagObs2 = 0.0;
00125 
00126             }
00127 
00128                // Get the smoothed PC.
00129             (*it).second[resultType] = getSmoothing( (*it).first,
00130                                                      codeObs,
00131                                                      phaseObs,
00132                                                      flagObs1,
00133                                                      flagObs2 );
00134 
00135          }  // End of 'for (it = gData.begin(); it != gData.end(); ++it)'
00136 
00137             // Remove satellites with missing data
00138          gData.removeSatID(satRejectedSet);
00139 
00140          return gData;
00141 
00142       }
00143       catch(Exception& u)
00144       {
00145             // Throw an exception if something unexpected happens
00146          ProcessingException e( getClassName() + ":"
00147                                 + StringUtils::asString( getIndex() ) + ":"
00148                                 + u.what() );
00149 
00150          GPSTK_THROW(e);
00151 
00152       }
00153 
00154    }  // End of method 'PCSmoother::Process()'
00155 
00156 
00157 
00158       /* Method to set the maximum size of filter window, in samples.
00159        *
00160        * @param maxSize       Maximum size of filter window, in samples.
00161        */
00162    PCSmoother& PCSmoother::setMaxWindowSize(const int& maxSize)
00163    {
00164 
00165          // Don't allow window sizes less than 1
00166       if (maxSize > 1)
00167       {
00168          maxWindowSize = maxSize;
00169       }
00170       else
00171       {
00172          maxWindowSize = 1;
00173       }
00174 
00175       return (*this);
00176 
00177    }  // End of method 'PCSmoother::setMaxWindowSize()'
00178 
00179 
00180 
00181       /* Compute the smoothed code observable.
00182        *
00183        * @param sat        Satellite object.
00184        * @param code       Code measurement.
00185        * @param phase      Phase measurement.
00186        * @param flag1      Cycle slip flag in L1.
00187        * @param flag2      Cycle slip flag in L2.
00188        */
00189    double PCSmoother::getSmoothing( const SatID& sat,
00190                                     const double& code,
00191                                     const double& phase,
00192                                     const double& flag1,
00193                                     const double& flag2 )
00194    {
00195 
00196          // In case we have a cycle slip either in L1 or L2
00197       if ( (flag1!=0.0) || (flag2!=0.0) )
00198       {
00199             // Prepare the structure for the next iteration
00200          SmoothingData[sat].previousCode = code;
00201          SmoothingData[sat].previousPhase = phase;
00202          SmoothingData[sat].windowSize = 1;
00203 
00204             // We don't need any further processing
00205          return code;
00206 
00207       }
00208 
00209          // In case we didn't have cycle slip
00210       double smoothedCode(0.0);
00211 
00212          // Increment size of window and check limit
00213       ++SmoothingData[sat].windowSize;
00214       if (SmoothingData[sat].windowSize > maxWindowSize)
00215       {
00216          SmoothingData[sat].windowSize = maxWindowSize;
00217       }
00218 
00219          // The formula used is the following:
00220          //
00221          // CSn = (1/n)*Cn + ((n-1)/n)*(CSn-1 + Ln - Ln-1)
00222          //
00223          // As window size "n" increases, the former formula gives more
00224          // weight to the previous smoothed code CSn-1 plus the phase bias
00225          // (Ln - Ln-1), and less weight to the current code observation Cn
00226       smoothedCode = ( code +
00227                ((static_cast<double>(SmoothingData[sat].windowSize)) - 1.0) *
00228                (SmoothingData[sat].previousCode +
00229                (phase - SmoothingData[sat].previousPhase) ) ) /
00230                (static_cast<double>(SmoothingData[sat].windowSize));
00231 
00232          // Store results for next iteration
00233       SmoothingData[sat].previousCode = smoothedCode;
00234       SmoothingData[sat].previousPhase = phase;
00235 
00236       return smoothedCode;
00237 
00238    }  // End of method 'PCSmoother::getSmoothing()'
00239 
00240 
00241 }  // End of namespace gpstk

Generated on Wed Feb 8 03:31:01 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1