GNSS-SDR  0.0.13
An Open Source GNSS Software Defined Receiver
pcps_quicksync_acquisition_cc.h
Go to the documentation of this file.
1 /*!
2  * \file pcps_quicksync_acquisition_cc.h
3  * \brief This class implements a Parallel Code Phase Search Acquisition with the
4  * QuickSync Algorithm
5  *
6  * Acquisition strategy (Kay Borre book CFAR + threshold).
7  * <ol>
8  * <li> Compute the input signal power estimation
9  * <li> Doppler serial search loop
10  * <li> Perform folding of the incoming signal and local generated code
11  * <li> Perform the FFT-based circular convolution (parallel time search)
12  * <li> Record the maximum peak and the associated synchronization parameters
13  * <li> Compute the test statistics and compare to the threshold
14  * <li> Declare positive or negative acquisition using a message port
15  * <li> Obtain the adequate acquisition parameters by correlating the incoming
16  * signal shifted by the possible folded delays
17  * </ol>
18  *
19  * Kay Borre book: K.Borre, D.M.Akos, N.Bertelsen, P.Rinder, and S.H.Jensen,
20  * "A Software-Defined GPS and Galileo Receiver. A Single-Frequency
21  * Approach", Birkha user, 2007. pp 81-84
22  *
23  * \date Jun2 2014
24  * \author Damian Miralles Sanchez, dmiralles2009@gmail.com
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_QUICKSYNC_ACQUISITION_CC_H
41 #define GNSS_SDR_PCPS_QUICKSYNC_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 <algorithm>
49 #include <cassert>
50 #include <fstream>
51 #include <functional>
52 #include <memory> // for weak_ptr
53 #include <string>
54 #include <utility>
55 #include <vector>
56 #if GNURADIO_USES_STD_POINTERS
57 #else
58 #include <boost/shared_ptr.hpp>
59 #endif
60 
62 
63 #if GNURADIO_USES_STD_POINTERS
64 using pcps_quicksync_acquisition_cc_sptr = std::shared_ptr<pcps_quicksync_acquisition_cc>;
65 #else
66 using pcps_quicksync_acquisition_cc_sptr = boost::shared_ptr<pcps_quicksync_acquisition_cc>;
67 #endif
68 
69 pcps_quicksync_acquisition_cc_sptr pcps_quicksync_make_acquisition_cc(
70  uint32_t folding_factor,
71  uint32_t sampled_ms,
72  uint32_t max_dwells,
73  uint32_t doppler_max,
74  int64_t fs_in,
75  int32_t samples_per_ms,
76  int32_t samples_per_code,
77  bool bit_transition_flag,
78  bool dump,
79  const std::string& dump_filename);
80 
81 /*!
82  * \brief This class implements a Parallel Code Phase Search Acquisition with
83  * the implementation of the Sparse QuickSync Algorithm.
84  *
85  * Check \ref Navitec2012 "Faster GPS via the Sparse Fourier Transform",
86  * for details of its implementation and functionality.
87  */
88 class pcps_quicksync_acquisition_cc : public gr::block
89 {
90 public:
91  /*!
92  * \brief Default destructor.
93  */
95 
96  /*!
97  * \brief Set acquisition/tracking common Gnss_Synchro object pointer
98  * to exchange synchronization data between acquisition and tracking blocks.
99  * \param p_gnss_synchro Satellite information shared by the processing blocks.
100  */
101  inline void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro)
102  {
103  d_gnss_synchro = p_gnss_synchro;
104  }
105 
106  /*!
107  * \brief Returns the maximum peak of grid search.
108  */
109  inline uint32_t mag() const
110  {
111  return d_mag;
112  }
113 
114  /*!
115  * \brief Initializes acquisition algorithm.
116  */
117  void init();
118 
119  /*!
120  * \brief Sets local code for PCPS acquisition algorithm.
121  * \param code - Pointer to the PRN code.
122  */
123  void set_local_code(std::complex<float>* code);
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  inline void set_active(bool active)
131  {
132  d_active = active;
133  }
134 
135  /*!
136  * \brief If set to 1, ensures that acquisition starts at the
137  * first available sample.
138  * \param state - int=1 forces start of acquisition
139  */
140  void set_state(int32_t state);
141 
142  /*!
143  * \brief Set acquisition channel unique ID
144  * \param channel - receiver channel.
145  */
146  inline void set_channel(uint32_t channel)
147  {
148  d_channel = channel;
149  }
150 
151  /*!
152  * \brief Set channel fsm associated to this acquisition instance
153  */
154  inline void set_channel_fsm(std::weak_ptr<ChannelFsm> channel_fsm)
155  {
156  d_channel_fsm = std::move(channel_fsm);
157  }
158 
159  /*!
160  * \brief Set statistics threshold of PCPS algorithm.
161  * \param threshold - Threshold for signal detection (check \ref Navitec2012,
162  * Algorithm 1, for a definition of this threshold).
163  */
164  inline void set_threshold(float threshold)
165  {
166  d_threshold = threshold;
167  }
168 
169  /*!
170  * \brief Set maximum Doppler grid search
171  * \param doppler_max - Maximum Doppler shift considered in the grid search [Hz].
172  */
173  inline void set_doppler_max(uint32_t doppler_max)
174  {
175  d_doppler_max = doppler_max;
176  }
177 
178  /*!
179  * \brief Set Doppler steps for the grid search
180  * \param doppler_step - Frequency bin of the search grid [Hz].
181  */
182  inline void set_doppler_step(uint32_t doppler_step)
183  {
184  d_doppler_step = doppler_step;
185  }
186 
187  /*!
188  * \brief Parallel Code Phase Search Acquisition signal processing.
189  */
190  int general_work(int noutput_items, gr_vector_int& ninput_items,
191  gr_vector_const_void_star& input_items,
192  gr_vector_void_star& output_items);
193 
194 private:
195  friend pcps_quicksync_acquisition_cc_sptr
196  pcps_quicksync_make_acquisition_cc(uint32_t folding_factor,
197  uint32_t sampled_ms, uint32_t max_dwells,
198  uint32_t doppler_max, int64_t fs_in,
199  int32_t samples_per_ms, int32_t samples_per_code,
200  bool bit_transition_flag,
201  bool dump,
202  const std::string& dump_filename);
203 
204  pcps_quicksync_acquisition_cc(uint32_t folding_factor,
205  uint32_t sampled_ms, uint32_t max_dwells,
206  uint32_t doppler_max, int64_t fs_in,
207  int32_t samples_per_ms, int32_t samples_per_code,
208  bool bit_transition_flag,
209  bool dump,
210  const std::string& dump_filename);
211 
212  void calculate_magnitudes(gr_complex* fft_begin, int32_t doppler_shift,
213  int32_t doppler_offset);
214 
215  std::weak_ptr<ChannelFsm> d_channel_fsm;
216 
217  std::unique_ptr<gr::fft::fft_complex> d_fft_if;
218  std::unique_ptr<gr::fft::fft_complex> d_ifft;
219 
220  std::vector<std::vector<gr_complex>> d_grid_doppler_wipeoffs;
221  std::vector<gr_complex> d_code;
222  std::vector<gr_complex> d_fft_codes;
223  std::vector<gr_complex> d_signal_folded;
224  std::vector<gr_complex> d_code_folded;
225  std::vector<float> d_magnitude;
226  std::vector<float> d_corr_output_f;
227  std::vector<float> d_magnitude_folded;
228  std::vector<uint32_t> d_possible_delay;
229 
230  std::string d_dump_filename;
231  std::string d_satellite_str;
232 
233  std::ofstream d_dump_file;
234 
235  Gnss_Synchro* d_gnss_synchro;
236 
237  int64_t d_fs_in;
238  uint64_t d_sample_counter;
239 
240  float d_noise_floor_power;
241  float d_threshold;
242  float d_doppler_freq;
243  float d_mag;
244  float d_input_power;
245  float d_test_statistics;
246  int32_t d_samples_per_ms;
247  int32_t d_samples_per_code;
248  int32_t d_state;
249  uint32_t d_channel;
250  uint32_t d_folding_factor; // also referred in the paper as 'p'
251  uint32_t d_doppler_resolution;
252  uint32_t d_doppler_max;
253  uint32_t d_doppler_step;
254  uint32_t d_sampled_ms;
255  uint32_t d_max_dwells;
256  uint32_t d_well_count;
257  uint32_t d_fft_size;
258  uint32_t d_num_doppler_bins;
259  uint32_t d_code_phase;
260 
261  bool d_bit_transition_flag;
262  bool d_active;
263  bool d_dump;
264 };
265 
266 #endif // GNSS_SDR_PCPS_QUICKSYNC_ACQUISITION_CC_H
void set_channel_fsm(std::weak_ptr< ChannelFsm > channel_fsm)
Set channel fsm associated to this acquisition instance.
void set_channel(uint32_t channel)
Set acquisition channel unique ID.
void set_local_code(std::complex< float > *code)
Sets local code for PCPS acquisition algorithm.
uint32_t mag() const
Returns the maximum peak of grid search.
void set_state(int32_t state)
If set to 1, ensures that acquisition starts at the first available sample.
void init()
Initializes acquisition algorithm.
void set_doppler_step(uint32_t doppler_step)
Set Doppler steps for the grid search.
This class implements a Parallel Code Phase Search Acquisition with the implementation of the Sparse ...
Interface of the State Machine for channel.
void set_threshold(float threshold)
Set statistics threshold of PCPS algorithm.
This is the class that contains the information that is shared by the processing blocks.
Definition: gnss_synchro.h:33
void set_doppler_max(uint32_t doppler_max)
Set maximum Doppler grid search.
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.
void set_gnss_synchro(Gnss_Synchro *p_gnss_synchro)
Set acquisition/tracking common Gnss_Synchro object pointer to exchange synchronization data between ...
void set_active(bool active)
Starts acquisition algorithm, turning from standby mode to active mode.
~pcps_quicksync_acquisition_cc()
Default destructor.
Interface of the Gnss_Synchro class.