summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc110
-rw-r--r--gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h151
-rw-r--r--gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i13
3 files changed, 231 insertions, 43 deletions
diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc
index a52d1d901..7dafe25dd 100644
--- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc
+++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2009,2010 Free Software Foundation, Inc.
+ * Copyright 2009-2011 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -33,14 +33,14 @@
#include <gr_io_signature.h>
#include <gr_math.h>
-gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain,
+gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float loop_bw,
const std::vector<float> &taps,
unsigned int filter_size,
float init_phase,
float max_rate_deviation,
int osps)
{
- return gnuradio::get_initial_sptr(new gr_pfb_clock_sync_ccf (sps, gain, taps,
+ return gnuradio::get_initial_sptr(new gr_pfb_clock_sync_ccf (sps, loop_bw, taps,
filter_size,
init_phase,
max_rate_deviation,
@@ -49,7 +49,7 @@ gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain,
static int ios[] = {sizeof(gr_complex), sizeof(float), sizeof(float), sizeof(float)};
static std::vector<int> iosig(ios, ios+sizeof(ios)/sizeof(int));
-gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (double sps, float gain,
+gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (double sps, float loop_bw,
const std::vector<float> &taps,
unsigned int filter_size,
float init_phase,
@@ -65,11 +65,15 @@ gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (double sps, float gain,
d_nfilters = filter_size;
d_sps = floor(sps);
+ // Set the damping factor for a critically damped system
+ d_damping = sqrtf(2.0f)/2.0f;
+
+ // Set the bandwidth, which will then call update_gains()
+ set_loop_bandwidth(loop_bw);
+
// Store the last filter between calls to work
// The accumulator keeps track of overflow to increment the stride correctly.
// set it here to the fractional difference based on the initial phaes
- set_alpha(gain);
- set_beta(0.25*gain*gain);
d_k = init_phase;
d_rate = (sps-floor(sps))*(double)d_nfilters;
d_rate_i = (int)floor(d_rate);
@@ -107,6 +111,94 @@ gr_pfb_clock_sync_ccf::check_topology(int ninputs, int noutputs)
return noutputs == 1 || noutputs == 4;
}
+
+
+/*******************************************************************
+ SET FUNCTIONS
+*******************************************************************/
+
+
+void
+gr_pfb_clock_sync_ccf::set_loop_bandwidth(float bw)
+{
+ if(bw < 0) {
+ throw std::out_of_range ("gr_pfb_clock_sync_cc: invalid bandwidth. Must be >= 0.");
+ }
+
+ d_loop_bw = bw;
+ update_gains();
+}
+
+void
+gr_pfb_clock_sync_ccf::set_damping_factor(float df)
+{
+ if(df < 0 || df > 1.0) {
+ throw std::out_of_range ("gr_pfb_clock_sync_cc: invalid damping factor. Must be in [0,1].");
+ }
+
+ d_damping = df;
+ update_gains();
+}
+
+void
+gr_pfb_clock_sync_ccf::set_alpha(float alpha)
+{
+ if(alpha < 0 || alpha > 1.0) {
+ throw std::out_of_range ("gr_pfb_clock_sync_cc: invalid alpha. Must be in [0,1].");
+ }
+ d_alpha = alpha;
+}
+
+void
+gr_pfb_clock_sync_ccf::set_beta(float beta)
+{
+ if(beta < 0 || beta > 1.0) {
+ throw std::out_of_range ("gr_pfb_clock_sync_cc: invalid beta. Must be in [0,1].");
+ }
+ d_beta = beta;
+}
+
+/*******************************************************************
+ GET FUNCTIONS
+*******************************************************************/
+
+
+float
+gr_pfb_clock_sync_ccf::get_loop_bandwidth() const
+{
+ return d_loop_bw;
+}
+
+float
+gr_pfb_clock_sync_ccf::get_damping_factor() const
+{
+ return d_damping;
+}
+
+float
+gr_pfb_clock_sync_ccf::get_alpha() const
+{
+ return d_alpha;
+}
+
+float
+gr_pfb_clock_sync_ccf::get_beta() const
+{
+ return d_beta;
+}
+
+/*******************************************************************
+*******************************************************************/
+
+void
+gr_pfb_clock_sync_ccf::update_gains()
+{
+ float denom = (1.0 + 2.0*d_damping*d_loop_bw + d_loop_bw*d_loop_bw);
+ d_alpha = (4*d_damping*d_loop_bw) / denom;
+ d_beta = (4*d_loop_bw*d_loop_bw) / denom;
+}
+
+
void
gr_pfb_clock_sync_ccf::set_taps (const std::vector<float> &newtaps,
std::vector< std::vector<float> > &ourtaps,
@@ -271,13 +363,13 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items,
}
gr_complex diff = d_diff_filters[d_filtnum]->filter(&in[count]);
- error_r = out[i].real() * diff.real();
- error_i = out[i].imag() * diff.imag();
+ error_r = tanh(out[i].real()) * diff.real();
+ error_i = tanh(out[i].imag()) * diff.imag();
error = (error_i + error_r) / 2.0; // average error from I&Q channel
// Run the control loop to update the current phase (k) and tracking rate
- d_k = d_k + d_alpha*error + d_rate_i + d_rate_f;
d_rate_f = d_rate_f + d_beta*error;
+ d_k = d_k + d_alpha*error + d_rate_i + d_rate_f;
// Keep our rate within a good range
d_rate_f = gr_branchless_clip(d_rate_f, d_max_dev);
diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h
index d4357e3d8..a869bcf1d 100644
--- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h
+++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h
@@ -28,7 +28,7 @@
class gr_pfb_clock_sync_ccf;
typedef boost::shared_ptr<gr_pfb_clock_sync_ccf> gr_pfb_clock_sync_ccf_sptr;
-gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain,
+gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float loop_bw,
const std::vector<float> &taps,
unsigned int filter_size=32,
float init_phase=0,
@@ -117,7 +117,7 @@ class gr_pfb_clock_sync_ccf : public gr_block
/*!
* Build the polyphase filterbank timing synchronizer.
* \param sps (double) The number of samples per symbol in the incoming signal
- * \param gain (float) The alpha gain of the control loop; beta = (gain^2)/4 by default.
+ * \param loop_bw (float) The bandwidth of the control loop; set's alpha and beta.
* \param taps (vector<int>) The filter taps.
* \param filter_size (uint) The number of filters in the filterbank (default = 32).
* \param init_phase (float) The initial phase to look at, or which filter to start
@@ -125,36 +125,40 @@ class gr_pfb_clock_sync_ccf : public gr_block
* \param max_rate_deviation (float) Distance from 0 d_rate can get (default = 1.5).
*
*/
- friend gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain,
+ friend gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float loop_bw,
const std::vector<float> &taps,
unsigned int filter_size,
float init_phase,
float max_rate_deviation,
int osps);
- bool d_updated;
- double d_sps;
- double d_sample_num;
- float d_alpha;
- float d_beta;
- int d_nfilters;
- std::vector<gr_fir_ccf*> d_filters;
- std::vector<gr_fir_ccf*> d_diff_filters;
+ bool d_updated;
+ double d_sps;
+ double d_sample_num;
+ float d_loop_bw;
+ float d_damping;
+ float d_alpha;
+ float d_beta;
+
+ int d_nfilters;
+ int d_taps_per_filter;
+ std::vector<gr_fir_ccf*> d_filters;
+ std::vector<gr_fir_ccf*> d_diff_filters;
std::vector< std::vector<float> > d_taps;
std::vector< std::vector<float> > d_dtaps;
- float d_k;
- float d_rate;
- float d_rate_i;
- float d_rate_f;
- float d_max_dev;
- int d_filtnum;
- int d_taps_per_filter;
- int d_osps;
+
+ float d_k;
+ float d_rate;
+ float d_rate_i;
+ float d_rate_f;
+ float d_max_dev;
+ int d_filtnum;
+ int d_osps;
/*!
* Build the polyphase filterbank timing synchronizer.
*/
- gr_pfb_clock_sync_ccf (double sps, float gain,
+ gr_pfb_clock_sync_ccf (double sps, float loop_bw,
const std::vector<float> &taps,
unsigned int filter_size,
float init_phase,
@@ -166,6 +170,15 @@ class gr_pfb_clock_sync_ccf : public gr_block
public:
~gr_pfb_clock_sync_ccf ();
+
+ /*! \brief update the system gains from omega and eta
+ *
+ * This function updates the system gains based on the loop
+ * bandwidth and damping factor of the system.
+ * These two factors can be set separately through their own
+ * set functions.
+ */
+ void update_gains();
/*!
* Resets the filterbank's filter taps with the new prototype filter
@@ -194,21 +207,68 @@ public:
*/
void print_diff_taps();
+
+ /*******************************************************************
+ SET FUNCTIONS
+ *******************************************************************/
+
+
/*!
- * Set the gain value alpha for the control loop
- */
- void set_alpha(float alpha)
- {
- d_alpha = alpha;
- }
+ * \brief Set the loop bandwidth
+ *
+ * Set the loop filter's bandwidth to \p bw. This should be between
+ * 2*pi/200 and 2*pi/100 (in rads/samp). It must also be a positive
+ * number.
+ *
+ * When a new damping factor is set, the gains, alpha and beta, of the loop
+ * are recalculated by a call to update_gains().
+ *
+ * \param bw (float) new bandwidth
+ *
+ */
+ void set_loop_bandwidth(float bw);
/*!
- * Set the gain value beta for the control loop
- */
- void set_beta(float beta)
- {
- d_beta = beta;
- }
+ * \brief Set the loop damping factor
+ *
+ * Set the loop filter's damping factor to \p df. The damping factor
+ * should be sqrt(2)/2.0 for critically damped systems.
+ * Set it to anything else only if you know what you are doing. It must
+ * be a number between 0 and 1.
+ *
+ * When a new damping factor is set, the gains, alpha and beta, of the loop
+ * are recalculated by a call to update_gains().
+ *
+ * \param df (float) new damping factor
+ *
+ */
+ void set_damping_factor(float df);
+
+ /*!
+ * \brief Set the loop gain alpha
+ *
+ * Set's the loop filter's alpha gain parameter.
+ *
+ * This value should really only be set by adjusting the loop bandwidth
+ * and damping factor.
+ *
+ * \param alpha (float) new alpha gain
+ *
+ */
+ void set_alpha(float alpha);
+
+ /*!
+ * \brief Set the loop gain beta
+ *
+ * Set's the loop filter's beta gain parameter.
+ *
+ * This value should really only be set by adjusting the loop bandwidth
+ * and damping factor.
+ *
+ * \param beta (float) new beta gain
+ *
+ */
+ void set_beta(float beta);
/*!
* Set the maximum deviation from 0 d_rate can have
@@ -218,6 +278,33 @@ public:
d_max_dev = m;
}
+ /*******************************************************************
+ GET FUNCTIONS
+ *******************************************************************/
+
+ /*!
+ * \brief Returns the loop bandwidth
+ */
+ float get_loop_bandwidth() const;
+
+ /*!
+ * \brief Returns the loop damping factor
+ */
+ float get_damping_factor() const;
+
+ /*!
+ * \brief Returns the loop gain alpha
+ */
+ float get_alpha() const;
+
+ /*!
+ * \brief Returns the loop gain beta
+ */
+ float get_beta() const;
+
+ /*******************************************************************
+ *******************************************************************/
+
bool check_topology(int ninputs, int noutputs);
int general_work (int noutput_items,
diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i
index 343ed0912..4d7aaec2b 100644
--- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i
+++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i
@@ -22,7 +22,7 @@
GR_SWIG_BLOCK_MAGIC(gr,pfb_clock_sync_ccf);
-gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain,
+gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float loop_bw,
const std::vector<float> &taps,
unsigned int filter_size=32,
float init_phase=0,
@@ -32,7 +32,7 @@ gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain,
class gr_pfb_clock_sync_ccf : public gr_block
{
private:
- gr_pfb_clock_sync_ccf (double sps, float gain,
+ gr_pfb_clock_sync_ccf (double sps, float loop_bw,
const std::vector<float> &taps,
unsigned int filter_size,
float init_phase,
@@ -50,7 +50,16 @@ class gr_pfb_clock_sync_ccf : public gr_block
std::vector<float> diff_channel_taps(int channel);
void print_taps();
void print_diff_taps();
+
+ void set_loop_bandwidth(float bw);
+ void set_damping_factor(float df);
void set_alpha(float alpha);
void set_beta(float beta);
void set_max_rate_deviation(float m);
+
+ float get_loop_bandwidth() const;
+ float get_damping_factor() const;
+ float get_alpha() const;
+ float get_beta() const;
+
};