diff --git a/src/algorithms/libs/glonass_l1_signal_replica.cc b/src/algorithms/libs/glonass_l1_signal_replica.cc index 4895182bf..b0cab18cd 100644 --- a/src/algorithms/libs/glonass_l1_signal_replica.cc +++ b/src/algorithms/libs/glonass_l1_signal_replica.cc @@ -19,8 +19,7 @@ #include "glonass_l1_signal_replica.h" #include #include - -const auto AUX_CEIL = [](float x) { return static_cast(static_cast((x) + 1)); }; +#include void glonass_l1_ca_code_gen_complex(own::span> dest, uint32_t chip_shift) { @@ -104,8 +103,8 @@ void glonass_l1_ca_code_gen_complex_sampled(own::span> dest, // number of samples per millisecond (because one C/A code period is // one millisecond). - aux = (ts * (static_cast(i) + 1)) / tc; - codeValueIndex = AUX_CEIL(aux) - 1; + aux = ts * static_cast(i) / tc; + codeValueIndex = static_cast(std::floor(aux)); // --- Make the digitized version of the C/A code ------------------ // The "upsampled" code is made by selecting values form the CA code diff --git a/src/algorithms/libs/glonass_l2_signal_replica.cc b/src/algorithms/libs/glonass_l2_signal_replica.cc index a7edb55df..1b262213c 100644 --- a/src/algorithms/libs/glonass_l2_signal_replica.cc +++ b/src/algorithms/libs/glonass_l2_signal_replica.cc @@ -19,8 +19,7 @@ #include "glonass_l2_signal_replica.h" #include #include - -const auto AUX_CEIL = [](float x) { return static_cast(static_cast((x) + 1)); }; +#include void glonass_l2_ca_code_gen_complex(own::span> dest, uint32_t chip_shift) { @@ -104,8 +103,8 @@ void glonass_l2_ca_code_gen_complex_sampled(own::span> dest, // number of samples per millisecond (because one C/A code period is // one millisecond). - aux = (ts * (static_cast(i) + 1)) / tc; - codeValueIndex = AUX_CEIL(aux) - 1; + aux = ts * static_cast(i) / tc; + codeValueIndex = static_cast(std::floor(aux)); // --- Make the digitized version of the C/A code ------------------ // The "upsampled" code is made by selecting values form the CA code diff --git a/src/algorithms/libs/gnss_signal_replica.cc b/src/algorithms/libs/gnss_signal_replica.cc index 4a64d56e8..02c1df9d1 100644 --- a/src/algorithms/libs/gnss_signal_replica.cc +++ b/src/algorithms/libs/gnss_signal_replica.cc @@ -19,11 +19,10 @@ #include "gnss_signal_replica.h" #include "MATH_CONSTANTS.h" #include +#include #include // for size_t -const auto AUX_CEIL2 = [](float x) { return static_cast(static_cast((x) + 1)); }; - void complex_exp_gen(own::span> dest, double freq, double sampling_freq) { gr::fxpt_nco d_nco; @@ -258,13 +257,11 @@ void resampler(const own::span from, own::span dest, float fs_in, float fs_out) { uint32_t codeValueIndex; - float aux; const float t_out = 1.0F / fs_out; // Output sampling period const size_t dest_size = dest.size(); for (size_t i = 0; i < dest_size - 1; i++) { - aux = (t_out * (static_cast(i) + 1.0F)) * fs_in; - codeValueIndex = AUX_CEIL2(aux) - 1; + codeValueIndex = static_cast(std::floor(t_out * i * fs_in)); dest[i] = from[codeValueIndex]; } // Correct the last index (due to number rounding issues) @@ -281,8 +278,8 @@ void resampler(own::span> from, own::span(i) + 1.0F)) * fs_in; - codeValueIndex = AUX_CEIL2(aux) - 1; + aux = (t_out * (static_cast(i))) * fs_in; + codeValueIndex = static_cast(std::floor(aux)); dest[i] = from[codeValueIndex]; } // Correct the last index (due to number rounding issues) diff --git a/src/algorithms/libs/gps_l2c_signal_replica.cc b/src/algorithms/libs/gps_l2c_signal_replica.cc index c536be0af..de7df8128 100644 --- a/src/algorithms/libs/gps_l2c_signal_replica.cc +++ b/src/algorithms/libs/gps_l2c_signal_replica.cc @@ -92,7 +92,7 @@ void gps_l2c_m_code_gen_complex_sampled(own::span> dest, uin // === Digitizing ================================================== // --- Make index array to read L2C code values -------------------- - codeValueIndex = std::ceil((ts * (static_cast(i) + 1.0F)) / tc) - 1; + codeValueIndex = static_cast(std::floor(ts * static_cast(i) / tc)); // --- Make the digitized version of the L2C code ------------------ if (i == samplesPerCode - 1) diff --git a/src/algorithms/libs/gps_l5_signal_replica.cc b/src/algorithms/libs/gps_l5_signal_replica.cc index 09a6ac798..1de243ece 100644 --- a/src/algorithms/libs/gps_l5_signal_replica.cc +++ b/src/algorithms/libs/gps_l5_signal_replica.cc @@ -210,7 +210,7 @@ void gps_l5i_code_gen_complex_sampled(own::span> dest, uint3 // === Digitizing ================================================== // --- Make index array to read L5 code values --------------------- - codeValueIndex = static_cast(std::ceil(ts * (i + 1.0F) / tc)) - 1; + codeValueIndex = static_cast(std::floor(ts * static_cast(i) / tc)); // --- Make the digitized version of the L5I code ------------------ if (i == samplesPerCode - 1) diff --git a/src/algorithms/libs/gps_sdr_signal_replica.cc b/src/algorithms/libs/gps_sdr_signal_replica.cc index ba439377f..c006d21f8 100644 --- a/src/algorithms/libs/gps_sdr_signal_replica.cc +++ b/src/algorithms/libs/gps_sdr_signal_replica.cc @@ -19,8 +19,7 @@ #include "gps_sdr_signal_replica.h" #include #include - -const auto AUX_CEIL = [](float x) { return static_cast(static_cast((x) + 1)); }; +#include void gps_l1_ca_code_gen_int(own::span dest, int32_t prn, uint32_t chip_shift) { @@ -144,7 +143,6 @@ void gps_l1_ca_code_gen_complex_sampled(own::span> dest, uin const float ts = 1.0F / static_cast(sampling_freq); // Sampling period in sec std::array, 1023> code_aux{}; int32_t codeValueIndex; - float aux; gps_l1_ca_code_gen_complex(code_aux, prn, chip_shift); // generate C/A code 1 sample per chip @@ -157,8 +155,7 @@ void gps_l1_ca_code_gen_complex_sampled(own::span> dest, uin // number of samples per millisecond (because one C/A code period is one // millisecond). - aux = (ts * (static_cast(i) + 1)) / tc; - codeValueIndex = AUX_CEIL(aux) - 1; + codeValueIndex = static_cast(std::floor(ts * static_cast(i) / tc)); // --- Make the digitized version of the C/A code ------------------- // The "upsampled" code is made by selecting values form the CA code