GNU Radio 3.6.5 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2009,2011,2012 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 00024 #ifndef INCLUDED_DIGITAL_FLL_BAND_EDGE_CC_H 00025 #define INCLUDED_DIGITAL_FLL_BAND_EDGE_CC_H 00026 00027 #include <digital_api.h> 00028 #include <gr_sync_block.h> 00029 #include <gri_control_loop.h> 00030 #include <gr_fir_util.h> 00031 #include <gr_fir_ccc.h> 00032 00033 typedef gr_fir_ccc* (*fir_maker_t)(const std::vector<gr_complex> &taps); 00034 typedef gr_fir_ccc filter_t; 00035 00036 class digital_fll_band_edge_cc; 00037 typedef boost::shared_ptr<digital_fll_band_edge_cc> digital_fll_band_edge_cc_sptr; 00038 DIGITAL_API digital_fll_band_edge_cc_sptr 00039 digital_make_fll_band_edge_cc(float samps_per_sym, 00040 float rolloff, 00041 int filter_size, 00042 float bandwidth); 00043 00044 /*! 00045 * \class digital_fll_band_edge_cc 00046 * \brief Frequency Lock Loop using band-edge filters 00047 * \ingroup synchronizers_blk 00048 * 00049 * \details 00050 * The frequency lock loop derives a band-edge filter that covers the 00051 * upper and lower bandwidths of a digitally-modulated signal. The 00052 * bandwidth range is determined by the excess bandwidth (e.g., 00053 * rolloff factor) of the modulated signal. The placement in frequency 00054 * of the band-edges is determined by the oversampling ratio (number 00055 * of samples per symbol) and the excess bandwidth. The size of the 00056 * filters should be fairly large so as to average over a number of 00057 * symbols. 00058 * 00059 * The FLL works by filtering the upper and lower band edges into 00060 * x_u(t) and x_l(t), respectively. These are combined to form cc(t) 00061 * = x_u(t) + x_l(t) and ss(t) = x_u(t) - x_l(t). Combining these to 00062 * form the signal e(t) = Re{cc(t) \\times ss(t)^*} (where ^* is the 00063 * complex conjugate) provides an error signal at the DC term that is 00064 * directly proportional to the carrier frequency. We then make a 00065 * second-order loop using the error signal that is the running 00066 * average of e(t). 00067 * 00068 * In practice, the above equation can be simplified by just comparing 00069 * the absolute value squared of the output of both filters: 00070 * abs(x_l(t))^2 - abs(x_u(t))^2 = norm(x_l(t)) - norm(x_u(t)). 00071 * 00072 * In theory, the band-edge filter is the derivative of the matched 00073 * filter in frequency, (H_be(f) = frac{H(f)}{df}). In practice, 00074 * this comes down to a quarter sine wave at the point of the matched 00075 * filter's rolloff (if it's a raised-cosine, the derivative of a 00076 * cosine is a sine). Extend this sine by another quarter wave to 00077 * make a half wave around the band-edges is equivalent in time to the 00078 * sum of two sinc functions. The baseband filter fot the band edges 00079 * is therefore derived from this sum of sincs. The band edge filters 00080 * are then just the baseband signal modulated to the correct place in 00081 * frequency. All of these calculations are done in the 00082 * 'design_filter' function. 00083 * 00084 * Note: We use FIR filters here because the filters have to have a 00085 * flat phase response over the entire frequency range to allow their 00086 * comparisons to be valid. 00087 * 00088 * It is very important that the band edge filters be the derivatives 00089 * of the pulse shaping filter, and that they be linear 00090 * phase. Otherwise, the variance of the error will be very large. 00091 * 00092 */ 00093 00094 class DIGITAL_API digital_fll_band_edge_cc : 00095 public gr_sync_block, public gri_control_loop 00096 { 00097 private: 00098 /*! 00099 * Build the FLL 00100 * \param samps_per_sym (float) Number of samples per symbol of signal 00101 * \param rolloff (float) Rolloff factor of signal 00102 * \param filter_size (int) Size (in taps) of the filter 00103 * \param bandwidth (float) Loop bandwidth 00104 */ 00105 friend DIGITAL_API digital_fll_band_edge_cc_sptr 00106 digital_make_fll_band_edge_cc(float samps_per_sym, 00107 float rolloff, 00108 int filter_size, 00109 float bandwidth); 00110 00111 float d_sps; 00112 float d_rolloff; 00113 int d_filter_size; 00114 00115 std::vector<gr_complex> d_taps_lower; 00116 std::vector<gr_complex> d_taps_upper; 00117 bool d_updated; 00118 filter_t* d_filter_lower; 00119 filter_t* d_filter_upper; 00120 std::vector<gr_complex> d_output_hist; 00121 std::vector<gr_complex> d_fllbuffer; 00122 00123 /*! 00124 * Build the FLL 00125 * \param samps_per_sym (float) number of samples per symbol 00126 * \param rolloff (float) Rolloff (excess bandwidth) of signal filter 00127 * \param filter_size (int) number of filter taps to generate 00128 * \param bandwidth (float) Loop bandwidth 00129 */ 00130 digital_fll_band_edge_cc(float samps_per_sym, float rolloff, 00131 int filter_size, float bandwidth); 00132 00133 /*! 00134 * Design the band-edge filter based on the number of samples per symbol, 00135 * filter rolloff factor, and the filter size 00136 * 00137 * \param samps_per_sym (float) Number of samples per symbol of signal 00138 * \param rolloff (float) Rolloff factor of signal 00139 * \param filter_size (int) Size (in taps) of the filter 00140 */ 00141 void design_filter(float samps_per_sym, float rolloff, int filter_size); 00142 00143 public: 00144 ~digital_fll_band_edge_cc(); 00145 00146 /******************************************************************* 00147 SET FUNCTIONS 00148 *******************************************************************/ 00149 00150 /*! 00151 * \brief Set the number of samples per symbol 00152 * 00153 * Set's the number of samples per symbol the system should 00154 * use. This value is uesd to calculate the filter taps and will 00155 * force a recalculation. 00156 * 00157 * \param sps (float) new samples per symbol 00158 * 00159 */ 00160 void set_samples_per_symbol(float sps); 00161 00162 /*! 00163 * \brief Set the rolloff factor of the shaping filter 00164 * 00165 * This sets the rolloff factor that is used in the pulse shaping 00166 * filter and is used to calculate the filter taps. Changing this 00167 * will force a recalculation of the filter taps. 00168 * 00169 * This should be the same value that is used in the transmitter's 00170 * pulse shaping filter. It must be between 0 and 1 and is usually 00171 * between 0.2 and 0.5 (where 0.22 and 0.35 are commonly used 00172 * values). 00173 * 00174 * \param rolloff (float) new shaping filter rolloff factor [0,1] 00175 * 00176 */ 00177 void set_rolloff(float rolloff); 00178 00179 /*! 00180 * \brief Set the number of taps in the filter 00181 * 00182 * This sets the number of taps in the band-edge filters. Setting 00183 * this will force a recalculation of the filter taps. 00184 * 00185 * This should be about the same number of taps used in the 00186 * transmitter's shaping filter and also not very large. A large 00187 * number of taps will result in a large delay between input and 00188 * frequency estimation, and so will not be as accurate. Between 30 00189 * and 70 taps is usual. 00190 * 00191 * \param filter_size (float) number of taps in the filters 00192 * 00193 */ 00194 void set_filter_size(int filter_size); 00195 00196 /******************************************************************* 00197 GET FUNCTIONS 00198 *******************************************************************/ 00199 00200 /*! 00201 * \brief Returns the number of sampler per symbol used for the filter 00202 */ 00203 float get_samples_per_symbol() const; 00204 00205 /*! 00206 * \brief Returns the rolloff factor used for the filter 00207 */ 00208 float get_rolloff() const; 00209 00210 /*! 00211 * \brief Returns the number of taps of the filter 00212 */ 00213 int get_filter_size() const; 00214 00215 /*! 00216 * Print the taps to screen. 00217 */ 00218 void print_taps(); 00219 00220 int work(int noutput_items, 00221 gr_vector_const_void_star &input_items, 00222 gr_vector_void_star &output_items); 00223 }; 00224 00225 #endif