GNSS-SDR  0.0.21
An Open Source GNSS Software Defined Receiver
pcps_acquisition.h
Go to the documentation of this file.
1 /*!
2  * \file pcps_acquisition.h
3  * \brief This class implements a Parallel Code Phase Search Acquisition
4  *
5  * Acquisition strategy (Kay Borre book + CFAR threshold).
6  * <ol>
7  * <li> Compute the input signal power estimation
8  * <li> Doppler serial search loop
9  * <li> Perform the FFT-based circular convolution (parallel time search)
10  * <li> Record the maximum peak and the associated synchronization parameters
11  * <li> Compute the test statistics and compare to the threshold
12  * <li> Declare positive or negative acquisition using a message queue
13  * </ol>
14  *
15  * Kay Borre book: K.Borre, D.M.Akos, N.Bertelsen, P.Rinder, and S.H.Jensen,
16  * "A Software-Defined GPS and Galileo Receiver. A Single-Frequency
17  * Approach", Birkhauser, 2007. pp 81-84
18  *
19  * \authors <ul>
20  * <li> Javier Arribas, 2011. jarribas(at)cttc.es
21  * <li> Luis Esteve, 2012. luis(at)epsilon-formacion.com
22  * <li> Marc Molina, 2013. marc.molina.pena@gmail.com
23  * <li> Cillian O'Driscoll, 2017. cillian(at)ieee.org
24  * <li> Antonio Ramos, 2017. antonio.ramos@cttc.es
25  * </ul>
26  *
27  * -----------------------------------------------------------------------------
28  *
29  * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
30  * This file is part of GNSS-SDR.
31  *
32  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
33  * SPDX-License-Identifier: GPL-3.0-or-later
34  *
35  * -----------------------------------------------------------------------------
36  */
37 
38 #ifndef GNSS_SDR_PCPS_ACQUISITION_H
39 #define GNSS_SDR_PCPS_ACQUISITION_H
40 
42 #if ARMA_NO_BOUND_CHECKING
43 #define ARMA_NO_DEBUG 1
44 #endif
45 
46 #include "acq_conf.h"
47 #include "channel_fsm.h"
48 #include "gnss_sdr_fft.h"
49 #include <armadillo>
50 #include <gnuradio/block.h>
51 #include <gnuradio/gr_complex.h> // for gr_complex
52 #include <gnuradio/thread/thread.h> // for scoped_lock
53 #include <gnuradio/types.h> // for gr_vector_const_void_star
54 #include <volk/volk_complex.h> // for lv_16sc_t
55 #include <volk_gnsssdr/volk_gnsssdr_alloc.h> // for volk_gnsssdr::vector
56 #include <complex>
57 #include <cstdint>
58 #include <memory>
59 #include <queue>
60 #include <string>
61 #include <utility>
62 
63 
64 #if HAS_STD_SPAN
65 #include <span>
66 namespace own = std;
67 #else
68 #include <gsl-lite/gsl-lite.hpp>
69 namespace own = gsl_lite;
70 #endif
71 
72 /** \addtogroup Acquisition
73  * Classes for GNSS signal acquisition
74  * \{ */
75 /** \addtogroup Acq_gnuradio_blocks acquisition_gr_blocks
76  * GNU Radio processing blocks for GNSS signal acquisition
77  * \{ */
78 
79 
80 class Gnss_Synchro;
81 class pcps_acquisition;
82 
83 using pcps_acquisition_sptr = gnss_shared_ptr<pcps_acquisition>;
84 
85 pcps_acquisition_sptr pcps_make_acquisition(const Acq_Conf& conf_);
86 
87 /*!
88  * \brief This class implements a Parallel Code Phase Search Acquisition.
89  *
90  * Check \ref Navitec2012 "An Open Source Galileo E1 Software Receiver",
91  * Algorithm 1, for a pseudocode description of this implementation.
92  */
94 {
95 public:
96  ~pcps_acquisition() override;
97 
98  /*!
99  * \brief Set acquisition/tracking common Gnss_Synchro object pointer
100  * to exchange synchronization data between acquisition and tracking blocks.
101  * \param p_gnss_synchro Satellite information shared by the processing blocks.
102  */
103  inline void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro) override
104  {
105  gr::thread::scoped_lock lock(d_setlock); // require mutex with work function called by the scheduler
106  d_gnss_synchro = p_gnss_synchro;
107  }
108 
109  /*!
110  * \brief Sets local code for PCPS acquisition algorithm.
111  * \param code - Pointer to the PRN code.
112  */
113  void set_local_code(std::complex<float>* code) override;
114 
115  void set_resampler_latency(uint32_t latency_samples);
116 
117  /*!
118  * \brief Returns the maximum peak of grid search.
119  */
120  inline uint32_t mag() const override
121  {
122  return 0; // Not implemented
123  }
124 
125  /*!
126  * \brief Starts acquisition algorithm, turning from standby mode to
127  * active mode
128  * \param active - bool that activates/deactivates the block.
129  */
130  void set_active(bool active) override;
131 
132  /*!
133  * \brief Set acquisition channel unique ID
134  * \param channel - receiver channel.
135  */
136  inline void set_channel(uint32_t channel) override
137  {
138  d_channel = channel;
139  }
140 
141  /*!
142  * \brief Set channel fsm associated to this acquisition instance
143  */
144  inline void set_channel_fsm(std::weak_ptr<ChannelFsm> channel_fsm) override
145  {
146  d_channel_fsm = std::move(channel_fsm);
147  }
148 
149  /*!
150  * \brief Set Doppler center frequency for the grid search. It will refresh the Doppler grid.
151  * \param doppler_center - Frequency center of the search grid [Hz].
152  */
153  void set_doppler_center(int32_t doppler_center);
154 
155  /*!
156  * \brief Parallel Code Phase Search Acquisition signal processing.
157  */
158  int general_work(int noutput_items, gr_vector_int& ninput_items,
159  gr_vector_const_void_star& input_items,
160  gr_vector_void_star& output_items) override;
161 
162 private:
163  friend pcps_acquisition_sptr pcps_make_acquisition(const Acq_Conf& conf_);
164  explicit pcps_acquisition(const Acq_Conf& conf_);
165 
166  struct AcquisitionResult
167  {
168  int32_t doppler{0};
169  uint32_t index_time{0};
170  uint64_t sample_count{0};
171  float test_statistics{0};
172  bool positive_acq{false};
173  };
174 
175  void update_local_carrier(own::span<gr_complex> carrier_vector, float freq) const;
176  void update_grid_doppler_wipeoffs();
177  void update_grid_doppler_wipeoffs_step2();
178  void doppler_grid(const gr_complex* in);
179  AcquisitionResult compute_statistics();
180  void update_synchro(const AcquisitionResult& result);
181  void handle_threshold_reached(AcquisitionResult& result);
182  void handle_integration_done(const AcquisitionResult& result);
183  void acquisition_core(uint64_t sample_count);
184  void log_acquisition(const AcquisitionResult& result) const;
185  void send_negative_acquisition(const AcquisitionResult& result);
186  void send_positive_acquisition(const AcquisitionResult& result);
187  void dump_results(const AcquisitionResult& result);
188  bool is_fdma();
189  float get_threshold() const;
190  AcquisitionResult first_vs_second_peak_statistic(uint32_t num_doppler_bins, int32_t doppler_max, int32_t doppler_step);
191  AcquisitionResult max_to_input_power_statistic(uint32_t num_doppler_bins, int32_t doppler_max, int32_t doppler_step);
192  void wait_if_active();
193 
194  const Acq_Conf d_acq_parameters;
195  const std::string d_dump_filename;
196  const float d_doppler_max;
197  const uint32_t d_samplesPerChip;
198  const uint32_t d_doppler_step;
199  const uint32_t d_consumed_samples;
200  const uint32_t d_fft_size;
201  const uint32_t d_effective_fft_size;
202  const uint32_t d_num_doppler_bins;
203  const uint32_t d_num_doppler_bins_step2;
204  const uint32_t d_dump_channel;
205  const float d_threshold;
206  const float d_threshold_step_two;
207  const bool d_cshort;
208  const bool d_use_CFAR_algorithm_flag;
209  const bool d_dump;
210 
211  // Need lock to access these
212  std::weak_ptr<ChannelFsm> d_channel_fsm;
213  std::unique_ptr<gr::thread::thread> d_worker;
214  Gnss_Synchro* d_gnss_synchro;
215  std::queue<Gnss_Synchro> d_monitor_queue;
216  int32_t d_state;
217  int32_t d_doppler_center;
218  int32_t d_doppler_bias;
219  uint32_t d_buffer_count;
220  uint32_t d_channel;
221  uint32_t d_resampler_latency_samples;
222  uint64_t d_sample_count;
223  bool d_step_two;
224  bool d_active;
225  bool d_worker_active;
226 
227  // Only access these in acquisition_core and functions strictly called from acquisition_core
228  uint32_t d_num_noncoherent_integrations_counter;
229  int64_t d_dump_number;
230  float d_input_power;
231  float d_doppler_center_step_two;
232  volk_gnsssdr::vector<volk_gnsssdr::vector<float>> d_magnitude_grid;
233  volk_gnsssdr::vector<float> d_tmp_buffer;
234  volk_gnsssdr::vector<std::complex<float>> d_input_signal;
235  volk_gnsssdr::vector<volk_gnsssdr::vector<std::complex<float>>> d_grid_doppler_wipeoffs_step_two;
236  std::unique_ptr<gnss_fft_complex_rev> d_ifft;
237  arma::fmat d_grid;
238  arma::fmat d_narrow_grid;
239 
240  // These are never accessed outside acquisition_core while acquisition is active
241  volk_gnsssdr::vector<volk_gnsssdr::vector<std::complex<float>>> d_grid_doppler_wipeoffs;
242  volk_gnsssdr::vector<std::complex<float>> d_fft_codes;
243  volk_gnsssdr::vector<std::complex<float>> d_data_buffer;
244  volk_gnsssdr::vector<lv_16sc_t> d_data_buffer_sc;
245  std::unique_ptr<gnss_fft_complex_fwd> d_fft_if;
246 };
247 
248 
249 /** \} */
250 /** \} */
251 #endif // GNSS_SDR_PCPS_ACQUISITION_H
Helper file for FFT interface.
This class implements a Parallel Code Phase Search Acquisition.
Header file of the interface to an acquisition implementation GNSS block.
STL namespace.
Class that contains all the configuration parameters for generic acquisition block based on the PCPS ...
Interface of the State Machine for channel.
void set_local_code(std::complex< float > *code) override
Sets local code for PCPS acquisition algorithm.
void set_active(bool active) override
Starts acquisition algorithm, turning from standby mode to active mode.
This is the class that contains the information that is shared by the processing blocks.
Definition: gnss_synchro.h:38
void set_doppler_center(int32_t doppler_center)
Set Doppler center frequency for the grid search. It will refresh the Doppler grid.
void set_channel(uint32_t channel) override
Set acquisition channel unique ID.
void set_channel_fsm(std::weak_ptr< ChannelFsm > channel_fsm) override
Set channel fsm associated to this acquisition instance.
void set_gnss_synchro(Gnss_Synchro *p_gnss_synchro) override
Set acquisition/tracking common Gnss_Synchro object pointer to exchange synchronization data between ...
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) override
Parallel Code Phase Search Acquisition signal processing.
uint32_t mag() const override
Returns the maximum peak of grid search.
This abstract class represents an interface to an acquisition GNSS block.