GNU Radio's GSM Package
receiver_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * @file
4  * @author (C) 2009-2017 by Piotr Krysik <ptrkrysik@gmail.com>
5  * @section LICENSE
6  *
7  * Gr-gsm is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * Gr-gsm is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with gr-gsm; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_GSM_RECEIVER_IMPL_H
24 #define INCLUDED_GSM_RECEIVER_IMPL_H
25 
27 #include <grgsm/gsmtap.h>
28 #include <grgsm/gsm_constants.h>
29 #include <receiver_config.h>
30 #include <vector>
31 #include "time_sample_ref.h"
32 
33 namespace gr {
34  namespace gsm {
35  class receiver_impl : public receiver
36  {
37  private:
38  unsigned int d_samples_consumed;
39  bool d_rx_time_received;
40  time_sample_ref d_time_samp_ref;
41  int d_c0_burst_start;
42  float d_c0_signal_dbm;
43 
44  /**@name Configuration of the receiver */
45  //@{
46  const int d_OSR; ///< oversampling ratio
47  bool d_process_uplink;
48  const int d_chan_imp_length; ///< channel impulse length
49  float d_signal_dbm;
50  std::vector<int> d_tseq_nums; ///< stores training sequence numbers for channels different than C0
51  std::vector<int> d_cell_allocation; ///< stores cell allocation - absolute rf channel numbers (ARFCNs) assigned to the given cell. The variable should at least contain C0 channel number.
52  //@}
53 
54  gr_complex d_sch_training_seq[N_SYNC_BITS]; ///<encoded training sequence of a SCH burst
55  gr_complex d_norm_training_seq[TRAIN_SEQ_NUM][N_TRAIN_BITS]; ///<encoded training sequences of a normal and dummy burst
56 
57  float d_last_time;
58 
59  /** Counts samples consumed by the receiver
60  *
61  * It is used in beetween find_fcch_burst and reach_sch_burst calls.
62  * My intention was to synchronize this counter with some internal sample
63  * counter of the USRP. Simple access to such USRP's counter isn't possible
64  * so this variable isn't used in the "synchronized" state of the receiver yet.
65  */
66  unsigned d_counter;
67 
68  /**@name Variables used to store result of the find_fcch_burst fuction */
69  //@{
70  bool d_freq_offset_tag_in_fcch; ///< frequency offset tag presence
71  unsigned d_fcch_start_pos; ///< position of the first sample of the fcch burst
72  float d_freq_offset_setting; ///< frequency offset set in frequency shifter located upstream
73  //@}
74  std::list<double> d_freq_offset_vals;
75 
76  /**@name Identifiers of the BTS extracted from the SCH burst */
77  //@{
78  int d_ncc; ///< network color code
79  int d_bcc; ///< base station color code
80  //@}
81 
82  /**@name Internal state of the gsm receiver */
83  //@{
84  enum states {
85  fcch_search, sch_search, // synchronization search part
86  synchronized // receiver is synchronized in this state
87  } d_state;
88  //@}
89 
90  /**@name Variables which make internal state in the "synchronized" state */
91  //@{
92  burst_counter d_burst_nr; ///< frame number and timeslot number
93  channel_configuration d_channel_conf; ///< mapping of burst_counter to burst_type
94  //@}
95 
96  unsigned d_failed_sch; ///< number of subsequent erroneous SCH bursts
97 
98  /** Function whis is used to search a FCCH burst and to compute frequency offset before
99  * "synchronized" state of the receiver
100  *
101  * @param input vector with input signal
102  * @param nitems number of samples in the input vector
103  * @return
104  */
105  bool find_fcch_burst(const gr_complex *input, const int nitems, double & computed_freq_offset);
106 
107  /** Computes frequency offset from FCCH burst samples
108  *
109  * @param[in] input vector with input samples
110  * @param[in] first_sample number of the first sample of the FCCH busrt
111  * @param[in] last_sample number of the last sample of the FCCH busrt
112  * @param[out] computed_freq_offset contains frequency offset estimate if FCCH burst was located
113  * @return true if frequency offset was faound
114  */
115  double compute_freq_offset(const gr_complex * input, unsigned first_sample, unsigned last_sample);
116  /** Computes angle between two complex numbers
117  *
118  * @param val1 first complex number
119  * @param val2 second complex number
120  * @return
121  */
122  inline float compute_phase_diff(gr_complex val1, gr_complex val2);
123 
124  /** Function whis is used to get near to SCH burst
125  *
126  * @param nitems number of samples in the gsm_receiver's buffer
127  * @return true if SCH burst is near, false otherwise
128  */
129  bool reach_sch_burst(const int nitems);
130 
131  /** Extracts channel impulse response from a SCH burst and computes first sample number of this burst
132  *
133  * @param input vector with input samples
134  * @param chan_imp_resp complex vector where channel impulse response will be stored
135  * @return number of first sample of the burst
136  */
137  int get_sch_chan_imp_resp(const gr_complex *input, gr_complex * chan_imp_resp);
138 
139  /** MLSE detection of a burst bits
140  *
141  * Detects bits of burst using viterbi algorithm.
142  * @param input vector with input samples
143  * @param chan_imp_resp vector with the channel impulse response
144  * @param burst_start number of the first sample of the burst
145  * @param output_binary vector with output bits
146  */
147  void detect_burst(const gr_complex * input, gr_complex * chan_imp_resp, int burst_start, unsigned char * output_binary);
148 
149  /** Encodes differentially input bits and maps them into MSK states
150  *
151  * @param input vector with input bits
152  * @param nitems number of samples in the "input" vector
153  * @param gmsk_output bits mapped into MSK states
154  * @param start_point first state
155  */
156  void gmsk_mapper(const unsigned char * input, int nitems, gr_complex * gmsk_output, gr_complex start_point);
157 
158  /** Correlates MSK mapped sequence with input signal
159  *
160  * @param sequence MKS mapped sequence
161  * @param length length of the sequence
162  * @param input_signal vector with input samples
163  * @return correlation value
164  */
165  gr_complex correlate_sequence(const gr_complex * sequence, int length, const gr_complex * input);
166 
167  /** Computes autocorrelation of input vector for positive arguments
168  *
169  * @param input vector with input samples
170  * @param out output vector
171  * @param nitems length of the input vector
172  */
173  inline void autocorrelation(const gr_complex * input, gr_complex * out, int nitems);
174 
175  /** Filters input signal through channel impulse response
176  *
177  * @param input vector with input samples
178  * @param nitems number of samples to pass through filter
179  * @param filter filter taps - channel impulse response
180  * @param filter_length nember of filter taps
181  * @param output vector with filtered samples
182  */
183  inline void mafi(const gr_complex * input, int nitems, gr_complex * filter, int filter_length, gr_complex * output);
184 
185  /** Extracts channel impulse response from a normal burst and computes first sample number of this burst
186  *
187  * @param input vector with input samples
188  * @param chan_imp_resp complex vector where channel impulse response will be stored
189  * @param search_range possible absolute offset of a channel impulse response start
190  * @param bcc base station color code - number of a training sequence
191  * @return first sample number of normal burst
192  */
193  int get_norm_chan_imp_resp(const gr_complex *input, gr_complex * chan_imp_resp, float *corr_max, int bcc);
194 
195  /**
196  * Sends burst through a C0 (for burst from C0 channel) or Cx (for other bursts) message port
197  *
198  * @param burst_nr - frame number of the burst
199  * @param burst_binary - content of the burst
200  * @b_type - type of the burst
201  */
202  void send_burst(burst_counter burst_nr, const unsigned char * burst_binary, uint8_t burst_type, size_t input_nr, unsigned int burst_start=-1);
203 
204  /**
205  * Configures burst types in different channels
206  */
207  void configure_receiver();
208 
209  /* State machine handlers */
210  void fcch_search_handler(gr_complex *input, int noutput_items);
211  void sch_search_handler(gr_complex *input, int noutput_items);
212  void synchronized_handler(gr_complex *input,
213  gr_vector_const_void_star &input_items, int noutput_items);
214 
215  public:
216  receiver_impl(int osr, const std::vector<int> &cell_allocation, const std::vector<int> &tseq_nums, bool process_uplink);
217  ~receiver_impl();
218 
219  int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items);
220  virtual void set_cell_allocation(const std::vector<int> &cell_allocation);
221  virtual void set_tseq_nums(const std::vector<int> & tseq_nums);
222  virtual void reset();
223  };
224  } // namespace gsm
225 } // namespace gr
226 
227 #endif /* INCLUDED_GSM_RECEIVER_IMPL_H */
228 
gr::gsm::receiver_impl::set_tseq_nums
virtual void set_tseq_nums(const std::vector< int > &tseq_nums)
burst_counter
Definition: receiver_config.h:66
gr::gsm::receiver_impl::~receiver_impl
~receiver_impl()
gr::gsm::receiver_impl::receiver_impl
receiver_impl(int osr, const std::vector< int > &cell_allocation, const std::vector< int > &tseq_nums, bool process_uplink)
TRAIN_SEQ_NUM
#define TRAIN_SEQ_NUM
Definition: gsm_constants.h:93
gsm_constants.h
N_SYNC_BITS
#define N_SYNC_BITS
Definition: gsm_constants.h:37
gr::gsm::time_sample_ref
Definition: time_sample_ref.h:34
channel_configuration
Definition: receiver_config.h:130
gr::gsm::receiver_impl::work
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
time_sample_ref.h
burst_type
burst_type
Definition: gsm_constants.h:63
N_TRAIN_BITS
#define N_TRAIN_BITS
Definition: gsm_constants.h:36
receiver.h
gr
Definition: constants.h:29
gr::gsm::receiver
<+description of block+>
Definition: receiver.h:40
gr::gsm::receiver_impl
Definition: receiver_impl.h:35
receiver_config.h
gr::gsm::receiver_impl::set_cell_allocation
virtual void set_cell_allocation(const std::vector< int > &cell_allocation)
gsmtap.h
gr::gsm::receiver_impl::reset
virtual void reset()
bcc
uint8_t bcc
Definition: gsm_04_08.h:2