mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-11-02 16:23:06 +00:00
Faster resampler
This commit is contained in:
@@ -34,11 +34,15 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
auto auxCeil = [](float x){ return static_cast<int>(static_cast<long>((x)+1)); };
|
||||||
|
|
||||||
void gps_l1_ca_code_gen_complex(std::complex<float>* _dest, signed int _prn, unsigned int _chip_shift)
|
void gps_l1_ca_code_gen_complex(std::complex<float>* _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 G1_register[10], G2_register[10];
|
||||||
bool feedback1, feedback2;
|
bool feedback1, feedback2;
|
||||||
bool aux;
|
bool aux;
|
||||||
@@ -47,7 +51,7 @@ void gps_l1_ca_code_gen_complex(std::complex<float>* _dest, signed int _prn, uns
|
|||||||
signed int prn_idx;
|
signed int prn_idx;
|
||||||
|
|
||||||
/* G2 Delays as defined in GPS-ISD-200D */
|
/* 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*/,
|
473, 474, 509, 512, 513, 514, 515, 516, 859, 860, 861, 862 /*PRN32*/,
|
||||||
145 /*PRN120*/, 175, 52, 21, 237, 235, 886, 657, 634, 762,
|
145 /*PRN120*/, 175, 52, 21, 237, 235, 886, 657, 634, 762,
|
||||||
355, 1012, 176, 603, 130, 359, 595, 68, 386 /*PRN138*/};
|
355, 1012, 176, 603, 130, 359, 595, 68, 386 /*PRN138*/};
|
||||||
@@ -73,7 +77,7 @@ void gps_l1_ca_code_gen_complex(std::complex<float>* _dest, signed int _prn, uns
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Generate G1 & G2 Register */
|
/* Generate G1 & G2 Register */
|
||||||
for(lcv = 0; lcv < 1023; lcv++)
|
for(lcv = 0; lcv < _code_length; lcv++)
|
||||||
{
|
{
|
||||||
G1[lcv] = G1_register[0];
|
G1[lcv] = G1_register[0];
|
||||||
G2[lcv] = G2_register[0];
|
G2[lcv] = G2_register[0];
|
||||||
@@ -92,14 +96,14 @@ void gps_l1_ca_code_gen_complex(std::complex<float>* _dest, signed int _prn, uns
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set the delay */
|
/* Set the delay */
|
||||||
delay = 1023 - delays[prn_idx];
|
delay = _code_length - delays[prn_idx];
|
||||||
delay += _chip_shift;
|
delay += _chip_shift;
|
||||||
delay %= 1023;
|
delay %= _code_length;
|
||||||
|
|
||||||
/* Generate PRN from G1 and G2 Registers */
|
/* 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)
|
if(aux == true)
|
||||||
{
|
{
|
||||||
_dest[lcv] = std::complex<float>(1, 0);
|
_dest[lcv] = std::complex<float>(1, 0);
|
||||||
@@ -109,7 +113,7 @@ void gps_l1_ca_code_gen_complex(std::complex<float>* _dest, signed int _prn, uns
|
|||||||
_dest[lcv] = std::complex<float>(-1, 0);
|
_dest[lcv] = std::complex<float>(-1, 0);
|
||||||
}
|
}
|
||||||
delay++;
|
delay++;
|
||||||
delay %= 1023;
|
delay %= _code_length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,6 +129,7 @@ void gps_l1_ca_code_gen_complex_sampled(std::complex<float>* _dest, unsigned int
|
|||||||
signed int _samplesPerCode, _codeValueIndex;
|
signed int _samplesPerCode, _codeValueIndex;
|
||||||
float _ts;
|
float _ts;
|
||||||
float _tc;
|
float _tc;
|
||||||
|
float aux;
|
||||||
const signed int _codeFreqBasis = 1023000; //Hz
|
const signed int _codeFreqBasis = 1023000; //Hz
|
||||||
const signed int _codeLength = 1023;
|
const signed int _codeLength = 1023;
|
||||||
|
|
||||||
@@ -145,7 +150,9 @@ void gps_l1_ca_code_gen_complex_sampled(std::complex<float>* _dest, unsigned int
|
|||||||
// number of samples per millisecond (because one C/A code period is one
|
// number of samples per millisecond (because one C/A code period is one
|
||||||
// millisecond).
|
// 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 -----------------------
|
//--- Make the digitized version of the C/A code -----------------------
|
||||||
// The "upsampled" code is made by selecting values form the CA 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<float>* _dest, unsigned int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -78,3 +78,53 @@ TEST(CodeGenGPSL1_Test, CodeGeneration)
|
|||||||
}
|
}
|
||||||
delete _dest2; */
|
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<float>* _dest = new std::complex<float>[_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<float>* _dest2 = new std::complex<float>[_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; */
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user