GNSS-SDR  0.0.13
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  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
29  *
30  * GNSS-SDR is a software defined Global Navigation
31  * Satellite Systems receiver
32  *
33  * This file is part of GNSS-SDR.
34  *
35  * SPDX-License-Identifier: GPL-3.0-or-later
36  *
37  * -----------------------------------------------------------------------------
38  */
39 
40 #ifndef GNSS_SDR_PCPS_TONG_ACQUISITION_CC_H
41 #define GNSS_SDR_PCPS_TONG_ACQUISITION_CC_H
42 
43 #include "channel_fsm.h"
44 #include "gnss_synchro.h"
45 #include <gnuradio/block.h>
46 #include <gnuradio/fft/fft.h>
47 #include <gnuradio/gr_complex.h>
48 #include <fstream>
49 #include <memory> // for weak_ptr
50 #include <string>
51 #include <utility>
52 #include <vector>
53 #if GNURADIO_USES_STD_POINTERS
54 #else
55 #include <boost/shared_ptr.hpp>
56 #endif
57 
59 
60 #if GNURADIO_USES_STD_POINTERS
61 using pcps_tong_acquisition_cc_sptr = std::shared_ptr<pcps_tong_acquisition_cc>;
62 #else
63 using pcps_tong_acquisition_cc_sptr = boost::shared_ptr<pcps_tong_acquisition_cc>;
64 #endif
65 
66 pcps_tong_acquisition_cc_sptr pcps_tong_make_acquisition_cc(
67  uint32_t sampled_ms,
68  uint32_t doppler_max,
69  int64_t fs_in,
70  int32_t samples_per_ms,
71  int32_t samples_per_code,
72  uint32_t tong_init_val,
73  uint32_t tong_max_val,
74  uint32_t tong_max_dwells,
75  bool dump,
76  const std::string& dump_filename);
77 
78 /*!
79  * \brief This class implements a Parallel Code Phase Search Acquisition with
80  * Tong algorithm.
81  */
82 class pcps_tong_acquisition_cc : public gr::block
83 {
84 public:
85  /*!
86  * \brief Default destructor.
87  */
89 
90  /*!
91  * \brief Set acquisition/tracking common Gnss_Synchro object pointer
92  * to exchange synchronization data between acquisition and tracking blocks.
93  * \param p_gnss_synchro Satellite information shared by the processing blocks.
94  */
95  inline void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro)
96  {
97  d_gnss_synchro = p_gnss_synchro;
98  }
99 
100  /*!
101  * \brief Returns the maximum peak of grid search.
102  */
103  inline uint32_t mag() const
104  {
105  return d_mag;
106  }
107 
108  /*!
109  * \brief Initializes acquisition algorithm.
110  */
111  void init();
112 
113  /*!
114  * \brief Sets local code for TONG acquisition algorithm.
115  * \param code - Pointer to the PRN code.
116  */
117  void set_local_code(std::complex<float>* code);
118 
119  /*!
120  * \brief Starts acquisition algorithm, turning from standby mode to
121  * active mode
122  * \param active - bool that activates/deactivates the block.
123  */
124  inline void set_active(bool active)
125  {
126  d_active = active;
127  }
128 
129  /*!
130  * \brief If set to 1, ensures that acquisition starts at the
131  * first available sample.
132  * \param state - int=1 forces start of acquisition
133  */
134  void set_state(int32_t state);
135 
136  /*!
137  * \brief Set acquisition channel unique ID
138  * \param channel - receiver channel.
139  */
140  inline void set_channel(uint32_t channel)
141  {
142  d_channel = channel;
143  }
144 
145  /*!
146  * \brief Set channel fsm associated to this acquisition instance
147  */
148  inline void set_channel_fsm(std::weak_ptr<ChannelFsm> channel_fsm)
149  {
150  d_channel_fsm = std::move(channel_fsm);
151  }
152 
153  /*!
154  * \brief Set statistics threshold of TONG algorithm.
155  * \param threshold - Threshold for signal detection (check \ref Navitec2012,
156  * Algorithm 1, for a definition of this threshold).
157  */
158  inline void set_threshold(float threshold)
159  {
160  d_threshold = threshold;
161  }
162 
163  /*!
164  * \brief Set maximum Doppler grid search
165  * \param doppler_max - Maximum Doppler shift considered in the grid search [Hz].
166  */
167  inline void set_doppler_max(uint32_t doppler_max)
168  {
169  d_doppler_max = doppler_max;
170  }
171 
172  /*!
173  * \brief Set Doppler steps for the grid search
174  * \param doppler_step - Frequency bin of the search grid [Hz].
175  */
176  inline void set_doppler_step(uint32_t doppler_step)
177  {
178  d_doppler_step = doppler_step;
179  }
180 
181  /*!
182  * \brief Parallel Code Phase Search Acquisition signal processing.
183  */
184  int general_work(int noutput_items, gr_vector_int& ninput_items,
185  gr_vector_const_void_star& input_items,
186  gr_vector_void_star& output_items);
187 
188 private:
189  friend pcps_tong_acquisition_cc_sptr
190  pcps_tong_make_acquisition_cc(uint32_t sampled_ms, uint32_t doppler_max,
191  int64_t fs_in, int32_t samples_per_ms,
192  int32_t samples_per_code, uint32_t tong_init_val,
193  uint32_t tong_max_val, uint32_t tong_max_dwells,
194  bool dump, const std::string& dump_filename);
195 
196  pcps_tong_acquisition_cc(uint32_t sampled_ms, uint32_t doppler_max,
197  int64_t fs_in, int32_t samples_per_ms,
198  int32_t samples_per_code, uint32_t tong_init_val,
199  uint32_t tong_max_val, uint32_t tong_max_dwells,
200  bool dump, const std::string& dump_filename);
201 
202  void calculate_magnitudes(gr_complex* fft_begin, int32_t doppler_shift,
203  int32_t doppler_offset);
204 
205  std::weak_ptr<ChannelFsm> d_channel_fsm;
206 
207  std::unique_ptr<gr::fft::fft_complex> d_fft_if;
208  std::unique_ptr<gr::fft::fft_complex> d_ifft;
209 
210  std::vector<std::vector<gr_complex>> d_grid_doppler_wipeoffs;
211  std::vector<std::vector<float>> d_grid_data;
212  std::vector<gr_complex> d_fft_codes;
213  std::vector<float> d_magnitude;
214 
215  std::string d_satellite_str;
216  std::string d_dump_filename;
217 
218  std::ofstream d_dump_file;
219 
220  Gnss_Synchro* d_gnss_synchro;
221 
222  int64_t d_fs_in;
223  uint64_t d_sample_counter;
224 
225  float d_threshold;
226  float d_doppler_freq;
227  float d_mag;
228  float d_input_power;
229  float d_test_statistics;
230  int32_t d_state;
231  int32_t d_samples_per_ms;
232  int32_t d_samples_per_code;
233  uint32_t d_channel;
234  uint32_t d_doppler_resolution;
235  uint32_t d_doppler_max;
236  uint32_t d_doppler_step;
237  uint32_t d_sampled_ms;
238  uint32_t d_dwell_count;
239  uint32_t d_tong_count;
240  uint32_t d_tong_init_val;
241  uint32_t d_tong_max_val;
242  uint32_t d_tong_max_dwells;
243  uint32_t d_fft_size;
244  uint32_t d_num_doppler_bins;
245  uint32_t d_code_phase;
246 
247  bool d_active;
248  bool d_dump;
249 };
250 
251 #endif // GNSS_SDR_PCPS_TONG_ACQUISITION_CC_H
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:33
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.