2014-07-23 23:38:58 +00:00
|
|
|
/*!
|
|
|
|
* \file gps_l1_ca_pcps_quicksync_acquisition.cc
|
|
|
|
* \brief Adapts a PCPS acquisition block to an AcquisitionInterface for
|
|
|
|
* GPS L1 C/A signals using the QuickSync Algorithm
|
|
|
|
* \author Damian Miralles, 2014. dmiralles2009@gmail.com
|
|
|
|
*
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2014-07-23 23:38:58 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
2014-07-23 23:38:58 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is a software defined Global Navigation
|
|
|
|
* Satellite Systems receiver
|
|
|
|
*
|
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2014-07-23 23:38:58 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2014-07-23 23:38:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gps_l1_ca_pcps_quicksync_acquisition.h"
|
|
|
|
#include "GPS_L1_CA.h"
|
|
|
|
#include "configuration_interface.h"
|
2018-02-18 17:37:38 +00:00
|
|
|
#include "gnss_sdr_flags.h"
|
2018-12-09 21:00:09 +00:00
|
|
|
#include "gps_sdr_signal_processing.h"
|
|
|
|
#include <boost/math/distributions/exponential.hpp>
|
|
|
|
#include <glog/logging.h>
|
2019-06-29 09:58:08 +00:00
|
|
|
#include <algorithm>
|
2014-07-23 23:38:58 +00:00
|
|
|
|
2020-05-07 19:47:45 +00:00
|
|
|
#if HAS_STD_SPAN
|
|
|
|
#include <span>
|
2020-05-07 21:11:11 +00:00
|
|
|
namespace own = std;
|
2020-05-07 19:47:45 +00:00
|
|
|
#else
|
|
|
|
#include <gsl/gsl>
|
2020-05-07 21:11:11 +00:00
|
|
|
namespace own = gsl;
|
2020-05-07 19:47:45 +00:00
|
|
|
#endif
|
2014-07-23 23:38:58 +00:00
|
|
|
|
|
|
|
GpsL1CaPcpsQuickSyncAcquisition::GpsL1CaPcpsQuickSyncAcquisition(
|
2020-06-29 07:07:41 +00:00
|
|
|
const ConfigurationInterface* configuration,
|
2018-12-02 04:29:11 +00:00
|
|
|
const std::string& role,
|
|
|
|
unsigned int in_streams,
|
|
|
|
unsigned int out_streams) : role_(role),
|
|
|
|
in_streams_(in_streams),
|
|
|
|
out_streams_(out_streams)
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
configuration_ = configuration;
|
2020-07-09 22:37:55 +00:00
|
|
|
const std::string default_item_type("gr_complex");
|
2014-07-23 23:38:58 +00:00
|
|
|
std::string default_dump_filename = "./data/acquisition.dat";
|
|
|
|
|
|
|
|
DLOG(INFO) << "role " << role;
|
|
|
|
|
|
|
|
item_type_ = configuration_->property(role + ".item_type", default_item_type);
|
2018-12-02 04:29:11 +00:00
|
|
|
int64_t fs_in_deprecated = configuration_->property("GNSS-SDR.internal_fs_hz", 2048000);
|
2017-09-02 09:24:44 +00:00
|
|
|
fs_in_ = configuration_->property("GNSS-SDR.internal_fs_sps", fs_in_deprecated);
|
2014-07-23 23:38:58 +00:00
|
|
|
dump_ = configuration_->property(role + ".dump", false);
|
2016-05-06 17:04:55 +00:00
|
|
|
doppler_max_ = configuration->property(role + ".doppler_max", 5000);
|
2019-02-11 20:13:02 +00:00
|
|
|
if (FLAGS_doppler_max != 0)
|
|
|
|
{
|
|
|
|
doppler_max_ = FLAGS_doppler_max;
|
|
|
|
}
|
2014-07-23 23:38:58 +00:00
|
|
|
sampled_ms_ = configuration_->property(role + ".coherent_integration_time_ms", 4);
|
2016-01-05 09:59:37 +00:00
|
|
|
|
2019-09-13 06:56:37 +00:00
|
|
|
// -- Find number of samples per spreading code -------------------------
|
2020-07-09 22:37:55 +00:00
|
|
|
code_length_ = static_cast<unsigned int>(round(fs_in_ / (GPS_L1_CA_CODE_RATE_CPS / GPS_L1_CA_CODE_LENGTH_CHIPS)));
|
2014-07-23 23:38:58 +00:00
|
|
|
|
2019-07-27 09:22:08 +00:00
|
|
|
/* Calculate the folding factor value based on the calculations */
|
2018-12-03 15:25:11 +00:00
|
|
|
auto temp = static_cast<unsigned int>(ceil(sqrt(log2(code_length_))));
|
2014-08-13 18:51:25 +00:00
|
|
|
folding_factor_ = configuration_->property(role + ".folding_factor", temp);
|
2014-07-23 23:38:58 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
if (sampled_ms_ % folding_factor_ != 0)
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
LOG(WARNING) << "QuickSync Algorithm requires a coherent_integration_time"
|
2017-08-18 10:45:47 +00:00
|
|
|
<< " multiple of " << folding_factor_ << "ms, Value entered "
|
|
|
|
<< sampled_ms_ << " ms";
|
2018-03-03 01:03:39 +00:00
|
|
|
if (sampled_ms_ < folding_factor_)
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
2017-08-18 10:45:47 +00:00
|
|
|
sampled_ms_ = static_cast<int>(folding_factor_);
|
2014-07-23 23:38:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-18 10:45:47 +00:00
|
|
|
sampled_ms_ = static_cast<int>(sampled_ms_ / folding_factor_) * folding_factor_;
|
2014-07-23 23:38:58 +00:00
|
|
|
}
|
|
|
|
|
2017-08-18 10:45:47 +00:00
|
|
|
LOG(WARNING) << " Coherent_integration_time of "
|
|
|
|
<< sampled_ms_ << " ms will be used instead.";
|
2014-07-23 23:38:58 +00:00
|
|
|
}
|
2017-08-18 10:45:47 +00:00
|
|
|
|
2016-01-05 09:59:37 +00:00
|
|
|
vector_length_ = code_length_ * sampled_ms_;
|
2014-07-23 23:38:58 +00:00
|
|
|
bit_transition_flag_ = configuration_->property(role + ".bit_transition_flag", false);
|
|
|
|
|
|
|
|
if (!bit_transition_flag_)
|
|
|
|
{
|
|
|
|
max_dwells_ = configuration_->property(role + ".max_dwells", 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
max_dwells_ = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_filename_ = configuration_->property(role + ".dump_filename", default_dump_filename);
|
|
|
|
|
|
|
|
int samples_per_ms = round(code_length_);
|
2019-06-30 02:47:15 +00:00
|
|
|
code_ = std::vector<std::complex<float>>(code_length_);
|
2019-07-27 09:22:08 +00:00
|
|
|
/* Object relevant information for debugging */
|
2015-05-25 16:46:55 +00:00
|
|
|
LOG(INFO) << "Implementation: " << this->implementation()
|
2018-03-03 01:03:39 +00:00
|
|
|
<< ", Vector Length: " << vector_length_
|
|
|
|
<< ", Samples per ms: " << samples_per_ms
|
|
|
|
<< ", Folding factor: " << folding_factor_
|
|
|
|
<< ", Sampled ms: " << sampled_ms_
|
|
|
|
<< ", Code Length: " << code_length_;
|
2014-07-23 23:38:58 +00:00
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
if (item_type_ == "gr_complex")
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
item_size_ = sizeof(gr_complex);
|
|
|
|
acquisition_cc_ = pcps_quicksync_make_acquisition_cc(folding_factor_,
|
2018-06-06 15:25:03 +00:00
|
|
|
sampled_ms_, max_dwells_, doppler_max_, fs_in_,
|
2018-03-03 01:03:39 +00:00
|
|
|
samples_per_ms, code_length_, bit_transition_flag_,
|
|
|
|
dump_, dump_filename_);
|
2014-07-23 23:38:58 +00:00
|
|
|
|
|
|
|
stream_to_vector_ = gr::blocks::stream_to_vector::make(item_size_,
|
2018-03-03 01:03:39 +00:00
|
|
|
code_length_ * folding_factor_);
|
2014-07-23 23:38:58 +00:00
|
|
|
|
|
|
|
DLOG(INFO) << "stream_to_vector_quicksync(" << stream_to_vector_->unique_id() << ")";
|
|
|
|
DLOG(INFO) << "acquisition(" << acquisition_cc_->unique_id() << ")";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-15 17:38:51 +00:00
|
|
|
item_size_ = sizeof(gr_complex);
|
2014-07-23 23:38:58 +00:00
|
|
|
LOG(WARNING) << item_type_ << " unknown acquisition item type";
|
|
|
|
}
|
|
|
|
|
2015-05-15 17:38:51 +00:00
|
|
|
channel_ = 0;
|
2016-05-06 17:04:55 +00:00
|
|
|
threshold_ = 0.0;
|
|
|
|
doppler_step_ = 0;
|
2018-12-02 04:29:11 +00:00
|
|
|
gnss_synchro_ = nullptr;
|
2019-06-28 23:28:30 +00:00
|
|
|
|
2018-06-03 17:11:16 +00:00
|
|
|
if (in_streams_ > 1)
|
|
|
|
{
|
|
|
|
LOG(ERROR) << "This implementation only supports one input stream";
|
|
|
|
}
|
|
|
|
if (out_streams_ > 0)
|
|
|
|
{
|
|
|
|
LOG(ERROR) << "This implementation does not provide an output stream";
|
|
|
|
}
|
2014-07-23 23:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
void GpsL1CaPcpsQuickSyncAcquisition::stop_acquisition()
|
|
|
|
{
|
2020-06-27 07:52:59 +00:00
|
|
|
acquisition_cc_->set_state(0);
|
|
|
|
acquisition_cc_->set_active(false);
|
2018-12-02 04:29:11 +00:00
|
|
|
}
|
|
|
|
|
2019-06-30 02:47:15 +00:00
|
|
|
|
2014-07-23 23:38:58 +00:00
|
|
|
void GpsL1CaPcpsQuickSyncAcquisition::set_threshold(float threshold)
|
|
|
|
{
|
2020-07-09 22:37:55 +00:00
|
|
|
float pfa = configuration_->property(role_ + std::to_string(channel_) + ".pfa", static_cast<float>(0.0));
|
2014-07-23 23:38:58 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
if (pfa == 0.0)
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
2020-07-09 22:37:55 +00:00
|
|
|
pfa = configuration_->property(role_ + ".pfa", static_cast<float>(0.0));
|
2014-07-23 23:38:58 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (pfa == 0.0)
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
threshold_ = threshold;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
threshold_ = calculate_threshold(pfa);
|
|
|
|
}
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
DLOG(INFO) << "Channel " << channel_ << " Threshold = " << threshold_;
|
2014-07-23 23:38:58 +00:00
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
if (item_type_ == "gr_complex")
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
acquisition_cc_->set_threshold(threshold_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GpsL1CaPcpsQuickSyncAcquisition::set_doppler_max(unsigned int doppler_max)
|
|
|
|
{
|
|
|
|
doppler_max_ = doppler_max;
|
2018-12-02 04:29:11 +00:00
|
|
|
if (item_type_ == "gr_complex")
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
acquisition_cc_->set_doppler_max(doppler_max_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GpsL1CaPcpsQuickSyncAcquisition::set_doppler_step(unsigned int doppler_step)
|
|
|
|
{
|
|
|
|
doppler_step_ = doppler_step;
|
2018-12-02 04:29:11 +00:00
|
|
|
if (item_type_ == "gr_complex")
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
acquisition_cc_->set_doppler_step(doppler_step_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GpsL1CaPcpsQuickSyncAcquisition::set_gnss_synchro(Gnss_Synchro* gnss_synchro)
|
|
|
|
{
|
|
|
|
gnss_synchro_ = gnss_synchro;
|
2018-12-02 04:29:11 +00:00
|
|
|
if (item_type_ == "gr_complex")
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
acquisition_cc_->set_gnss_synchro(gnss_synchro_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
signed int GpsL1CaPcpsQuickSyncAcquisition::mag()
|
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
if (item_type_ == "gr_complex")
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
return acquisition_cc_->mag();
|
|
|
|
}
|
2018-12-03 21:08:19 +00:00
|
|
|
return 0;
|
2014-07-23 23:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GpsL1CaPcpsQuickSyncAcquisition::init()
|
|
|
|
{
|
|
|
|
acquisition_cc_->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GpsL1CaPcpsQuickSyncAcquisition::set_local_code()
|
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
if (item_type_ == "gr_complex")
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
2019-07-26 01:51:43 +00:00
|
|
|
std::vector<std::complex<float>> code(code_length_);
|
2014-07-23 23:38:58 +00:00
|
|
|
|
2019-07-26 01:51:43 +00:00
|
|
|
gps_l1_ca_code_gen_complex_sampled(code, gnss_synchro_->PRN, fs_in_, 0);
|
2014-07-23 23:38:58 +00:00
|
|
|
|
2020-05-07 21:11:11 +00:00
|
|
|
own::span<gr_complex> code_span(code_.data(), vector_length_);
|
2019-06-29 19:13:14 +00:00
|
|
|
for (unsigned int i = 0; i < (sampled_ms_ / folding_factor_); i++)
|
2016-01-05 09:59:37 +00:00
|
|
|
{
|
2019-07-26 01:51:43 +00:00
|
|
|
std::copy_n(code.data(), code_length_, code_span.subspan(i * code_length_, code_length_).data());
|
2016-01-05 09:59:37 +00:00
|
|
|
}
|
|
|
|
|
2019-06-30 02:47:15 +00:00
|
|
|
acquisition_cc_->set_local_code(code_.data());
|
2014-07-23 23:38:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GpsL1CaPcpsQuickSyncAcquisition::reset()
|
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
if (item_type_ == "gr_complex")
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
acquisition_cc_->set_active(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-18 12:24:42 +00:00
|
|
|
|
2015-02-10 18:30:15 +00:00
|
|
|
void GpsL1CaPcpsQuickSyncAcquisition::set_state(int state)
|
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
if (item_type_ == "gr_complex")
|
2015-02-10 18:30:15 +00:00
|
|
|
{
|
|
|
|
acquisition_cc_->set_state(state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 23:38:58 +00:00
|
|
|
|
|
|
|
float GpsL1CaPcpsQuickSyncAcquisition::calculate_threshold(float pfa)
|
|
|
|
{
|
2019-07-27 09:22:08 +00:00
|
|
|
// Calculate the threshold
|
2014-07-23 23:38:58 +00:00
|
|
|
unsigned int frequency_bins = 0;
|
2020-07-10 11:35:15 +00:00
|
|
|
for (int doppler = static_cast<int>(-doppler_max_); doppler <= static_cast<int>(doppler_max_); doppler += static_cast<int>(doppler_step_))
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
frequency_bins++;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
DLOG(INFO) << "Channel " << channel_ << " Pfa = " << pfa;
|
2014-09-12 18:23:39 +00:00
|
|
|
unsigned int ncells = (code_length_ / folding_factor_) * frequency_bins;
|
2015-05-15 17:38:51 +00:00
|
|
|
double exponent = 1.0 / static_cast<double>(ncells);
|
2014-07-23 23:38:58 +00:00
|
|
|
double val = pow(1.0 - pfa, exponent);
|
2015-05-15 17:47:41 +00:00
|
|
|
double lambda = static_cast<double>(code_length_) / static_cast<double>(folding_factor_);
|
2018-03-03 01:03:39 +00:00
|
|
|
boost::math::exponential_distribution<double> mydist(lambda);
|
2018-12-03 15:25:11 +00:00
|
|
|
auto threshold = static_cast<float>(quantile(mydist, val));
|
2014-07-23 23:38:58 +00:00
|
|
|
|
|
|
|
return threshold;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GpsL1CaPcpsQuickSyncAcquisition::connect(gr::top_block_sptr top_block)
|
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
if (item_type_ == "gr_complex")
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
top_block->connect(stream_to_vector_, 0, acquisition_cc_, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GpsL1CaPcpsQuickSyncAcquisition::disconnect(gr::top_block_sptr top_block)
|
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
if (item_type_ == "gr_complex")
|
2014-07-23 23:38:58 +00:00
|
|
|
{
|
|
|
|
top_block->disconnect(stream_to_vector_, 0, acquisition_cc_, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gr::basic_block_sptr GpsL1CaPcpsQuickSyncAcquisition::get_left_block()
|
|
|
|
{
|
|
|
|
return stream_to_vector_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gr::basic_block_sptr GpsL1CaPcpsQuickSyncAcquisition::get_right_block()
|
|
|
|
{
|
|
|
|
return acquisition_cc_;
|
|
|
|
}
|