From 4272d4f86f6d3abd99ebd1a9a25e3f44164432e0 Mon Sep 17 00:00:00 2001 From: Dmitry Tatarinov Date: Mon, 22 Feb 2016 14:44:34 +0200 Subject: [PATCH 1/4] Add necessary chanes for L2C track loop --- include/libswiftnav/constants.h | 3 +++ src/bit_sync.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/libswiftnav/constants.h b/include/libswiftnav/constants.h index 2b3c59b5..66c39866 100644 --- a/include/libswiftnav/constants.h +++ b/include/libswiftnav/constants.h @@ -37,6 +37,9 @@ /** The GPS L1 center frequency in Hz. */ #define GPS_L1_HZ 1.57542e9 +/** The GPS L2 center frequency in Hz. */ +#define GPS_L2_HZ 1.2276e9 + /** Earth's rotation rate as defined in the ICD in rad / s * \note This is actually not identical to the usual WGS84 definition. */ #define GPS_OMEGAE_DOT 7.2921151467e-5 diff --git a/src/bit_sync.c b/src/bit_sync.c index 0e226125..100ab526 100755 --- a/src/bit_sync.c +++ b/src/bit_sync.c @@ -28,7 +28,8 @@ /* Table of bit lengths for each code type */ static const u8 bit_length_table[CODE_COUNT] = { [CODE_GPS_L1CA] = BIT_LENGTH_GPS_L1CA, - [CODE_GPS_L2CM] = 0, + [CODE_GPS_L2CM] = BIT_LENGTH_GPS_L1CA, /*same like in L1CA, because + we use 2 symbols per bit*/ [CODE_SBAS_L1CA] = BIT_LENGTH_SBAS_L1CA }; From 5c94c8af44cfe0453c5017c71936a79ebf2897d7 Mon Sep 17 00:00:00 2001 From: Dmitry Tatarinov Date: Mon, 21 Mar 2016 15:25:57 +0200 Subject: [PATCH 2/4] Intermediate commit --- include/libswiftnav/constants.h | 8 ++++---- include/libswiftnav/signal.h | 1 + src/almanac.c | 2 +- src/observation.c | 3 ++- src/pvt.c | 3 ++- src/signal.c | 25 +++++++++++++++++++++++++ src/track.c | 3 ++- 7 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/libswiftnav/constants.h b/include/libswiftnav/constants.h index 66c39866..c3ef59fc 100644 --- a/include/libswiftnav/constants.h +++ b/include/libswiftnav/constants.h @@ -59,14 +59,14 @@ * \note This is GPS_C / mu where mu is 1.0002926 */ #define GPS_C_NO_VAC (GPS_C / 1.0002926) -/** The wavelength of L1 in a vacuum. - * \note This is GPS_C / GPS_L1_HZ. */ -#define GPS_L1_LAMBDA (GPS_C / GPS_L1_HZ) - /** The wavelength of L1 in air at standard temperature and pressure. * \note This is GPS_C_NO_VAC / GPS_L1_HZ. */ #define GPS_L1_LAMBDA_NO_VAC (GPS_C_NO_VAC / GPS_L1_HZ) +/** The wavelength of L2 in air at standard temperature and pressure. + * \note This is GPS_C_NO_VAC / GPS_L2_HZ. */ +#define GPS_L2_LAMBDA_NO_VAC (GPS_C_NO_VAC / GPS_L2_HZ) + /** Approximate average distance to the GPS satellites in m. */ #define GPS_NOMINAL_RANGE 22.980e6 diff --git a/include/libswiftnav/signal.h b/include/libswiftnav/signal.h index 5eb3411b..e2b224ff 100644 --- a/include/libswiftnav/signal.h +++ b/include/libswiftnav/signal.h @@ -98,5 +98,6 @@ gnss_signal_t sid_from_code_index(code_t code, u16 code_index); u16 sid_to_code_index(gnss_signal_t sid); enum constellation sid_to_constellation(gnss_signal_t sid); enum constellation code_to_constellation(code_t code); +double sid_to_carr_freq(gnss_signal_t code); #endif /* LIBSWIFTNAV_SIGNAL_H */ diff --git a/src/almanac.c b/src/almanac.c index b48b990b..4a254ddf 100755 --- a/src/almanac.c +++ b/src/almanac.c @@ -238,7 +238,7 @@ double calc_sat_doppler_almanac(const almanac_t* alm, double t, s16 week, vector_norm(3, vec_ref_sat); /* Return the Doppler shift. */ - return GPS_L1_HZ * radial_velocity / GPS_C; + return sid_to_carr_freq(alm->sid) * radial_velocity / GPS_C; } /** \} */ diff --git a/src/observation.c b/src/observation.c index a77457f5..3e4d96e8 100644 --- a/src/observation.c +++ b/src/observation.c @@ -218,7 +218,8 @@ u8 make_propagated_sdiffs(u8 n_local, navigation_measurement_t *m_local, + dist_diff); sds[n].carrier_phase = m_local[i].carrier_phase - (m_remote[j].carrier_phase - - dist_diff / GPS_L1_LAMBDA); + - dist_diff / + (GPS_C/sid_to_carr_freq(e[i]->sid))); /* Doppler is not propagated. * sds[n].doppler = m_local[i].raw_doppler - m_remote[j].raw_doppler; */ diff --git a/src/pvt.c b/src/pvt.c index 48f3ac91..53cb88ea 100644 --- a/src/pvt.c +++ b/src/pvt.c @@ -49,7 +49,8 @@ static double vel_solve(double rx_vel[], pdot_pred = -vector_dot(3, G[j], nav_meas[j]->sat_vel); /* The residual is due to the user's motion. */ - tempvX[j] = -nav_meas[j]->doppler * GPS_C / GPS_L1_HZ - pdot_pred; + tempvX[j] = -nav_meas[j]->doppler * GPS_C / + sid_to_carr_freq(nav_meas[j]->sid)- pdot_pred; } /* Use X to map our pseudorange rate residuals onto the Jacobian update. diff --git a/src/signal.c b/src/signal.c index 2d10eb0b..f8ce2ae5 100644 --- a/src/signal.c +++ b/src/signal.c @@ -15,6 +15,7 @@ #include #include +#include /** \defgroup signal GNSS signal identifiers (SID) * \{ */ @@ -164,4 +165,28 @@ constellation_t code_to_constellation(code_t code) return code_table[code].constellation; } +/** Return the center carrier frequency for a gnss_signal_t. + * + * \param sid gnss_signal_t to use. + * + * \return center carrier frequency + */ +double sid_to_carr_freq(gnss_signal_t code) +{ + double f; + assert(sid_valid(code)); + switch (code.code) { + case CODE_GPS_L1CA: + case CODE_SBAS_L1CA: + f = GPS_L1_HZ; + break; + case CODE_GPS_L2CM: + f = GPS_L2_HZ; + break; + default: + f = 0.0; + } + return f; +} + /* \} */ diff --git a/src/track.c b/src/track.c index d29c7121..b7c65989 100644 --- a/src/track.c +++ b/src/track.c @@ -802,7 +802,8 @@ void calc_navigation_measurement(u8 n_channels, const channel_measurement_t *mea nav_meas[i]->pseudorange = nav_meas[i]->raw_pseudorange \ + clock_err[i]*GPS_C; - nav_meas[i]->doppler = nav_meas[i]->raw_doppler + clock_rate_err[i]*GPS_L1_HZ; + nav_meas[i]->doppler = nav_meas[i]->raw_doppler + + clock_rate_err[i]*sid_to_carr_freq(nav_meas[i]->sid); nav_meas[i]->tot.tow -= clock_err[i]; normalize_gps_time(&nav_meas[i]->tot); From 4ea19a2af13138412e906ea37f2f3f96cd0ad77f Mon Sep 17 00:00:00 2001 From: Dmitry Tatarinov Date: Tue, 22 Mar 2016 15:49:24 +0200 Subject: [PATCH 3/4] Change sid_to_freq to code_to_freq --- include/libswiftnav/signal.h | 2 +- src/almanac.c | 2 +- src/observation.c | 2 +- src/pvt.c | 2 +- src/signal.c | 6 +++--- src/track.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/libswiftnav/signal.h b/include/libswiftnav/signal.h index e2b224ff..3aeb57ac 100644 --- a/include/libswiftnav/signal.h +++ b/include/libswiftnav/signal.h @@ -98,6 +98,6 @@ gnss_signal_t sid_from_code_index(code_t code, u16 code_index); u16 sid_to_code_index(gnss_signal_t sid); enum constellation sid_to_constellation(gnss_signal_t sid); enum constellation code_to_constellation(code_t code); -double sid_to_carr_freq(gnss_signal_t code); +double code_to_carr_freq(code_t code); #endif /* LIBSWIFTNAV_SIGNAL_H */ diff --git a/src/almanac.c b/src/almanac.c index 4a254ddf..63147ebd 100755 --- a/src/almanac.c +++ b/src/almanac.c @@ -238,7 +238,7 @@ double calc_sat_doppler_almanac(const almanac_t* alm, double t, s16 week, vector_norm(3, vec_ref_sat); /* Return the Doppler shift. */ - return sid_to_carr_freq(alm->sid) * radial_velocity / GPS_C; + return code_to_carr_freq(alm->sid.code) * radial_velocity / GPS_C; } /** \} */ diff --git a/src/observation.c b/src/observation.c index 3e4d96e8..11f743e0 100644 --- a/src/observation.c +++ b/src/observation.c @@ -219,7 +219,7 @@ u8 make_propagated_sdiffs(u8 n_local, navigation_measurement_t *m_local, sds[n].carrier_phase = m_local[i].carrier_phase - (m_remote[j].carrier_phase - dist_diff / - (GPS_C/sid_to_carr_freq(e[i]->sid))); + (GPS_C/code_to_carr_freq(e[i]->sid.code))); /* Doppler is not propagated. * sds[n].doppler = m_local[i].raw_doppler - m_remote[j].raw_doppler; */ diff --git a/src/pvt.c b/src/pvt.c index 53cb88ea..42f8d312 100644 --- a/src/pvt.c +++ b/src/pvt.c @@ -50,7 +50,7 @@ static double vel_solve(double rx_vel[], /* The residual is due to the user's motion. */ tempvX[j] = -nav_meas[j]->doppler * GPS_C / - sid_to_carr_freq(nav_meas[j]->sid)- pdot_pred; + code_to_carr_freq(nav_meas[j]->sid.code)- pdot_pred; } /* Use X to map our pseudorange rate residuals onto the Jacobian update. diff --git a/src/signal.c b/src/signal.c index f8ce2ae5..ffd2059c 100644 --- a/src/signal.c +++ b/src/signal.c @@ -171,11 +171,11 @@ constellation_t code_to_constellation(code_t code) * * \return center carrier frequency */ -double sid_to_carr_freq(gnss_signal_t code) +double code_to_carr_freq(code_t code) { double f; - assert(sid_valid(code)); - switch (code.code) { + assert(code_valid(code)); + switch (code) { case CODE_GPS_L1CA: case CODE_SBAS_L1CA: f = GPS_L1_HZ; diff --git a/src/track.c b/src/track.c index b7c65989..c338375d 100644 --- a/src/track.c +++ b/src/track.c @@ -803,7 +803,7 @@ void calc_navigation_measurement(u8 n_channels, const channel_measurement_t *mea nav_meas[i]->pseudorange = nav_meas[i]->raw_pseudorange \ + clock_err[i]*GPS_C; nav_meas[i]->doppler = nav_meas[i]->raw_doppler + - clock_rate_err[i]*sid_to_carr_freq(nav_meas[i]->sid); + clock_rate_err[i]*code_to_carr_freq(nav_meas[i]->sid.code); nav_meas[i]->tot.tow -= clock_err[i]; normalize_gps_time(&nav_meas[i]->tot); From d29d3a771930d63f4e9b9d658c73328838d43e4d Mon Sep 17 00:00:00 2001 From: Dmitry Tatarinov Date: Wed, 23 Mar 2016 10:37:38 +0200 Subject: [PATCH 4/4] Add code_to_chip_num utility --- include/libswiftnav/constants.h | 4 ---- include/libswiftnav/signal.h | 1 + src/signal.c | 28 ++++++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/libswiftnav/constants.h b/include/libswiftnav/constants.h index c3ef59fc..5a23f6ad 100644 --- a/include/libswiftnav/constants.h +++ b/include/libswiftnav/constants.h @@ -63,10 +63,6 @@ * \note This is GPS_C_NO_VAC / GPS_L1_HZ. */ #define GPS_L1_LAMBDA_NO_VAC (GPS_C_NO_VAC / GPS_L1_HZ) -/** The wavelength of L2 in air at standard temperature and pressure. - * \note This is GPS_C_NO_VAC / GPS_L2_HZ. */ -#define GPS_L2_LAMBDA_NO_VAC (GPS_C_NO_VAC / GPS_L2_HZ) - /** Approximate average distance to the GPS satellites in m. */ #define GPS_NOMINAL_RANGE 22.980e6 diff --git a/include/libswiftnav/signal.h b/include/libswiftnav/signal.h index 3aeb57ac..2945246c 100644 --- a/include/libswiftnav/signal.h +++ b/include/libswiftnav/signal.h @@ -99,5 +99,6 @@ u16 sid_to_code_index(gnss_signal_t sid); enum constellation sid_to_constellation(gnss_signal_t sid); enum constellation code_to_constellation(code_t code); double code_to_carr_freq(code_t code); +u16 code_to_chip_num(code_t code); #endif /* LIBSWIFTNAV_SIGNAL_H */ diff --git a/src/signal.c b/src/signal.c index ffd2059c..e2e14c9b 100644 --- a/src/signal.c +++ b/src/signal.c @@ -165,9 +165,9 @@ constellation_t code_to_constellation(code_t code) return code_table[code].constellation; } -/** Return the center carrier frequency for a gnss_signal_t. +/** Return the center carrier frequency for a code_t. * - * \param sid gnss_signal_t to use. + * \param code code_t to use. * * \return center carrier frequency */ @@ -189,4 +189,28 @@ double code_to_carr_freq(code_t code) return f; } +/** Return the chips number for a code_t. + * + * \param code code_t to use. + * + * \return chips number + */ +u16 code_to_chip_num(code_t code) +{ + u16 cn; + assert(code_valid(code)); + switch (code) { + case CODE_GPS_L1CA: + case CODE_SBAS_L1CA: + cn = 1023; + break; + case CODE_GPS_L2CM: + cn = 10230; + break; + default: + cn = 0; + } + return cn; +} + /* \} */