From b4cfef1a449c5de56d3c0f49389a3cfd1d640864 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 5 May 2015 13:00:24 +0200 Subject: [PATCH] Faster resampler --- .../libs/gps_sdr_signal_processing.cc | 30 ++++++----- src/tests/arithmetic/code_generation_test.cc | 50 +++++++++++++++++++ 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/algorithms/libs/gps_sdr_signal_processing.cc b/src/algorithms/libs/gps_sdr_signal_processing.cc index 5ac0c19b5..714c2dce1 100644 --- a/src/algorithms/libs/gps_sdr_signal_processing.cc +++ b/src/algorithms/libs/gps_sdr_signal_processing.cc @@ -34,11 +34,15 @@ #include #include +auto auxCeil = [](float x){ return static_cast(static_cast((x)+1)); }; void gps_l1_ca_code_gen_complex(std::complex* _dest, signed int _prn, unsigned int _chip_shift) { - bool G1[1023]; - bool G2[1023]; + + + const unsigned int _code_length = 1023; + bool G1[_code_length]; + bool G2[_code_length]; bool G1_register[10], G2_register[10]; bool feedback1, feedback2; bool aux; @@ -47,7 +51,7 @@ void gps_l1_ca_code_gen_complex(std::complex* _dest, signed int _prn, uns signed int prn_idx; /* G2 Delays as defined in GPS-ISD-200D */ - signed int delays[51] = {5 /*PRN1*/, 6, 7, 8, 17, 18, 139, 140, 141, 251, 252, 254 ,255, 256, 257, 258, 469, 470, 471, 472, + const signed int delays[51] = {5 /*PRN1*/, 6, 7, 8, 17, 18, 139, 140, 141, 251, 252, 254 ,255, 256, 257, 258, 469, 470, 471, 472, 473, 474, 509, 512, 513, 514, 515, 516, 859, 860, 861, 862 /*PRN32*/, 145 /*PRN120*/, 175, 52, 21, 237, 235, 886, 657, 634, 762, 355, 1012, 176, 603, 130, 359, 595, 68, 386 /*PRN138*/}; @@ -73,7 +77,7 @@ void gps_l1_ca_code_gen_complex(std::complex* _dest, signed int _prn, uns } /* Generate G1 & G2 Register */ - for(lcv = 0; lcv < 1023; lcv++) + for(lcv = 0; lcv < _code_length; lcv++) { G1[lcv] = G1_register[0]; G2[lcv] = G2_register[0]; @@ -92,14 +96,14 @@ void gps_l1_ca_code_gen_complex(std::complex* _dest, signed int _prn, uns } /* Set the delay */ - delay = 1023 - delays[prn_idx]; + delay = _code_length - delays[prn_idx]; delay += _chip_shift; - delay %= 1023; + delay %= _code_length; /* Generate PRN from G1 and G2 Registers */ - for(lcv = 0; lcv < 1023; lcv++) + for(lcv = 0; lcv < _code_length; lcv++) { - aux = G1[(lcv + _chip_shift) % 1023]^G2[delay]; + aux = G1[(lcv + _chip_shift) % _code_length]^G2[delay]; if(aux == true) { _dest[lcv] = std::complex(1, 0); @@ -109,7 +113,7 @@ void gps_l1_ca_code_gen_complex(std::complex* _dest, signed int _prn, uns _dest[lcv] = std::complex(-1, 0); } delay++; - delay %= 1023; + delay %= _code_length; } } @@ -125,6 +129,7 @@ void gps_l1_ca_code_gen_complex_sampled(std::complex* _dest, unsigned int signed int _samplesPerCode, _codeValueIndex; float _ts; float _tc; + float aux; const signed int _codeFreqBasis = 1023000; //Hz const signed int _codeLength = 1023; @@ -145,7 +150,9 @@ void gps_l1_ca_code_gen_complex_sampled(std::complex* _dest, unsigned int // number of samples per millisecond (because one C/A code period is one // millisecond). - _codeValueIndex = ceil((_ts * ((float)i + 1)) / _tc) - 1; + // _codeValueIndex = ceil((_ts * ((float)i + 1)) / _tc) - 1; + aux = (_ts * (i + 1)) / _tc; + _codeValueIndex = auxCeil( aux ) - 1; //--- Make the digitized version of the C/A code ----------------------- // The "upsampled" code is made by selecting values form the CA code @@ -163,6 +170,3 @@ void gps_l1_ca_code_gen_complex_sampled(std::complex* _dest, unsigned int } } - - - diff --git a/src/tests/arithmetic/code_generation_test.cc b/src/tests/arithmetic/code_generation_test.cc index 0813cadb4..aea2f5079 100644 --- a/src/tests/arithmetic/code_generation_test.cc +++ b/src/tests/arithmetic/code_generation_test.cc @@ -78,3 +78,53 @@ TEST(CodeGenGPSL1_Test, CodeGeneration) } delete _dest2; */ } + + + + +TEST(CodeGenGPSL1Sampled_Test, CodeGeneration) +{ + signed int _prn = 1; + unsigned int _chip_shift = 4; + int _fs = 8000000; + const signed int _codeFreqBasis = 1023000; //Hz + const signed int _codeLength = 1023; + int _samplesPerCode = round(_fs / (_codeFreqBasis / _codeLength)); + std::complex* _dest = new std::complex[_samplesPerCode]; + + int iterations = 10000; + + struct timeval tv; + gettimeofday(&tv, NULL); + long long int begin = tv.tv_sec * 1000000 + tv.tv_usec; + + for(int i = 0; i < iterations; i++) + { + gps_l1_ca_code_gen_complex_sampled( _dest, _prn, _fs, _chip_shift); + } + + gettimeofday(&tv, NULL); + long long int end = tv.tv_sec * 1000000 + tv.tv_usec; + ASSERT_LE(0, end - begin); + std::cout << "Generation completed in " << (end - begin) << " microseconds" << std::endl; + delete[] _dest; + + /* std::complex* _dest2 = new std::complex[_samplesPerCode]; + gettimeofday(&tv, NULL); + long long int begin2 = tv.tv_sec * 1000000 + tv.tv_usec; + + for(int i = 0; i < iterations; i++) + { + gps_l1_ca_code_gen_complex_sampled2( _dest2, _prn, _fs, _chip_shift); + } + + gettimeofday(&tv, NULL); + long long int end2 = tv.tv_sec * 1000000 + tv.tv_usec; + std::cout << "Generation completed in " << (end2 - begin2) << " microseconds (New)" << std::endl; + + for (int j=0; j<_samplesPerCode;j++) + { + if(_dest[j] != _dest2[j]) std::cout << "Error!" << std::endl; + } + delete[] _dest2; */ +}