GNU Radio's BLUETOOTH 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 <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
33namespace gr {
34 namespace bluetooth {
35
36 /*!
37 * \brief Bluetooth multi-channel parent class.
38 * \ingroup bluetooth
39 */
40 class 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
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 */
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 */
76
77 /* lowest frequency we can decode */
78 double d_low_freq;
79
80 /* highest frequency we can decode */
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 */
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 */
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
164} // namespace bluetooth
165} // namespace gr
166
167
168#endif /* INCLUDED_GR_BLUETOOTH_MULTI_BLOCK_H */
169
#define BLUETOOTH_API
Definition api.h:19
void slicer(const float *in, char *out, int noutput_items)
float d_gain_omega
Definition multi_block.h:91
int mm_cr(const float *in, int ninput_items, float *out, int noutput_items)
double d_center_freq
Definition multi_block.h:75
int d_first_noise_sample
Definition multi_block.h:110
bool check_snr(const double freq, const double on_channel_energy, double &snr, gr_vector_const_void_star &in)
std::map< int, gr::filter::freq_xlating_fir_filter_ccf::sptr > d_channel_ddcs
Definition multi_block.h:101
float d_omega_mid
Definition multi_block.h:92
void demod(const gr_complex *in, float *out, int noutput_items)
double d_target_snr
Definition multi_block.h:96
double d_samples_per_slot
Definition multi_block.h:72
float d_gain_mu
Definition multi_block.h:87
std::map< int, gr::filter::freq_xlating_fir_filter_ccf::sptr > d_noise_ddcs
Definition multi_block.h:106
static const int SYMBOL_RATE
Definition multi_block.h:47
static const int CHANNEL_WIDTH
Definition multi_block.h:60
int d_ddc_decimation_rate
Definition multi_block.h:84
float d_mu
Definition multi_block.h:88
float d_omega
Definition multi_block.h:90
static const int SYMBOLS_FOR_BASIC_RATE_HISTORY
Definition multi_block.h:54
void set_symbol_history(int num_symbols)
double d_noise_filter_width
Definition multi_block.h:104
multi_block(double sample_rate, double center_freq, double squelch_threshold)
multi_block()
Definition multi_block.h:43
double d_sample_rate
Definition multi_block.h:66
uint64_t d_cumulative_count
Definition multi_block.h:63
std::vector< float > d_noise_filter
Definition multi_block.h:105
static const int SYMBOLS_PER_LOW_ENERGY_PREAMBLE_AA
Definition multi_block.h:50
double d_samples_per_symbol
Definition multi_block.h:69
std::vector< float > d_channel_filter
Definition multi_block.h:100
gr::filter::mmse_fir_interpolator_ff * d_interp
Definition multi_block.h:116
float d_omega_relative_limit
Definition multi_block.h:89
double channel_rel_freq(int channel)
double channel_abs_freq(int channel)
static const int SYMBOLS_PER_BASIC_RATE_SLOT
Definition multi_block.h:53
float d_demod_gain
Definition multi_block.h:113
int channel_samples(const double freq, gr_vector_const_void_star &in, gr_vector_void_star &out, double &energy, int ninput_items)
double d_low_freq
Definition multi_block.h:78
static const uint32_t BASE_FREQUENCY
Definition multi_block.h:57
static const int SYMBOLS_PER_BASIC_RATE_SHORTENED_ACCESS_CODE
Definition multi_block.h:49
int d_first_channel_sample
Definition multi_block.h:109
double d_high_freq
Definition multi_block.h:81
int abs_freq_channel(double freq)
int channel_symbols(gr_vector_const_void_star &in, char *out, int ninput_items)
double d_channel_filter_width
Definition multi_block.h:99
float d_last_sample
Definition multi_block.h:93
Definition multi_block.h:34
Definition multi_block.h:33