2012-07-12 21:17:37 +00:00
|
|
|
/*!
|
|
|
|
* \file gnss_signal_processing.cc
|
|
|
|
* \brief This library gathers a few functions used by the algorithms of gnss-sdr,
|
|
|
|
* regardless of system used
|
|
|
|
* \author Luis Esteve, 2012. luis(at)epsilon-formacion.com
|
|
|
|
*
|
|
|
|
* Detailed description of the file here if needed.
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2015-01-08 18:49:59 +00:00
|
|
|
* Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
|
2012-07-12 21:17:37 +00:00
|
|
|
*
|
|
|
|
* 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
|
2015-01-08 18:49:59 +00:00
|
|
|
* (at your option) any later version.
|
2012-07-12 21:17:37 +00:00
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gnss_signal_processing.h"
|
2015-05-05 14:14:46 +00:00
|
|
|
#include <gnuradio/fxpt_nco.h>
|
2016-01-10 21:21:31 +00:00
|
|
|
#include "GPS_L1_CA.h"
|
2012-07-12 21:17:37 +00:00
|
|
|
|
|
|
|
|
2015-05-06 08:53:27 +00:00
|
|
|
auto auxCeil2 = [](float x){ return static_cast<int>(static_cast<long>((x)+1)); };
|
|
|
|
|
2012-08-04 08:41:32 +00:00
|
|
|
void complex_exp_gen(std::complex<float>* _dest, double _f, double _fs, unsigned int _samps)
|
|
|
|
{
|
2015-05-05 14:14:46 +00:00
|
|
|
gr::fxpt_nco d_nco;
|
2015-05-05 14:59:34 +00:00
|
|
|
d_nco.set_freq((GPS_TWO_PI * _f) / _fs);
|
2015-05-05 14:14:46 +00:00
|
|
|
d_nco.sincos(_dest, _samps, 1);
|
2012-07-12 21:17:37 +00:00
|
|
|
}
|
|
|
|
|
2012-10-28 12:38:11 +00:00
|
|
|
|
2012-10-18 10:24:41 +00:00
|
|
|
void complex_exp_gen_conj(std::complex<float>* _dest, double _f, double _fs, unsigned int _samps)
|
|
|
|
{
|
2015-05-05 14:14:46 +00:00
|
|
|
gr::fxpt_nco d_nco;
|
|
|
|
d_nco.set_freq(-(GPS_TWO_PI * _f) / _fs);
|
|
|
|
d_nco.sincos(_dest, _samps, 1);
|
2012-10-18 10:24:41 +00:00
|
|
|
}
|
|
|
|
|
2012-07-12 21:17:37 +00:00
|
|
|
void hex_to_binary_converter(int * _dest, char _from)
|
|
|
|
{
|
|
|
|
switch(_from)
|
|
|
|
{
|
|
|
|
case '0':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = 1;
|
|
|
|
*(_dest+1) = 1;
|
|
|
|
*(_dest+2) = 1;
|
|
|
|
*(_dest+3) = 1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case '1':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = 1;
|
|
|
|
*(_dest+1) = 1;
|
|
|
|
*(_dest+2) = 1;
|
|
|
|
*(_dest+3) = -1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case '2':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = 1;
|
|
|
|
*(_dest+1) = 1;
|
|
|
|
*(_dest+2) = -1;
|
|
|
|
*(_dest+3) = 1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case '3':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = 1;
|
|
|
|
*(_dest+1) = 1;
|
|
|
|
*(_dest+2) = -1;
|
|
|
|
*(_dest+3) = -1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case '4':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = 1;
|
|
|
|
*(_dest+1) = -1;
|
|
|
|
*(_dest+2) = 1;
|
|
|
|
*(_dest+3) = 1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case '5':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = 1;
|
|
|
|
*(_dest+1) = -1;
|
|
|
|
*(_dest+2) = 1;
|
|
|
|
*(_dest+3) = -1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case '6':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = 1;
|
|
|
|
*(_dest+1) = -1;
|
|
|
|
*(_dest+2) = -1;
|
|
|
|
*(_dest+3) = 1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case '7':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = 1;
|
|
|
|
*(_dest+1) = -1;
|
|
|
|
*(_dest+2) = -1;
|
|
|
|
*(_dest+3) = -1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case '8':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = -1;
|
|
|
|
*(_dest+1) = 1;
|
|
|
|
*(_dest+2) = 1;
|
|
|
|
*(_dest+3) = 1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case '9':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = -1;
|
|
|
|
*(_dest+1) = 1;
|
|
|
|
*(_dest+2) = 1;
|
|
|
|
*(_dest+3) = -1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case 'A':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = -1;
|
|
|
|
*(_dest+1) = 1;
|
|
|
|
*(_dest+2) = -1;
|
|
|
|
*(_dest+3) = 1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case 'B':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = -1;
|
|
|
|
*(_dest+1) = 1;
|
|
|
|
*(_dest+2) = -1;
|
|
|
|
*(_dest+3) = -1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case 'C':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = -1;
|
|
|
|
*(_dest+1) = -1;
|
|
|
|
*(_dest+2) = 1;
|
|
|
|
*(_dest+3) = 1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case 'D':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = -1;
|
|
|
|
*(_dest+1) = -1;
|
|
|
|
*(_dest+2) = 1;
|
|
|
|
*(_dest+3) = -1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case 'E':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = -1;
|
|
|
|
*(_dest+1) = -1;
|
|
|
|
*(_dest+2) = -1;
|
|
|
|
*(_dest+3) = 1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
case 'F':
|
2012-10-28 12:38:11 +00:00
|
|
|
*(_dest) = -1;
|
|
|
|
*(_dest+1) = -1;
|
|
|
|
*(_dest+2) = -1;
|
|
|
|
*(_dest+3) = -1;
|
2012-07-12 21:17:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-04 11:39:01 +00:00
|
|
|
|
2012-07-12 21:17:37 +00:00
|
|
|
void resampler(std::complex<float>* _from, std::complex<float>* _dest, float _fs_in,
|
2012-10-28 12:38:11 +00:00
|
|
|
float _fs_out, unsigned int _length_in, unsigned int _length_out)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
2012-10-28 12:38:11 +00:00
|
|
|
unsigned int _codeValueIndex;
|
2015-05-06 08:53:27 +00:00
|
|
|
float aux;
|
2012-10-28 12:38:11 +00:00
|
|
|
//--- Find time constants --------------------------------------------------
|
2015-03-16 23:22:20 +00:00
|
|
|
const float _t_in = 1 / _fs_in; // Incoming sampling period in sec
|
|
|
|
const float _t_out = 1 / _fs_out; // Out sampling period in sec
|
|
|
|
for (unsigned int i = 0; i < _length_out - 1; i++)
|
2012-07-12 21:17:37 +00:00
|
|
|
{
|
|
|
|
//=== Digitizing =======================================================
|
2012-08-04 11:39:01 +00:00
|
|
|
//--- compute index array to read sampled values -------------------------
|
2015-05-06 08:53:27 +00:00
|
|
|
//_codeValueIndex = ceil((_t_out * ((float)i + 1)) / _t_in) - 1;
|
|
|
|
aux = (_t_out * (i + 1)) / _t_in;
|
|
|
|
_codeValueIndex = auxCeil2(aux) - 1;
|
|
|
|
|
2014-06-17 17:13:24 +00:00
|
|
|
//if repeat the chip -> upsample by nearest neighborhood interpolation
|
|
|
|
_dest[i] = _from[_codeValueIndex];
|
2012-07-12 21:17:37 +00:00
|
|
|
}
|
2014-06-17 17:13:24 +00:00
|
|
|
//--- Correct the last index (due to number rounding issues) -----------
|
2015-03-16 23:22:20 +00:00
|
|
|
_dest[_length_out - 1] = _from[_length_in - 1];
|
2012-07-12 21:17:37 +00:00
|
|
|
}
|