GNSS-SDR  0.0.17
An Open Source GNSS Software Defined Receiver
kf_vtl_tracking.h
1 /*!
2  * \file kf_vtl_tracking.cc
3  * \brief Implementation of a Kalman filter based tracking with optional Vector
4  * Tracking Loop message receiver block.
5  * \author Javier Arribas, 2020. jarribas(at)cttc.es
6  *
7  * -----------------------------------------------------------------------------
8  *
9  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
10  *
11  * GNSS-SDR is a software defined Global Navigation
12  * Satellite Systems receiver
13  *
14  * This file is part of GNSS-SDR.
15  *
16  * SPDX-License-Identifier: GPL-3.0-or-later
17  *
18  * -----------------------------------------------------------------------------
19  */
20 
21 #ifndef GNSS_SDR_KF_VTL_TRACKING_H
22 #define GNSS_SDR_KF_VTL_TRACKING_H
23 
24 #if ARMA_NO_BOUND_CHECKING
25 #define ARMA_NO_DEBUG 1
26 #endif
27 
29 #include "exponential_smoother.h"
30 #include "gnss_block_interface.h"
31 #include "gnss_time.h" // for timetags produced by File_Timestamp_Signal_Source
32 #include "kf_conf.h"
33 #include "tracking_FLL_PLL_filter.h" // for PLL/FLL filter
34 #include "tracking_loop_filter.h" // for DLL filter
35 #include <armadillo>
36 #include <boost/circular_buffer.hpp>
37 #include <gnuradio/block.h> // for block
38 #include <gnuradio/gr_complex.h> // for gr_complex
39 #include <gnuradio/types.h> // for gr_vector_int, gr_vector...
40 #include <pmt/pmt.h> // for pmt_t
41 #include <volk_gnsssdr/volk_gnsssdr_alloc.h> // for volk_gnsssdr::vector
42 #include <cstddef> // for size_t
43 #include <cstdint> // for int32_t
44 #include <fstream> // for ofstream
45 #include <memory>
46 #include <string> // for string
47 #include <typeinfo> // for typeid
48 #include <utility> // for pair
49 
50 class Gnss_Synchro;
51 class kf_vtl_tracking;
52 
53 using kf_vtl_tracking_sptr = gnss_shared_ptr<kf_vtl_tracking>;
54 
55 kf_vtl_tracking_sptr kf_vtl_make_tracking(const Kf_Conf &conf_);
56 
57 /*!
58  * \brief This class implements a code DLL + carrier PLL tracking block.
59  */
60 class kf_vtl_tracking : public gr::block
61 {
62 public:
63  ~kf_vtl_tracking();
64 
65  void set_channel(uint32_t channel);
66  void set_gnss_synchro(Gnss_Synchro *p_gnss_synchro);
67  void start_tracking();
68  void stop_tracking();
69 
70  int general_work(int noutput_items, gr_vector_int &ninput_items,
71  gr_vector_const_void_star &input_items, gr_vector_void_star &output_items);
72 
73  void forecast(int noutput_items, gr_vector_int &ninput_items_required);
74 
75 private:
76  friend kf_vtl_tracking_sptr kf_vtl_make_tracking(const Kf_Conf &conf_);
77  explicit kf_vtl_tracking(const Kf_Conf &conf_);
78 
79  void init_kf(double acq_code_phase_chips, double acq_doppler_hz);
80  void update_kf_narrow_integration_time();
81  void update_kf_cn0(double current_cn0_dbhz);
82  void run_Kf();
83 
84  void msg_handler_telemetry_to_trk(const pmt::pmt_t &msg);
85  void msg_handler_pvt_to_trk(const pmt::pmt_t &msg);
86  void do_correlation_step(const gr_complex *input_samples);
87 
88  void check_carrier_phase_coherent_initialization();
89  void update_tracking_vars();
90  void clear_tracking_vars();
91  void save_correlation_results();
92  void log_data();
93  bool cn0_and_tracking_lock_status(double coh_integration_time_s);
94  bool acquire_secondary();
95  int32_t save_matfile() const;
96 
97  Cpu_Multicorrelator_Real_Codes d_multicorrelator_cpu;
98  Cpu_Multicorrelator_Real_Codes d_correlator_data_cpu; // for data channel
99 
100  Kf_Conf d_trk_parameters;
101 
102  Exponential_Smoother d_cn0_smoother;
103  Exponential_Smoother d_carrier_lock_test_smoother;
104 
105  Gnss_Synchro *d_acquisition_gnss_synchro;
106 
107  volk_gnsssdr::vector<float> d_tracking_code;
108  volk_gnsssdr::vector<float> d_data_code;
109  volk_gnsssdr::vector<float> d_local_code_shift_chips;
110  volk_gnsssdr::vector<gr_complex> d_correlator_outs;
111  volk_gnsssdr::vector<gr_complex> d_Prompt_Data;
112  volk_gnsssdr::vector<gr_complex> d_Prompt_buffer;
113 
114  boost::circular_buffer<gr_complex> d_Prompt_circular_buffer;
115 
116  const size_t d_int_type_hash_code = typeid(int).hash_code();
117 
118  // Kalman Filter class variables
119  arma::mat d_F;
120  arma::mat d_H;
121  arma::mat d_R;
122  arma::mat d_Q;
123  arma::mat d_P_old_old;
124  arma::mat d_P_new_old;
125  arma::mat d_P_new_new;
126  arma::vec d_x_old_old;
127  arma::vec d_x_new_old;
128  arma::vec d_x_new_new;
129 
130  std::string d_secondary_code_string;
131  std::string d_data_secondary_code_string;
132  std::string d_systemName;
133  std::string d_signal_type;
134  std::string d_signal_pretty_name;
135  std::string d_dump_filename;
136 
137  std::ofstream d_dump_file;
138 
139  gr_complex *d_Very_Early;
140  gr_complex *d_Early;
141  gr_complex *d_Prompt;
142  gr_complex *d_Late;
143  gr_complex *d_Very_Late;
144 
145  gr_complex d_VE_accu;
146  gr_complex d_E_accu;
147  gr_complex d_P_accu;
148  gr_complex d_P_accu_old;
149  gr_complex d_L_accu;
150  gr_complex d_VL_accu;
151  gr_complex d_P_data_accu;
152 
153  // nominal signal parameters
154  double d_signal_carrier_freq;
155  double d_code_period;
156  double d_code_chip_rate;
157 
158  // acquisition
159  double d_acq_code_phase_samples;
160  double d_acq_carrier_doppler_hz;
161  double d_current_correlation_time_s;
162 
163  // carrier and code discriminators output
164  double d_carr_phase_error_disc_hz;
165  double d_code_error_disc_chips;
166 
167  // estimated parameters
168  // code
169  double d_code_error_kf_chips;
170  double d_code_freq_kf_chips_s;
171  // carrier
172  double d_carrier_phase_kf_rad;
173  double d_carrier_doppler_kf_hz;
174  double d_carrier_doppler_rate_kf_hz_s;
175 
176  double d_acc_carrier_phase_rad;
177 
178  double d_T_chip_seconds;
179  double d_T_prn_seconds;
180  double d_T_prn_samples;
181  double d_K_blk_samples;
182  double d_carrier_lock_test;
183  double d_CN0_SNV_dB_Hz;
184  double d_carrier_lock_threshold;
185 
186  // carrier NCO
187  double d_carrier_phase_step_rad;
188  double d_carrier_phase_rate_step_rad;
189 
190  // code NCO
191  double d_code_phase_step_chips;
192  double d_code_phase_rate_step_chips;
193  double d_rem_code_phase_chips;
194  double d_rem_code_phase_samples;
195 
196  uint64_t d_sample_counter;
197  uint64_t d_acq_sample_stamp;
198 
199  float *d_prompt_data_shift;
200  float d_rem_carr_phase_rad;
201 
202  uint32_t d_channel;
203  uint32_t d_secondary_code_length;
204  uint32_t d_data_secondary_code_length;
205 
206  int32_t d_symbols_per_bit;
207  int32_t d_state;
208  int32_t d_correlation_length_ms;
209  int32_t d_n_correlator_taps;
210  int32_t d_current_prn_length_samples;
211  int32_t d_extend_correlation_symbols_count;
212  int32_t d_current_symbol;
213  int32_t d_current_data_symbol;
214  int32_t d_cn0_estimation_counter;
215  int32_t d_carrier_lock_fail_counter;
216  int32_t d_code_lock_fail_counter;
217  int32_t d_code_samples_per_chip; // All signals have 1 sample per chip code except Gal. E1 which has 2 (CBOC disabled) or 12 (CBOC enabled)
218  int32_t d_code_length_chips;
219 
220  bool d_pull_in_transitory;
221  bool d_corrected_doppler;
222  bool d_interchange_iq;
223  bool d_veml;
224  bool d_cloop;
225  bool d_secondary;
226  bool d_dump;
227  bool d_dump_mat;
228  bool d_acc_carrier_phase_initialized;
229  bool d_enable_extended_integration;
230 };
231 
232 #endif // GNSS_SDR_KF_VTL_TRACKING_H
class that stores both the receiver time, relative to the receiver start and the GNSS time (absolute)...
This is the class that contains the information that is shared by the processing blocks.
Definition: gnss_synchro.h:38
This interface represents a GNSS block.
Highly optimized CPU vector multiTAP correlator class using real-valued local codes.
Class that implements a first-order exponential smoother.
Class that implements carrier wipe-off and correlators.
This class implements a code DLL + carrier PLL tracking block.
Generic 1st to 3rd order loop filter implementation.
Interface of a hybrid FLL and PLL filter for tracking carrier loop.
Class that implements an exponential smoother.