GNU Radio 3.6.5.1 C++ API
digital_fll_band_edge_cc.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2009,2011,2012 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio 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  * GNU Radio 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 GNU Radio; 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 
24 #ifndef INCLUDED_DIGITAL_FLL_BAND_EDGE_CC_H
25 #define INCLUDED_DIGITAL_FLL_BAND_EDGE_CC_H
26 
27 #include <digital_api.h>
28 #include <gr_sync_block.h>
29 #include <gri_control_loop.h>
30 #include <gr_fir_util.h>
31 #include <gr_fir_ccc.h>
32 
33 typedef gr_fir_ccc* (*fir_maker_t)(const std::vector<gr_complex> &taps);
34 typedef gr_fir_ccc filter_t;
35 
39 digital_make_fll_band_edge_cc(float samps_per_sym,
40  float rolloff,
41  int filter_size,
42  float bandwidth);
43 
44 /*!
45  * \class digital_fll_band_edge_cc
46  * \brief Frequency Lock Loop using band-edge filters
47  * \ingroup synchronizers_blk
48  *
49  * \details
50  * The frequency lock loop derives a band-edge filter that covers the
51  * upper and lower bandwidths of a digitally-modulated signal. The
52  * bandwidth range is determined by the excess bandwidth (e.g.,
53  * rolloff factor) of the modulated signal. The placement in frequency
54  * of the band-edges is determined by the oversampling ratio (number
55  * of samples per symbol) and the excess bandwidth. The size of the
56  * filters should be fairly large so as to average over a number of
57  * symbols.
58  *
59  * The FLL works by filtering the upper and lower band edges into
60  * x_u(t) and x_l(t), respectively. These are combined to form cc(t)
61  * = x_u(t) + x_l(t) and ss(t) = x_u(t) - x_l(t). Combining these to
62  * form the signal e(t) = Re{cc(t) \\times ss(t)^*} (where ^* is the
63  * complex conjugate) provides an error signal at the DC term that is
64  * directly proportional to the carrier frequency. We then make a
65  * second-order loop using the error signal that is the running
66  * average of e(t).
67  *
68  * In practice, the above equation can be simplified by just comparing
69  * the absolute value squared of the output of both filters:
70  * abs(x_l(t))^2 - abs(x_u(t))^2 = norm(x_l(t)) - norm(x_u(t)).
71  *
72  * In theory, the band-edge filter is the derivative of the matched
73  * filter in frequency, (H_be(f) = frac{H(f)}{df}). In practice,
74  * this comes down to a quarter sine wave at the point of the matched
75  * filter's rolloff (if it's a raised-cosine, the derivative of a
76  * cosine is a sine). Extend this sine by another quarter wave to
77  * make a half wave around the band-edges is equivalent in time to the
78  * sum of two sinc functions. The baseband filter fot the band edges
79  * is therefore derived from this sum of sincs. The band edge filters
80  * are then just the baseband signal modulated to the correct place in
81  * frequency. All of these calculations are done in the
82  * 'design_filter' function.
83  *
84  * Note: We use FIR filters here because the filters have to have a
85  * flat phase response over the entire frequency range to allow their
86  * comparisons to be valid.
87  *
88  * It is very important that the band edge filters be the derivatives
89  * of the pulse shaping filter, and that they be linear
90  * phase. Otherwise, the variance of the error will be very large.
91  *
92  */
93 
95  public gr_sync_block, public gri_control_loop
96 {
97  private:
98  /*!
99  * Build the FLL
100  * \param samps_per_sym (float) Number of samples per symbol of signal
101  * \param rolloff (float) Rolloff factor of signal
102  * \param filter_size (int) Size (in taps) of the filter
103  * \param bandwidth (float) Loop bandwidth
104  */
106  digital_make_fll_band_edge_cc(float samps_per_sym,
107  float rolloff,
108  int filter_size,
109  float bandwidth);
110 
111  float d_sps;
112  float d_rolloff;
113  int d_filter_size;
114 
115  std::vector<gr_complex> d_taps_lower;
116  std::vector<gr_complex> d_taps_upper;
117  bool d_updated;
118  filter_t* d_filter_lower;
119  filter_t* d_filter_upper;
120  std::vector<gr_complex> d_output_hist;
121  std::vector<gr_complex> d_fllbuffer;
122 
123  /*!
124  * Build the FLL
125  * \param samps_per_sym (float) number of samples per symbol
126  * \param rolloff (float) Rolloff (excess bandwidth) of signal filter
127  * \param filter_size (int) number of filter taps to generate
128  * \param bandwidth (float) Loop bandwidth
129  */
130  digital_fll_band_edge_cc(float samps_per_sym, float rolloff,
131  int filter_size, float bandwidth);
132 
133  /*!
134  * Design the band-edge filter based on the number of samples per symbol,
135  * filter rolloff factor, and the filter size
136  *
137  * \param samps_per_sym (float) Number of samples per symbol of signal
138  * \param rolloff (float) Rolloff factor of signal
139  * \param filter_size (int) Size (in taps) of the filter
140  */
141  void design_filter(float samps_per_sym, float rolloff, int filter_size);
142 
143 public:
145 
146  /*******************************************************************
147  SET FUNCTIONS
148  *******************************************************************/
149 
150  /*!
151  * \brief Set the number of samples per symbol
152  *
153  * Set's the number of samples per symbol the system should
154  * use. This value is uesd to calculate the filter taps and will
155  * force a recalculation.
156  *
157  * \param sps (float) new samples per symbol
158  *
159  */
160  void set_samples_per_symbol(float sps);
161 
162  /*!
163  * \brief Set the rolloff factor of the shaping filter
164  *
165  * This sets the rolloff factor that is used in the pulse shaping
166  * filter and is used to calculate the filter taps. Changing this
167  * will force a recalculation of the filter taps.
168  *
169  * This should be the same value that is used in the transmitter's
170  * pulse shaping filter. It must be between 0 and 1 and is usually
171  * between 0.2 and 0.5 (where 0.22 and 0.35 are commonly used
172  * values).
173  *
174  * \param rolloff (float) new shaping filter rolloff factor [0,1]
175  *
176  */
177  void set_rolloff(float rolloff);
178 
179  /*!
180  * \brief Set the number of taps in the filter
181  *
182  * This sets the number of taps in the band-edge filters. Setting
183  * this will force a recalculation of the filter taps.
184  *
185  * This should be about the same number of taps used in the
186  * transmitter's shaping filter and also not very large. A large
187  * number of taps will result in a large delay between input and
188  * frequency estimation, and so will not be as accurate. Between 30
189  * and 70 taps is usual.
190  *
191  * \param filter_size (float) number of taps in the filters
192  *
193  */
194  void set_filter_size(int filter_size);
195 
196  /*******************************************************************
197  GET FUNCTIONS
198  *******************************************************************/
199 
200  /*!
201  * \brief Returns the number of sampler per symbol used for the filter
202  */
203  float get_samples_per_symbol() const;
204 
205  /*!
206  * \brief Returns the rolloff factor used for the filter
207  */
208  float get_rolloff() const;
209 
210  /*!
211  * \brief Returns the number of taps of the filter
212  */
213  int get_filter_size() const;
214 
215  /*!
216  * Print the taps to screen.
217  */
218  void print_taps();
219 
220  int work(int noutput_items,
221  gr_vector_const_void_star &input_items,
222  gr_vector_void_star &output_items);
223 };
224 
225 #endif