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