GNSS-SDR  0.0.19
An Open Source GNSS Software Defined Receiver
pcps_tong_acquisition_cc.h
Go to the documentation of this file.
1 /*!
2  * \file pcps_tong_acquisition_cc.h
3  * \brief This class implements a Parallel Code Phase Search Acquisition with
4  * Tong algorithm.
5  * \author Marc Molina, 2013. marc.molina.pena(at)gmail.com
6  *
7  * Acquisition strategy (Kaplan book + CFAR threshold).
8  * <ol>
9  * <li> Compute the input signal power estimation.
10  * <li> Doppler serial search loop.
11  * <li> Perform the FFT-based circular convolution (parallel time search).
12  * <li> Compute the tests statistics for all the cells.
13  * <li> Accumulate the grid of tests statistics with the previous grids.
14  * <li> Record the maximum peak and the associated synchronization parameters.
15  * <li> Compare the maximum averaged test statistics with a threshold.
16  * <li> If the test statistics exceeds the threshold, increment the Tong counter.
17  * <li> Otherwise, decrement the Tong counter.
18  * <li> If the Tong counter is equal to a given maximum value, declare positive
19  * <li> acquisition. If the Tong counter is equa to zero, declare negative
20  * <li> acquisition. Otherwise, process the next block.
21  * </ol>
22  *
23  * Kaplan book: D.Kaplan, J.Hegarty, "Understanding GPS. Principles
24  * and Applications", Artech House, 2006, pp 223-227
25  *
26  * -----------------------------------------------------------------------------
27  *
28  * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
29  * This file is part of GNSS-SDR.
30  *
31  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
32  * SPDX-License-Identifier: GPL-3.0-or-later
33  *
34  * -----------------------------------------------------------------------------
35  */
36 
37 #ifndef GNSS_SDR_PCPS_TONG_ACQUISITION_CC_H
38 #define GNSS_SDR_PCPS_TONG_ACQUISITION_CC_H
39 
40 #include "channel_fsm.h"
41 #include "gnss_sdr_fft.h"
42 #include "gnss_synchro.h"
43 #include <gnuradio/block.h>
44 #include <gnuradio/gr_complex.h>
45 #include <fstream>
46 #include <memory> // for weak_ptr
47 #include <string>
48 #include <utility>
49 #include <vector>
50 
51 /** \addtogroup Acquisition
52  * \{ */
53 /** \addtogroup Acq_gnuradio_blocks
54  * \{ */
55 
56 
58 
59 using pcps_tong_acquisition_cc_sptr = gnss_shared_ptr<pcps_tong_acquisition_cc>;
60 
61 pcps_tong_acquisition_cc_sptr pcps_tong_make_acquisition_cc(
62  uint32_t sampled_ms,
63  uint32_t doppler_max,
64  int64_t fs_in,
65  int32_t samples_per_ms,
66  int32_t samples_per_code,
67  uint32_t tong_init_val,
68  uint32_t tong_max_val,
69  uint32_t tong_max_dwells,
70  bool dump,
71  const std::string& dump_filename,
72  bool enable_monitor_output);
73 
74 /*!
75  * \brief This class implements a Parallel Code Phase Search Acquisition with
76  * Tong algorithm.
77  */
78 class pcps_tong_acquisition_cc : public gr::block
79 {
80 public:
81  /*!
82  * \brief Default destructor.
83  */
85 
86  /*!
87  * \brief Set acquisition/tracking common Gnss_Synchro object pointer
88  * to exchange synchronization data between acquisition and tracking blocks.
89  * \param p_gnss_synchro Satellite information shared by the processing blocks.
90  */
91  inline void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro)
92  {
93  d_gnss_synchro = p_gnss_synchro;
94  }
95 
96  /*!
97  * \brief Returns the maximum peak of grid search.
98  */
99  inline uint32_t mag() const
100  {
101  return d_mag;
102  }
103 
104  /*!
105  * \brief Initializes acquisition algorithm.
106  */
107  void init();
108 
109  /*!
110  * \brief Sets local code for TONG acquisition algorithm.
111  * \param code - Pointer to the PRN code.
112  */
113  void set_local_code(std::complex<float>* code);
114 
115  /*!
116  * \brief Starts acquisition algorithm, turning from standby mode to
117  * active mode
118  * \param active - bool that activates/deactivates the block.
119  */
120  inline void set_active(bool active)
121  {
122  d_active = active;
123  }
124 
125  /*!
126  * \brief If set to 1, ensures that acquisition starts at the
127  * first available sample.
128  * \param state - int=1 forces start of acquisition
129  */
130  void set_state(int32_t state);
131 
132  /*!
133  * \brief Set acquisition channel unique ID
134  * \param channel - receiver channel.
135  */
136  inline void set_channel(uint32_t channel)
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)
145  {
146  d_channel_fsm = std::move(channel_fsm);
147  }
148 
149  /*!
150  * \brief Set statistics threshold of TONG algorithm.
151  * \param threshold - Threshold for signal detection (check \ref Navitec2012,
152  * Algorithm 1, for a definition of this threshold).
153  */
154  inline void set_threshold(float threshold)
155  {
156  d_threshold = threshold;
157  }
158 
159  /*!
160  * \brief Set maximum Doppler grid search
161  * \param doppler_max - Maximum Doppler shift considered in the grid search [Hz].
162  */
163  inline void set_doppler_max(uint32_t doppler_max)
164  {
165  d_doppler_max = doppler_max;
166  }
167 
168  /*!
169  * \brief Set Doppler steps for the grid search
170  * \param doppler_step - Frequency bin of the search grid [Hz].
171  */
172  inline void set_doppler_step(uint32_t doppler_step)
173  {
174  d_doppler_step = doppler_step;
175  }
176 
177  /*!
178  * \brief Parallel Code Phase Search Acquisition signal processing.
179  */
180  int general_work(int noutput_items, gr_vector_int& ninput_items,
181  gr_vector_const_void_star& input_items,
182  gr_vector_void_star& output_items);
183 
184 private:
185  friend pcps_tong_acquisition_cc_sptr
186  pcps_tong_make_acquisition_cc(uint32_t sampled_ms, uint32_t doppler_max,
187  int64_t fs_in, int32_t samples_per_ms,
188  int32_t samples_per_code, uint32_t tong_init_val,
189  uint32_t tong_max_val, uint32_t tong_max_dwells,
190  bool dump, const std::string& dump_filename, bool enable_monitor_output);
191 
192  pcps_tong_acquisition_cc(uint32_t sampled_ms, uint32_t doppler_max,
193  int64_t fs_in, int32_t samples_per_ms,
194  int32_t samples_per_code, uint32_t tong_init_val,
195  uint32_t tong_max_val, uint32_t tong_max_dwells,
196  bool dump, const std::string& dump_filename, bool enable_monitor_output);
197 
198  void calculate_magnitudes(gr_complex* fft_begin, int32_t doppler_shift,
199  int32_t doppler_offset);
200 
201  std::weak_ptr<ChannelFsm> d_channel_fsm;
202  std::unique_ptr<gnss_fft_complex_fwd> d_fft_if;
203  std::unique_ptr<gnss_fft_complex_rev> d_ifft;
204 
205  std::vector<std::vector<gr_complex>> d_grid_doppler_wipeoffs;
206  std::vector<std::vector<float>> d_grid_data;
207  std::vector<gr_complex> d_fft_codes;
208  std::vector<float> d_magnitude;
209 
210  std::string d_satellite_str;
211  std::string d_dump_filename;
212 
213  std::ofstream d_dump_file;
214 
215  Gnss_Synchro* d_gnss_synchro;
216 
217  int64_t d_fs_in;
218  uint64_t d_sample_counter;
219 
220  float d_threshold;
221  float d_doppler_freq;
222  float d_mag;
223  float d_input_power;
224  float d_test_statistics;
225  int32_t d_state;
226  int32_t d_samples_per_ms;
227  int32_t d_samples_per_code;
228  uint32_t d_channel;
229  uint32_t d_doppler_resolution;
230  uint32_t d_doppler_max;
231  uint32_t d_doppler_step;
232  uint32_t d_sampled_ms;
233  uint32_t d_dwell_count;
234  uint32_t d_tong_init_val;
235  uint32_t d_tong_max_val;
236  uint32_t d_tong_max_dwells;
237  uint32_t d_tong_count;
238  uint32_t d_fft_size;
239  uint32_t d_num_doppler_bins;
240  uint32_t d_code_phase;
241 
242  bool d_active;
243  bool d_dump;
244  bool d_enable_monitor_output;
245 };
246 
247 
248 /** \} */
249 /** \} */
250 #endif // GNSS_SDR_PCPS_TONG_ACQUISITION_CC_H
Helper file for FFT interface.
void set_gnss_synchro(Gnss_Synchro *p_gnss_synchro)
Set acquisition/tracking common Gnss_Synchro object pointer to exchange synchronization data between ...
~pcps_tong_acquisition_cc()
Default destructor.
void set_channel(uint32_t channel)
Set acquisition channel unique ID.
void init()
Initializes acquisition algorithm.
void set_doppler_step(uint32_t doppler_step)
Set Doppler steps for the grid search.
Interface of the State Machine for channel.
void set_channel_fsm(std::weak_ptr< ChannelFsm > channel_fsm)
Set channel fsm associated to this acquisition instance.
This is the class that contains the information that is shared by the processing blocks.
Definition: gnss_synchro.h:38
This class implements a Parallel Code Phase Search Acquisition with Tong algorithm.
void set_active(bool active)
Starts acquisition algorithm, turning from standby mode to active mode.
void set_local_code(std::complex< float > *code)
Sets local code for TONG acquisition algorithm.
void set_state(int32_t state)
If set to 1, ensures that acquisition starts at the first available sample.
void set_doppler_max(uint32_t doppler_max)
Set maximum Doppler grid search.
uint32_t mag() const
Returns the maximum peak of grid search.
void set_threshold(float threshold)
Set statistics threshold of TONG algorithm.
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
Parallel Code Phase Search Acquisition signal processing.
Interface of the Gnss_Synchro class.