Skip to content

Commit

Permalink
Float carrier phase for RTK simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
osqzss committed Dec 2, 2017
1 parent 398274a commit e467402
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
28 changes: 22 additions & 6 deletions gpssim.c
Expand Up @@ -1618,9 +1618,12 @@ int allocateChannel(channel_t *chan, ephem_t *eph, ionoutc_t ionoutc, gpstime_t
r_ref = rho.range;

phase_ini = (2.0*r_ref - r_xyz)/LAMBDA_L1;
#ifdef FLOAT_CARR_PHASE
chan[i].carr_phase = phase_ini - floor(phase_ini);
#else
phase_ini -= floor(phase_ini);
chan[i].carr_phase = (unsigned int)(512 * 65536.0 * phase_ini);

chan[i].carr_phase = (unsigned int)(512.0 * 65536.0 * phase_ini);
#endif
// Done.
break;
}
Expand Down Expand Up @@ -2153,8 +2156,9 @@ int main(int argc, char *argv[])

// Update code phase and data bit counters
computeCodePhase(&chan[i], rho, 0.1);
chan[i].carr_phasestep = (int)(512 * 65536.0 * chan[i].f_carr * delt);

#ifndef FLOAT_CARR_PHASE
chan[i].carr_phasestep = (int)round(512.0 * 65536.0 * chan[i].f_carr * delt);
#endif
// Path loss
path_loss = 20200000.0/rho.d;

Expand All @@ -2176,8 +2180,11 @@ int main(int argc, char *argv[])
{
if (chan[i].prn>0)
{
iTable = (chan[i].carr_phase >> 16) & 511;

#ifdef FLOAT_CARR_PHASE
iTable = (int)floor(chan[i].carr_phase*512.0);
#else
iTable = (chan[i].carr_phase >> 16) & 0x1ff; // 9-bit index
#endif
ip = chan[i].dataBit * chan[i].codeCA * cosTable512[iTable] * gain[i];
qp = chan[i].dataBit * chan[i].codeCA * sinTable512[iTable] * gain[i];

Expand Down Expand Up @@ -2218,7 +2225,16 @@ int main(int argc, char *argv[])
chan[i].codeCA = chan[i].ca[(int)chan[i].code_phase]*2-1;

// Update carrier phase
#ifdef FLOAT_CARR_PHASE
chan[i].carr_phase += chan[i].f_carr * delt;

if (chan[i].carr_phase >= 1.0)
chan[i].carr_phase -= 1.0;
else if (chan[i].carr_phase<0.0)
chan[i].carr_phase += 1.0;
#else
chan[i].carr_phase += chan[i].carr_phasestep;
#endif
}
}

Expand Down
6 changes: 6 additions & 0 deletions gpssim.h
@@ -1,6 +1,8 @@
#ifndef GPSSIM_H
#define GPSSIM_H

#define FLOAT_CARR_PHASE // For RKT simulation. Higher computational load, but smoother carrier phase.

#define TRUE (1)
#define FALSE (0)

Expand Down Expand Up @@ -159,8 +161,12 @@ typedef struct
int ca[CA_SEQ_LEN]; /*< C/A Sequence */
double f_carr; /*< Carrier frequency */
double f_code; /*< Code frequency */
#ifdef FLOAT_CARR_PHASE
double carr_phase;
#else
unsigned int carr_phase; /*< Carrier phase */
int carr_phasestep; /*< Carrier phasestep */
#endif
double code_phase; /*< Code phase */
gpstime_t g0; /*!< GPS time at start */
unsigned long sbf[5][N_DWRD_SBF]; /*!< current subframe */
Expand Down

0 comments on commit e467402

Please sign in to comment.