GNU Radio's GSM Package
receiver_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * @file
4  * @author 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 <gsm_constants.h>
29 #include <receiver_config.h>
30 #include <vector>
31 
32 namespace gr {
33  namespace gsm {
34  class receiver_impl : public receiver
35  {
36  private:
37  unsigned int d_c0_burst_start;
38  float d_c0_signal_dbm;
39  /**@name Configuration of the receiver */
40  //@{
41  const int d_OSR; ///< oversampling ratio
42  bool d_process_uplink;
43  const int d_chan_imp_length; ///< channel impulse length
44  float d_signal_dbm;
45  std::vector<int> d_tseq_nums; ///< stores training sequence numbers for channels different than C0
46  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.
47  //@}
48 
49  gr_complex d_sch_training_seq[N_SYNC_BITS]; ///<encoded training sequence of a SCH burst
50  gr_complex d_norm_training_seq[TRAIN_SEQ_NUM][N_TRAIN_BITS]; ///<encoded training sequences of a normal and dummy burst
51 
52  float d_last_time;
53 
54  /** Counts samples consumed by the receiver
55  *
56  * It is used in beetween find_fcch_burst and reach_sch_burst calls.
57  * My intention was to synchronize this counter with some internal sample
58  * counter of the USRP. Simple access to such USRP's counter isn't possible
59  * so this variable isn't used in the "synchronized" state of the receiver yet.
60  */
61  unsigned d_counter;
62 
63  /**@name Variables used to store result of the find_fcch_burst fuction */
64  //@{
65  unsigned d_fcch_start_pos; ///< position of the first sample of the fcch burst
66  float d_freq_offset_setting; ///< frequency offset set in frequency shifter located upstream
67  //@}
68  std::list<double> d_freq_offset_vals;
69 
70  /**@name Identifiers of the BTS extracted from the SCH burst */
71  //@{
72  int d_ncc; ///< network color code
73  int d_bcc; ///< base station color code
74  //@}
75 
76  /**@name Internal state of the gsm receiver */
77  //@{
78  enum states {
79  fcch_search, sch_search, // synchronization search part
80  synchronized // receiver is synchronized in this state
81  } d_state;
82  //@}
83 
84  /**@name Variables which make internal state in the "synchronized" state */
85  //@{
86  burst_counter d_burst_nr; ///< frame number and timeslot number
87  channel_configuration d_channel_conf; ///< mapping of burst_counter to burst_type
88  //@}
89 
90  unsigned d_failed_sch; ///< number of subsequent erroneous SCH bursts
91 
92  /** Function whis is used to search a FCCH burst and to compute frequency offset before
93  * "synchronized" state of the receiver
94  *
95  * @param input vector with input signal
96  * @param nitems number of samples in the input vector
97  * @return
98  */
99  bool find_fcch_burst(const gr_complex *input, const int nitems, double & computed_freq_offset);
100 
101  /** Computes frequency offset from FCCH burst samples
102  *
103  * @param[in] input vector with input samples
104  * @param[in] first_sample number of the first sample of the FCCH busrt
105  * @param[in] last_sample number of the last sample of the FCCH busrt
106  * @param[out] computed_freq_offset contains frequency offset estimate if FCCH burst was located
107  * @return true if frequency offset was faound
108  */
109  double compute_freq_offset(const gr_complex * input, unsigned first_sample, unsigned last_sample);
110 
111  /** Computes angle between two complex numbers
112  *
113  * @param val1 first complex number
114  * @param val2 second complex number
115  * @return
116  */
117  inline float compute_phase_diff(gr_complex val1, gr_complex val2);
118 
119  /** Function whis is used to get near to SCH burst
120  *
121  * @param nitems number of samples in the gsm_receiver's buffer
122  * @return true if SCH burst is near, false otherwise
123  */
124  bool reach_sch_burst(const int nitems);
125 
126  /** Extracts channel impulse response from a SCH burst and computes first sample number of this burst
127  *
128  * @param input vector with input samples
129  * @param chan_imp_resp complex vector where channel impulse response will be stored
130  * @return number of first sample of the burst
131  */
132  int get_sch_chan_imp_resp(const gr_complex *input, gr_complex * chan_imp_resp);
133 
134  /** MLSE detection of a burst bits
135  *
136  * Detects bits of burst using viterbi algorithm.
137  * @param input vector with input samples
138  * @param chan_imp_resp vector with the channel impulse response
139  * @param burst_start number of the first sample of the burst
140  * @param output_binary vector with output bits
141  */
142  void detect_burst(const gr_complex * input, gr_complex * chan_imp_resp, int burst_start, unsigned char * output_binary);
143 
144  /** Encodes differentially input bits and maps them into MSK states
145  *
146  * @param input vector with input bits
147  * @param nitems number of samples in the "input" vector
148  * @param gmsk_output bits mapped into MSK states
149  * @param start_point first state
150  */
151  void gmsk_mapper(const unsigned char * input, int nitems, gr_complex * gmsk_output, gr_complex start_point);
152 
153  /** Correlates MSK mapped sequence with input signal
154  *
155  * @param sequence MKS mapped sequence
156  * @param length length of the sequence
157  * @param input_signal vector with input samples
158  * @return correlation value
159  */
160  gr_complex correlate_sequence(const gr_complex * sequence, int length, const gr_complex * input);
161 
162  /** Computes autocorrelation of input vector for positive arguments
163  *
164  * @param input vector with input samples
165  * @param out output vector
166  * @param nitems length of the input vector
167  */
168  inline void autocorrelation(const gr_complex * input, gr_complex * out, int nitems);
169 
170  /** Filters input signal through channel impulse response
171  *
172  * @param input vector with input samples
173  * @param nitems number of samples to pass through filter
174  * @param filter filter taps - channel impulse response
175  * @param filter_length nember of filter taps
176  * @param output vector with filtered samples
177  */
178  inline void mafi(const gr_complex * input, int nitems, gr_complex * filter, int filter_length, gr_complex * output);
179 
180  /** Extracts channel impulse response from a normal burst and computes first sample number of this burst
181  *
182  * @param input vector with input samples
183  * @param chan_imp_resp complex vector where channel impulse response will be stored
184  * @param search_range possible absolute offset of a channel impulse response start
185  * @param bcc base station color code - number of a training sequence
186  * @return first sample number of normal burst
187  */
188  int get_norm_chan_imp_resp(const gr_complex *input, gr_complex * chan_imp_resp, float *corr_max, int bcc);
189 
190  /**
191  * Sends burst through a C0 (for burst from C0 channel) or Cx (for other bursts) message port
192  *
193  * @param burst_nr - frame number of the burst
194  * @param burst_binary - content of the burst
195  * @b_type - type of the burst
196  */
197  void send_burst(burst_counter burst_nr, const unsigned char * burst_binary, uint8_t burst_type, unsigned int input_nr);
198 
199  /**
200  * Configures burst types in different channels
201  */
202  void configure_receiver();
203 
204 
205 
206  public:
207  receiver_impl(int osr, const std::vector<int> &cell_allocation, const std::vector<int> &tseq_nums, bool process_uplink);
208  ~receiver_impl();
209 
210  int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items);
211  virtual void set_cell_allocation(const std::vector<int> &cell_allocation);
212  virtual void set_tseq_nums(const std::vector<int> & tseq_nums);
213  virtual void reset();
214  };
215  } // namespace gsm
216 } // namespace gr
217 
218 #endif /* INCLUDED_GSM_RECEIVER_IMPL_H */
219 
Definition: receiver_config.h:131
virtual void set_cell_allocation(const std::vector< int > &cell_allocation)
virtual void reset()
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
#define N_TRAIN_BITS
Definition: gsm_constants.h:36
#define TRAIN_SEQ_NUM
Definition: gsm_constants.h:92
burst_type
Definition: gsm_constants.h:62
#define N_SYNC_BITS
Definition: gsm_constants.h:37
receiver_impl(int osr, const std::vector< int > &cell_allocation, const std::vector< int > &tseq_nums, bool process_uplink)
Definition: receiver_config.h:67
Definition: receiver_impl.h:34
virtual void set_tseq_nums(const std::vector< int > &tseq_nums)
&lt;+description of block+&gt;
Definition: receiver.h:41