2013-08-28 17:17:57 +00:00
|
|
|
/*!
|
|
|
|
* \file pcps_tong_acquisition_cc.h
|
|
|
|
* \brief This class implements a Parallel Code Phase Search Acquisition with
|
|
|
|
* Tong algorithm.
|
|
|
|
* \author Marc Molina, 2013. marc.molina.pena(at)gmail.com
|
|
|
|
*
|
|
|
|
* Acquisition strategy (Kaplan book + CFAR threshold).
|
|
|
|
* <ol>
|
|
|
|
* <li> Compute the input signal power estimation.
|
|
|
|
* <li> Doppler serial search loop.
|
|
|
|
* <li> Perform the FFT-based circular convolution (parallel time search).
|
|
|
|
* <li> Compute the tests statistics for all the cells.
|
|
|
|
* <li> Accumulate the grid of tests statistics with the previous grids.
|
|
|
|
* <li> Record the maximum peak and the associated synchronization parameters.
|
|
|
|
* <li> Compare the maximum averaged test statistics with a threshold.
|
|
|
|
* <li> If the test statistics exceeds the threshold, increment the Tong counter.
|
|
|
|
* <li> Otherwise, decrement the Tong counter.
|
|
|
|
* <li> If the Tong counter is equal to a given maximum value, declare positive
|
2016-05-06 17:04:55 +00:00
|
|
|
* <li> acquisition. If the Tong counter is equal to zero, declare negative
|
2013-08-28 17:17:57 +00:00
|
|
|
* <li> acquisition. Otherwise, process the next block.
|
|
|
|
* </ol>
|
|
|
|
*
|
|
|
|
* Kaplan book: D.Kaplan, J.Hegarty, "Understanding GPS. Principles
|
|
|
|
* and Applications", Artech House, 2006, pp 223-227
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2018-05-13 20:49:11 +00:00
|
|
|
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
|
2013-08-28 17:17:57 +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.
|
2013-08-28 17:17:57 +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
|
2018-05-13 20:49:11 +00:00
|
|
|
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
|
2013-08-28 17:17:57 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pcps_tong_acquisition_cc.h"
|
2018-03-03 01:03:39 +00:00
|
|
|
#include "GPS_L1_CA.h" // for GPS_TWO_PI
|
2018-12-09 21:00:09 +00:00
|
|
|
#include "control_message_factory.h"
|
2013-08-28 17:17:57 +00:00
|
|
|
#include <glog/logging.h>
|
2014-01-14 23:22:54 +00:00
|
|
|
#include <gnuradio/io_signature.h>
|
2013-08-28 17:17:57 +00:00
|
|
|
#include <volk/volk.h>
|
2016-03-20 00:45:01 +00:00
|
|
|
#include <volk_gnsssdr/volk_gnsssdr.h>
|
2018-02-26 02:15:53 +00:00
|
|
|
#include <sstream>
|
2018-12-03 18:01:47 +00:00
|
|
|
#include <utility>
|
2013-08-28 17:17:57 +00:00
|
|
|
|
|
|
|
using google::LogMessage;
|
|
|
|
|
|
|
|
pcps_tong_acquisition_cc_sptr pcps_tong_make_acquisition_cc(
|
2018-12-08 17:49:31 +00:00
|
|
|
uint32_t sampled_ms,
|
|
|
|
uint32_t doppler_max,
|
|
|
|
int64_t fs_in,
|
|
|
|
int32_t samples_per_ms,
|
|
|
|
int32_t samples_per_code,
|
|
|
|
uint32_t tong_init_val,
|
|
|
|
uint32_t tong_max_val,
|
|
|
|
uint32_t tong_max_dwells,
|
2018-03-03 01:03:39 +00:00
|
|
|
bool dump, std::string dump_filename)
|
2013-08-28 17:17:57 +00:00
|
|
|
{
|
|
|
|
return pcps_tong_acquisition_cc_sptr(
|
2018-06-06 15:25:03 +00:00
|
|
|
new pcps_tong_acquisition_cc(sampled_ms, doppler_max, fs_in, samples_per_ms, samples_per_code,
|
2018-12-03 18:01:47 +00:00
|
|
|
tong_init_val, tong_max_val, tong_max_dwells, dump, std::move(dump_filename)));
|
2013-08-28 17:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pcps_tong_acquisition_cc::pcps_tong_acquisition_cc(
|
2018-12-08 17:49:31 +00:00
|
|
|
uint32_t sampled_ms,
|
|
|
|
uint32_t doppler_max,
|
|
|
|
int64_t fs_in,
|
|
|
|
int32_t samples_per_ms,
|
|
|
|
int32_t samples_per_code,
|
|
|
|
uint32_t tong_init_val,
|
|
|
|
uint32_t tong_max_val,
|
|
|
|
uint32_t tong_max_dwells,
|
2018-03-04 01:04:27 +00:00
|
|
|
bool dump,
|
|
|
|
std::string dump_filename) : gr::block("pcps_tong_acquisition_cc",
|
|
|
|
gr::io_signature::make(1, 1, sizeof(gr_complex) * sampled_ms * samples_per_ms),
|
|
|
|
gr::io_signature::make(0, 0, sizeof(gr_complex) * sampled_ms * samples_per_ms))
|
2013-08-28 17:17:57 +00:00
|
|
|
{
|
2016-04-21 16:54:08 +00:00
|
|
|
this->message_port_register_out(pmt::mp("events"));
|
2018-08-12 22:54:23 +00:00
|
|
|
d_sample_counter = 0ULL; // SAMPLE COUNTER
|
2013-08-28 17:17:57 +00:00
|
|
|
d_active = false;
|
|
|
|
d_state = 0;
|
|
|
|
d_fs_in = fs_in;
|
|
|
|
d_samples_per_ms = samples_per_ms;
|
|
|
|
d_samples_per_code = samples_per_code;
|
|
|
|
d_sampled_ms = sampled_ms;
|
2016-08-11 11:13:30 +00:00
|
|
|
d_dwell_count = 0;
|
2013-08-28 17:17:57 +00:00
|
|
|
d_tong_max_val = tong_max_val;
|
2016-08-11 11:13:30 +00:00
|
|
|
d_tong_max_dwells = tong_max_dwells;
|
2013-08-28 17:17:57 +00:00
|
|
|
d_tong_init_val = tong_init_val;
|
|
|
|
d_tong_count = d_tong_init_val;
|
|
|
|
d_doppler_max = doppler_max;
|
|
|
|
d_fft_size = d_sampled_ms * d_samples_per_ms;
|
|
|
|
d_mag = 0;
|
|
|
|
d_input_power = 0.0;
|
|
|
|
d_num_doppler_bins = 0;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
d_fft_codes = static_cast<gr_complex *>(volk_gnsssdr_malloc(d_fft_size * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
|
|
|
|
d_magnitude = static_cast<float *>(volk_gnsssdr_malloc(d_fft_size * sizeof(float), volk_gnsssdr_get_alignment()));
|
2013-08-28 17:17:57 +00:00
|
|
|
|
|
|
|
// Direct FFT
|
|
|
|
d_fft_if = new gr::fft::fft_complex(d_fft_size, true);
|
|
|
|
|
|
|
|
// Inverse FFT
|
|
|
|
d_ifft = new gr::fft::fft_complex(d_fft_size, false);
|
|
|
|
|
|
|
|
// For dumping samples into a file
|
|
|
|
d_dump = dump;
|
2018-12-03 18:01:47 +00:00
|
|
|
d_dump_filename = std::move(dump_filename);
|
2015-05-19 20:11:31 +00:00
|
|
|
|
|
|
|
d_doppler_resolution = 0;
|
|
|
|
d_threshold = 0;
|
|
|
|
d_doppler_step = 0;
|
2018-12-03 09:05:47 +00:00
|
|
|
d_grid_data = nullptr;
|
|
|
|
d_grid_doppler_wipeoffs = nullptr;
|
|
|
|
d_gnss_synchro = nullptr;
|
2015-05-19 20:11:31 +00:00
|
|
|
d_code_phase = 0;
|
|
|
|
d_doppler_freq = 0;
|
|
|
|
d_test_statistics = 0;
|
|
|
|
d_channel = 0;
|
2013-08-28 17:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pcps_tong_acquisition_cc::~pcps_tong_acquisition_cc()
|
|
|
|
{
|
|
|
|
if (d_num_doppler_bins > 0)
|
|
|
|
{
|
2018-12-08 17:49:31 +00:00
|
|
|
for (uint32_t i = 0; i < d_num_doppler_bins; i++)
|
2013-10-01 20:32:04 +00:00
|
|
|
{
|
2016-08-18 12:17:02 +00:00
|
|
|
volk_gnsssdr_free(d_grid_doppler_wipeoffs[i]);
|
|
|
|
volk_gnsssdr_free(d_grid_data[i]);
|
2013-10-01 20:32:04 +00:00
|
|
|
}
|
2013-08-28 17:17:57 +00:00
|
|
|
delete[] d_grid_doppler_wipeoffs;
|
|
|
|
delete[] d_grid_data;
|
|
|
|
}
|
|
|
|
|
2016-08-18 12:17:02 +00:00
|
|
|
volk_gnsssdr_free(d_fft_codes);
|
|
|
|
volk_gnsssdr_free(d_magnitude);
|
2013-08-28 17:17:57 +00:00
|
|
|
|
|
|
|
delete d_ifft;
|
|
|
|
delete d_fft_if;
|
|
|
|
|
|
|
|
if (d_dump)
|
|
|
|
{
|
|
|
|
d_dump_file.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
void pcps_tong_acquisition_cc::set_local_code(std::complex<float> *code)
|
2013-08-28 17:17:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
memcpy(d_fft_if->get_inbuf(), code, sizeof(gr_complex) * d_fft_size);
|
2013-08-28 17:17:57 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
d_fft_if->execute(); // We need the FFT of local code
|
2013-08-28 17:17:57 +00:00
|
|
|
|
|
|
|
//Conjugate the local code
|
2014-09-10 01:15:01 +00:00
|
|
|
volk_32fc_conjugate_32fc(d_fft_codes, d_fft_if->get_outbuf(), d_fft_size);
|
2013-08-28 17:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pcps_tong_acquisition_cc::init()
|
|
|
|
{
|
2016-04-08 13:10:46 +00:00
|
|
|
d_gnss_synchro->Flag_valid_acquisition = false;
|
|
|
|
d_gnss_synchro->Flag_valid_symbol_output = false;
|
|
|
|
d_gnss_synchro->Flag_valid_pseudorange = false;
|
|
|
|
d_gnss_synchro->Flag_valid_word = false;
|
2018-08-21 09:50:39 +00:00
|
|
|
d_gnss_synchro->Acq_doppler_step = 0U;
|
2013-08-28 17:17:57 +00:00
|
|
|
d_gnss_synchro->Acq_delay_samples = 0.0;
|
|
|
|
d_gnss_synchro->Acq_doppler_hz = 0.0;
|
2018-08-21 09:50:39 +00:00
|
|
|
d_gnss_synchro->Acq_samplestamp_samples = 0ULL;
|
2013-08-28 17:17:57 +00:00
|
|
|
d_mag = 0.0;
|
|
|
|
d_input_power = 0.0;
|
|
|
|
|
2013-10-01 20:32:04 +00:00
|
|
|
// Count the number of bins
|
|
|
|
d_num_doppler_bins = 0;
|
2018-12-08 17:49:31 +00:00
|
|
|
for (auto doppler = static_cast<int32_t>(-d_doppler_max);
|
|
|
|
doppler <= static_cast<int32_t>(d_doppler_max);
|
2013-10-01 20:32:04 +00:00
|
|
|
doppler += d_doppler_step)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
d_num_doppler_bins++;
|
|
|
|
}
|
2013-10-01 20:32:04 +00:00
|
|
|
|
|
|
|
// Create the carrier Doppler wipeoff signals and allocate data grid.
|
2018-03-03 01:03:39 +00:00
|
|
|
d_grid_doppler_wipeoffs = new gr_complex *[d_num_doppler_bins];
|
|
|
|
d_grid_data = new float *[d_num_doppler_bins];
|
2018-12-08 17:49:31 +00:00
|
|
|
for (uint32_t doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++)
|
2013-08-28 17:17:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
d_grid_doppler_wipeoffs[doppler_index] = static_cast<gr_complex *>(volk_gnsssdr_malloc(d_fft_size * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
|
2013-08-28 17:17:57 +00:00
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
int32_t doppler = -static_cast<int32_t>(d_doppler_max) + d_doppler_step * doppler_index;
|
2018-06-06 15:25:03 +00:00
|
|
|
float phase_step_rad = GPS_TWO_PI * doppler / static_cast<float>(d_fs_in);
|
2016-03-20 23:38:08 +00:00
|
|
|
float _phase[1];
|
|
|
|
_phase[0] = 0;
|
2018-03-03 01:03:39 +00:00
|
|
|
volk_gnsssdr_s32f_sincos_32fc(d_grid_doppler_wipeoffs[doppler_index], -phase_step_rad, _phase, d_fft_size);
|
2013-08-28 17:17:57 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
d_grid_data[doppler_index] = static_cast<float *>(volk_gnsssdr_malloc(d_fft_size * sizeof(float), volk_gnsssdr_get_alignment()));
|
2013-08-28 17:17:57 +00:00
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
for (uint32_t i = 0; i < d_fft_size; i++)
|
2013-08-28 17:17:57 +00:00
|
|
|
{
|
|
|
|
d_grid_data[doppler_index][i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
void pcps_tong_acquisition_cc::set_state(int32_t state)
|
2015-02-10 18:30:15 +00:00
|
|
|
{
|
|
|
|
d_state = state;
|
|
|
|
if (d_state == 1)
|
|
|
|
{
|
|
|
|
d_gnss_synchro->Acq_delay_samples = 0.0;
|
|
|
|
d_gnss_synchro->Acq_doppler_hz = 0.0;
|
2018-08-21 09:50:39 +00:00
|
|
|
d_gnss_synchro->Acq_samplestamp_samples = 0ULL;
|
|
|
|
d_gnss_synchro->Acq_doppler_step = 0U;
|
2016-08-11 11:13:30 +00:00
|
|
|
d_dwell_count = 0;
|
2015-02-10 18:30:15 +00:00
|
|
|
d_tong_count = d_tong_init_val;
|
|
|
|
d_mag = 0.0;
|
|
|
|
d_input_power = 0.0;
|
|
|
|
d_test_statistics = 0.0;
|
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
for (uint32_t doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++)
|
2015-02-10 18:30:15 +00:00
|
|
|
{
|
2018-12-08 17:49:31 +00:00
|
|
|
for (uint32_t i = 0; i < d_fft_size; i++)
|
2015-02-10 18:30:15 +00:00
|
|
|
{
|
|
|
|
d_grid_data[doppler_index][i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (d_state == 0)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
}
|
2015-02-10 18:30:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(ERROR) << "State can only be set to 0 or 1";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 17:17:57 +00:00
|
|
|
int pcps_tong_acquisition_cc::general_work(int noutput_items,
|
2018-03-03 01:03:39 +00:00
|
|
|
gr_vector_int &ninput_items, gr_vector_const_void_star &input_items,
|
|
|
|
gr_vector_void_star &output_items __attribute__((unused)))
|
2013-08-28 17:17:57 +00:00
|
|
|
{
|
2018-12-08 17:49:31 +00:00
|
|
|
int32_t acquisition_message = -1; //0=STOP_CHANNEL 1=ACQ_SUCCEES 2=ACQ_FAIL
|
2013-08-28 17:17:57 +00:00
|
|
|
|
|
|
|
switch (d_state)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
if (d_active)
|
|
|
|
{
|
|
|
|
//restart acquisition variables
|
|
|
|
d_gnss_synchro->Acq_delay_samples = 0.0;
|
|
|
|
d_gnss_synchro->Acq_doppler_hz = 0.0;
|
2018-08-21 09:50:39 +00:00
|
|
|
d_gnss_synchro->Acq_samplestamp_samples = 0ULL;
|
|
|
|
d_gnss_synchro->Acq_doppler_step = 0U;
|
2018-03-03 01:03:39 +00:00
|
|
|
d_dwell_count = 0;
|
|
|
|
d_tong_count = d_tong_init_val;
|
|
|
|
d_mag = 0.0;
|
|
|
|
d_input_power = 0.0;
|
|
|
|
d_test_statistics = 0.0;
|
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
for (uint32_t doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2018-12-08 17:49:31 +00:00
|
|
|
for (uint32_t i = 0; i < d_fft_size; i++)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
d_grid_data[doppler_index][i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d_state = 1;
|
|
|
|
}
|
|
|
|
|
2018-08-12 22:54:23 +00:00
|
|
|
d_sample_counter += static_cast<uint64_t>(d_fft_size * ninput_items[0]); // sample counter
|
2018-03-03 01:03:39 +00:00
|
|
|
consume_each(ninput_items[0]);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
// initialize acquisition algorithm
|
2018-12-08 17:49:31 +00:00
|
|
|
int32_t doppler;
|
2018-03-03 01:03:39 +00:00
|
|
|
uint32_t indext = 0;
|
|
|
|
float magt = 0.0;
|
2018-12-03 15:25:11 +00:00
|
|
|
const auto *in = reinterpret_cast<const gr_complex *>(input_items[0]); //Get the input samples pointer
|
2018-03-03 01:03:39 +00:00
|
|
|
float fft_normalization_factor = static_cast<float>(d_fft_size) * static_cast<float>(d_fft_size);
|
|
|
|
d_input_power = 0.0;
|
|
|
|
d_mag = 0.0;
|
|
|
|
|
2018-08-12 22:54:23 +00:00
|
|
|
d_sample_counter += static_cast<uint64_t>(d_fft_size); // sample counter
|
2018-03-03 01:03:39 +00:00
|
|
|
|
|
|
|
d_dwell_count++;
|
|
|
|
|
|
|
|
DLOG(INFO) << "Channel: " << d_channel
|
|
|
|
<< " , doing acquisition of satellite: " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN
|
|
|
|
<< " ,sample stamp: " << d_sample_counter << ", threshold: "
|
|
|
|
<< d_threshold << ", doppler_max: " << d_doppler_max
|
|
|
|
<< ", doppler_step: " << d_doppler_step;
|
|
|
|
|
|
|
|
// 1- Compute the input signal power estimation
|
|
|
|
volk_32fc_magnitude_squared_32f(d_magnitude, in, d_fft_size);
|
|
|
|
volk_32f_accumulator_s32f(&d_input_power, d_magnitude, d_fft_size);
|
|
|
|
d_input_power /= static_cast<float>(d_fft_size);
|
|
|
|
|
|
|
|
// 2- Doppler frequency search loop
|
2018-12-08 17:49:31 +00:00
|
|
|
for (uint32_t doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
// doppler search steps
|
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
doppler = -static_cast<int32_t>(d_doppler_max) + d_doppler_step * doppler_index;
|
2018-03-03 01:03:39 +00:00
|
|
|
|
|
|
|
volk_32fc_x2_multiply_32fc(d_fft_if->get_inbuf(), in,
|
|
|
|
d_grid_doppler_wipeoffs[doppler_index], d_fft_size);
|
|
|
|
|
|
|
|
// 3- Perform the FFT-based convolution (parallel time search)
|
|
|
|
// Compute the FFT of the carrier wiped--off incoming signal
|
|
|
|
d_fft_if->execute();
|
|
|
|
|
|
|
|
// Multiply carrier wiped--off, Fourier transformed incoming signal
|
|
|
|
// with the local FFT'd code reference using SIMD operations with VOLK library
|
|
|
|
volk_32fc_x2_multiply_32fc(d_ifft->get_inbuf(),
|
|
|
|
d_fft_if->get_outbuf(), d_fft_codes, d_fft_size);
|
|
|
|
|
|
|
|
// compute the inverse FFT
|
|
|
|
d_ifft->execute();
|
|
|
|
|
|
|
|
// Compute magnitude
|
|
|
|
volk_32fc_magnitude_squared_32f(d_magnitude, d_ifft->get_outbuf(), d_fft_size);
|
|
|
|
|
|
|
|
// Compute vector of test statistics corresponding to current doppler index.
|
|
|
|
volk_32f_s32f_multiply_32f(d_magnitude, d_magnitude,
|
|
|
|
1 / (fft_normalization_factor * fft_normalization_factor * d_input_power),
|
|
|
|
d_fft_size);
|
|
|
|
|
|
|
|
// Accumulate test statistics in d_grid_data.
|
|
|
|
volk_32f_x2_add_32f(d_grid_data[doppler_index], d_magnitude, d_grid_data[doppler_index], d_fft_size);
|
|
|
|
|
|
|
|
// Search maximum
|
|
|
|
volk_gnsssdr_32f_index_max_32u(&indext, d_grid_data[doppler_index], d_fft_size);
|
|
|
|
|
|
|
|
magt = d_grid_data[doppler_index][indext];
|
|
|
|
|
|
|
|
// 4- record the maximum peak and the associated synchronization parameters
|
|
|
|
if (d_mag < magt)
|
|
|
|
{
|
|
|
|
d_mag = magt;
|
|
|
|
d_gnss_synchro->Acq_delay_samples = static_cast<double>(indext % d_samples_per_code);
|
|
|
|
d_gnss_synchro->Acq_doppler_hz = static_cast<double>(doppler);
|
|
|
|
d_gnss_synchro->Acq_samplestamp_samples = d_sample_counter;
|
2018-08-21 09:50:39 +00:00
|
|
|
d_gnss_synchro->Acq_doppler_step = d_doppler_step;
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Record results to file if required
|
|
|
|
if (d_dump)
|
|
|
|
{
|
|
|
|
std::stringstream filename;
|
|
|
|
std::streamsize n = 2 * sizeof(float) * (d_fft_size); // complex file write
|
|
|
|
filename.str("");
|
|
|
|
filename << "../data/test_statistics_" << d_gnss_synchro->System
|
|
|
|
<< "_" << d_gnss_synchro->Signal << "_sat_"
|
|
|
|
<< d_gnss_synchro->PRN << "_doppler_" << doppler << ".dat";
|
|
|
|
d_dump_file.open(filename.str().c_str(), std::ios::out | std::ios::binary);
|
|
|
|
d_dump_file.write(reinterpret_cast<char *>(d_ifft->get_outbuf()), n); //write directly |abs(x)|^2 in this Doppler bin?
|
|
|
|
d_dump_file.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 5- Compute the test statistics and compare to the threshold
|
|
|
|
d_test_statistics = d_mag;
|
|
|
|
|
|
|
|
if (d_test_statistics > d_threshold * d_dwell_count)
|
|
|
|
{
|
|
|
|
d_tong_count++;
|
|
|
|
if (d_tong_count == d_tong_max_val)
|
|
|
|
{
|
|
|
|
d_state = 2; // Positive acquisition
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d_tong_count--;
|
|
|
|
if (d_tong_count == 0)
|
|
|
|
{
|
|
|
|
d_state = 3; // Negative acquisition
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d_dwell_count >= d_tong_max_dwells)
|
|
|
|
{
|
|
|
|
d_state = 3; // Negative acquisition
|
|
|
|
}
|
|
|
|
consume_each(1);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
// 6.1- Declare positive acquisition using a message port
|
|
|
|
DLOG(INFO) << "positive acquisition";
|
|
|
|
DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN;
|
|
|
|
DLOG(INFO) << "sample_stamp " << d_sample_counter;
|
|
|
|
DLOG(INFO) << "test statistics value " << d_test_statistics;
|
|
|
|
DLOG(INFO) << "test statistics threshold " << d_threshold;
|
|
|
|
DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples;
|
|
|
|
DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz;
|
|
|
|
DLOG(INFO) << "magnitude " << d_mag;
|
|
|
|
DLOG(INFO) << "input signal power " << d_input_power;
|
|
|
|
|
|
|
|
d_active = false;
|
|
|
|
d_state = 0;
|
|
|
|
|
2018-08-12 22:54:23 +00:00
|
|
|
d_sample_counter += static_cast<uint64_t>(d_fft_size * ninput_items[0]); // sample counter
|
2018-03-03 01:03:39 +00:00
|
|
|
consume_each(ninput_items[0]);
|
|
|
|
|
|
|
|
acquisition_message = 1;
|
|
|
|
this->message_port_pub(pmt::mp("events"), pmt::from_long(acquisition_message));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
// 6.2- Declare negative acquisition using a message port
|
|
|
|
DLOG(INFO) << "negative acquisition";
|
|
|
|
DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN;
|
|
|
|
DLOG(INFO) << "sample_stamp " << d_sample_counter;
|
|
|
|
DLOG(INFO) << "test statistics value " << d_test_statistics;
|
|
|
|
DLOG(INFO) << "test statistics threshold " << d_threshold;
|
|
|
|
DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples;
|
|
|
|
DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz;
|
|
|
|
DLOG(INFO) << "magnitude " << d_mag;
|
|
|
|
DLOG(INFO) << "input signal power " << d_input_power;
|
|
|
|
|
|
|
|
d_active = false;
|
|
|
|
d_state = 0;
|
|
|
|
|
2018-08-12 22:54:23 +00:00
|
|
|
d_sample_counter += static_cast<uint64_t>(d_fft_size * ninput_items[0]); // sample counter
|
2018-03-03 01:03:39 +00:00
|
|
|
consume_each(ninput_items[0]);
|
|
|
|
|
|
|
|
acquisition_message = 2;
|
|
|
|
this->message_port_pub(pmt::mp("events"), pmt::from_long(acquisition_message));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2013-08-28 17:17:57 +00:00
|
|
|
}
|
|
|
|
|
2015-02-28 16:08:07 +00:00
|
|
|
return noutput_items;
|
2013-08-28 17:17:57 +00:00
|
|
|
}
|