From 1acd107d51b9e6bea98faac2adcc9cf46c3178e7 Mon Sep 17 00:00:00 2001 From: Gastd Date: Thu, 30 Mar 2017 09:44:47 -0300 Subject: [PATCH] Add code for C/A signal generation for glonass --- src/algorithms/libs/CMakeLists.txt | 1 + .../libs/glonass_l1_signal_processing.cc | 131 ++++++++++++++++++ .../libs/glonass_l1_signal_processing.h | 47 +++++++ 3 files changed, 179 insertions(+) create mode 100644 src/algorithms/libs/glonass_l1_signal_processing.cc create mode 100644 src/algorithms/libs/glonass_l1_signal_processing.h diff --git a/src/algorithms/libs/CMakeLists.txt b/src/algorithms/libs/CMakeLists.txt index f0a62912f..7a42ad90e 100644 --- a/src/algorithms/libs/CMakeLists.txt +++ b/src/algorithms/libs/CMakeLists.txt @@ -23,6 +23,7 @@ set(GNSS_SPLIBS_SOURCES gnss_sdr_valve.cc gnss_signal_processing.cc gps_sdr_signal_processing.cc + glonass_l1_signal_processing.cc pass_through.cc galileo_e5_signal_processing.cc complex_byte_to_float_x2.cc diff --git a/src/algorithms/libs/glonass_l1_signal_processing.cc b/src/algorithms/libs/glonass_l1_signal_processing.cc new file mode 100644 index 000000000..ff3ab5a2d --- /dev/null +++ b/src/algorithms/libs/glonass_l1_signal_processing.cc @@ -0,0 +1,131 @@ +/*! + * \file glonass_l1_signal_processing.cc + * \brief This class implements various functions for GLONASS L1 CA signals + * \author Javier Arribas, 2011. jarribas(at)cttc.es + * + * Detailed description of the file here if needed. + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#include "glonass_l1_signal_processing.h" + +auto auxCeil = [](float x){ return static_cast(static_cast((x)+1)); }; + +void glonass_l1_ca_code_gen_complex(std::complex* _dest/*, signed int _prn, unsigned int _chip_shift*/) +{ + const unsigned int _code_length = 511; + bool G1[_code_length]; + bool G1_register[9]; + bool feedback1; + bool aux; + unsigned int lcv, lcv2; + + for(lcv = 0; lcv < 9; lcv++) + { + G1_register[lcv] = 1; + } + + /* Generate G1 Register */ + for(lcv = 0; lcv < _code_length; lcv++) + { + G1[lcv] = G1_register[2]; + + feedback1 = G1_register[4]^G1_register[0]; + + for(lcv2 = 0; lcv2 < 8; lcv2++) + { + G1_register[lcv2] = G1_register[lcv2 + 1]; + } + + G1_register[8] = feedback1; + } + + /* Generate PRN from G1 Register */ + for(lcv = 0; lcv < _code_length; lcv++) + { + aux = G1[lcv]; + if(aux == true) + { + _dest[lcv] = std::complex(1, 0); + } + else + { + _dest[lcv] = std::complex(-1, 0); + } + } +} + + +/* + * Generates complex GLONASS L1 C/A code for the desired SV ID and sampled to specific sampling frequency + */ +void glonass_l1_ca_code_gen_complex_sampled(std::complex* _dest, unsigned int _prn, signed int _fs, unsigned int _chip_shift) +{ + // This function is based on the GNU software GPS for MATLAB in the Kay Borre book + std::complex _code[511]; + signed int _samplesPerCode, _codeValueIndex; + float _ts; + float _tc; + float aux; + const signed int _codeFreqBasis = 511000; //Hz + const signed int _codeLength = 511; + + //--- Find number of samples per spreading code ---------------------------- + _samplesPerCode = static_cast(static_cast(_fs) / static_cast(_codeFreqBasis / _codeLength)); + + //--- Find time constants -------------------------------------------------- + _ts = 1.0 / static_cast(_fs); // Sampling period in sec + _tc = 1.0 / static_cast(_codeFreqBasis); // C/A chip period in sec + glonass_l1_ca_code_gen_complex(_code); //generate C/A code 1 sample per chip + + for (signed int i = 0; i < _samplesPerCode; i++) + { + //=== Digitizing ======================================================= + + //--- Make index array to read C/A code values ------------------------- + // The length of the index array depends on the sampling frequency - + // number of samples per millisecond (because one C/A code period is one + // millisecond). + + // _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 + // chip array (caCode) for the time instances of each sample. + if (i == _samplesPerCode - 1) + { + //--- Correct the last index (due to number rounding issues) ----------- + _dest[i] = _code[_codeLength - 1]; + + } + else + { + _dest[i] = _code[_codeValueIndex]; //repeat the chip -> upsample + } + } +} diff --git a/src/algorithms/libs/glonass_l1_signal_processing.h b/src/algorithms/libs/glonass_l1_signal_processing.h new file mode 100644 index 000000000..b181d68ae --- /dev/null +++ b/src/algorithms/libs/glonass_l1_signal_processing.h @@ -0,0 +1,47 @@ +/*! + * \file glonass_l1_signal_processing.h + * \brief This class implements various functions for GLONASS L1 CA signals + * \author Gabriel Araujo, 2017. gabriel.araujo(at)ieee.org + * + * Detailed description of the file here if needed. + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_GPS_SDR_SIGNAL_PROCESSING_H_ +#define GNSS_SDR_GPS_SDR_SIGNAL_PROCESSING_H_ + +#include + +//!Generates complex GLONASS L1 C/A code for the desired SV ID and code shift, and sampled to specific sampling frequency +void glonass_l1_ca_code_gen_complex(std::complex* _dest/*, signed int _prn, unsigned int _chip_shift*/); + +//! Generates N complex GLONASS L1 C/A codes for the desired SV ID and code shift +void glonass_l1_ca_code_gen_complex_sampled(std::complex* _dest, unsigned int _prn, signed int _fs, unsigned int _chip_shift, unsigned int _ncodes); + +//! Generates complex GLONASS L1 C/A code for the desired SV ID and code shift +void glonass_l1_ca_code_gen_complex_sampled(std::complex* _dest, unsigned int _prn, signed int _fs, unsigned int _chip_shift); + +#endif /* GNSS_SDR_GPS_SDR_SIGNAL_PROCESSING_H_ */