GNU Radio's FOOT Package
multi_block.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2013 Christopher D. Kilgour
4  * Copyright 2008, 2009 Dominic Spill, Michael Ossmann
5  * Copyright 2007 Dominic Spill
6  * Copyright 2005, 2006 Free Software Foundation, Inc.
7  *
8  * This is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * This software is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this software; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 
25 #ifndef INCLUDED_GR_BLUETOOTH_MULTI_BLOCK_H
26 #define INCLUDED_GR_BLUETOOTH_MULTI_BLOCK_H
27 
28 #include <gr_bluetooth/api.h>
29 #include <gnuradio/sync_block.h>
30 #include <gnuradio/filter/mmse_fir_interpolator_ff.h>
31 #include <gnuradio/filter/freq_xlating_fir_filter.h>
32 
33 namespace gr {
34  namespace bluetooth {
35 
36  /*!
37  * \brief Bluetooth multi-channel parent class.
38  * \ingroup bluetooth
39  */
40  class GR_BLUETOOTH_API multi_block : virtual public gr::sync_block
41  {
42  protected:
43  multi_block() {} // to allow for pure virtual
44  multi_block(double sample_rate, double center_freq, double squelch_threshold);
45 
46  /* symbols per second */
47  static const int SYMBOL_RATE = 1000000;
48 
49  static const int SYMBOLS_PER_BASIC_RATE_SHORTENED_ACCESS_CODE = 68;
50  static const int SYMBOLS_PER_LOW_ENERGY_PREAMBLE_AA = 40;
51 
52  /* length of time slot in symbols */
53  static const int SYMBOLS_PER_BASIC_RATE_SLOT = 625;
54  static const int SYMBOLS_FOR_BASIC_RATE_HISTORY = 3125;
55 
56  /* channel 0 in Hz */
57  static const uint32_t BASE_FREQUENCY = 2402000000UL;
58 
59  /* channel width in Hz */
60  static const int CHANNEL_WIDTH = 1000000;
61 
62  /* total number of samples elapsed */
64 
65  /* sample rate of raw input stream */
66  double d_sample_rate;
67 
68  /* number of raw samples per symbol */
70 
71  /* number of raw samples per time slot (625 microseconds) */
73 
74  /* center frequency of input stream */
75  double d_center_freq;
76 
77  /* lowest frequency we can decode */
78  double d_low_freq;
79 
80  /* highest frequency we can decode */
81  double d_high_freq;
82 
83  /* decimation rate of digital downconverter */
85 
86  /* mm_cr variables */
87  float d_gain_mu; // gain for adjusting mu
88  float d_mu; // fractional sample position [0.0, 1.0]
89  float d_omega_relative_limit; // used to compute min and max omega
90  float d_omega; // nominal frequency
91  float d_gain_omega; // gain for adjusting omega
92  float d_omega_mid; // average omega
94 
95  /* target SNR */
96  double d_target_snr;
97 
98  /* channel filter coefficients for digital downconverter */
100  std::vector<float> d_channel_filter;
101  std::map<int, gr::filter::freq_xlating_fir_filter_ccf::sptr> d_channel_ddcs;
102 
103  /* noise power filter coefficients */
105  std::vector<float> d_noise_filter;
106  std::map<int, gr::filter::freq_xlating_fir_filter_ccf::sptr> d_noise_ddcs;
107 
108  /* input sample offset where channel and noise extraction happens */
111 
112  /* quadrature frequency demodulator sensitivity */
114 
115  /* interpolator M&M clock recovery block */
116  gr::filter::mmse_fir_interpolator_ff *d_interp;
117 
118  /* M&M clock recovery, adapted from gr_clock_recovery_mm_ff */
119  int mm_cr(const float *in, int ninput_items, float *out, int noutput_items);
120 
121  /* fm demodulation, taken from gr_quadrature_demod_cf */
122  void demod(const gr_complex *in, float *out, int noutput_items);
123 
124  /* binary slicer, similar to gr_binary_slicer_fb */
125  void slicer(const float *in, char *out, int noutput_items);
126 
127  /**
128  * Extract a single BT channel's worth of samples from the wider
129  * bandwidth samples.
130  */
131  int channel_samples( const double freq,
132  gr_vector_const_void_star& in,
133  gr_vector_void_star& out,
134  double& energy,
135  int ninput_items );
136 
137  /**
138  * Produce symbols stream for a single BT channel, developed
139  * from of the raw samples for a single BT channel.
140  */
141  int channel_symbols( gr_vector_const_void_star &in,
142  char *out,
143  int ninput_items );
144 
145  bool check_snr( const double freq,
146  const double on_channel_energy,
147  double& snr,
148  gr_vector_const_void_star& in );
149 
150  /* add some number of symbols to the block's history requirement */
151  void set_symbol_history(int num_symbols);
152 
153  /* set available channels based on d_center_freq and d_sample_rate */
154  void set_channels();
155 
156  /* returns relative (with respect to d_center_freq) frequency in Hz of given channel */
157  double channel_rel_freq(int channel);
158 
159  double channel_abs_freq(int channel);
160 
161  int abs_freq_channel(double freq);
162 
163  public:
164  virtual int work (int noutput_items,
165  gr_vector_const_void_star &input_items,
166  gr_vector_void_star &output_items) = 0;
167  };
168 
169  } // namespace bluetooth
170 } // namespace gr
171 
172 #endif /* INCLUDED_GR_BLUETOOTH_MULTI_BLOCK_H */
173 
float d_gain_omega
Definition: multi_block.h:91
Bluetooth multi-channel parent class.
Definition: multi_block.h:40
multi_block()
Definition: multi_block.h:43
#define GR_BLUETOOTH_API
Definition: api.h:30
double d_sample_rate
Definition: multi_block.h:66
int d_first_channel_sample
Definition: multi_block.h:109
gr::filter::mmse_fir_interpolator_ff * d_interp
Definition: multi_block.h:116
double d_samples_per_slot
Definition: multi_block.h:72
std::vector< float > d_channel_filter
Definition: multi_block.h:100
float d_mu
Definition: multi_block.h:88
float d_omega_mid
Definition: multi_block.h:92
int d_first_noise_sample
Definition: multi_block.h:110
float d_gain_mu
Definition: multi_block.h:87
Definition: multi_block.h:33
double d_samples_per_symbol
Definition: multi_block.h:69
uint64_t d_cumulative_count
Definition: multi_block.h:63
double d_noise_filter_width
Definition: multi_block.h:104
std::map< int, gr::filter::freq_xlating_fir_filter_ccf::sptr > d_channel_ddcs
Definition: multi_block.h:101
double d_channel_filter_width
Definition: multi_block.h:99
float d_omega_relative_limit
Definition: multi_block.h:89
double d_low_freq
Definition: multi_block.h:78
float d_demod_gain
Definition: multi_block.h:113
float d_omega
Definition: multi_block.h:90
std::map< int, gr::filter::freq_xlating_fir_filter_ccf::sptr > d_noise_ddcs
Definition: multi_block.h:106
std::vector< float > d_noise_filter
Definition: multi_block.h:105
int d_ddc_decimation_rate
Definition: multi_block.h:84
double d_center_freq
Definition: multi_block.h:75
float d_last_sample
Definition: multi_block.h:93
double d_target_snr
Definition: multi_block.h:96
double d_high_freq
Definition: multi_block.h:81