summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib
diff options
context:
space:
mode:
authorTom <trondeau@vt.edu>2009-10-08 21:40:16 -0700
committerTom <trondeau@vt.edu>2009-10-08 21:40:16 -0700
commit90b8b4cc8c53c963f8b0cf4bbc50277c031c3213 (patch)
treee02a9f7f0093dccf4863b9411a0973e58cfd5b26 /gnuradio-core/src/lib
parenta8d8b8355478ac127efb775d4f6e900f1c830090 (diff)
Working on allowing fractional samples per symbol.
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r--gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc57
-rw-r--r--gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h20
-rw-r--r--gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i7
3 files changed, 51 insertions, 33 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 7dc5715d90..a75b20d383 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
@@ -36,11 +36,13 @@
gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (float sps, float gain,
const std::vector<float> &taps,
unsigned int filter_size,
- float init_phase)
+ float init_phase,
+ float max_rate_deviation)
{
return gr_pfb_clock_sync_ccf_sptr (new gr_pfb_clock_sync_ccf (sps, gain, taps,
filter_size,
- init_phase));
+ init_phase,
+ max_rate_deviation));
}
int ios[] = {sizeof(gr_complex), sizeof(float), sizeof(float), sizeof(float)};
@@ -48,11 +50,13 @@ std::vector<int> iosig(ios, ios+sizeof(ios)/sizeof(int));
gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (float sps, float gain,
const std::vector<float> &taps,
unsigned int filter_size,
- float init_phase)
+ float init_phase,
+ float max_rate_deviation)
: gr_block ("pfb_clock_sync_ccf",
gr_make_io_signature (1, 1, sizeof(gr_complex)),
gr_make_io_signaturev (1, 4, iosig)),
- d_updated (false), d_sps(sps)
+ d_updated (false), d_sps(sps), d_nfilters(filter_size),
+ d_max_dev(max_rate_deviation), d_start_count(0)
{
d_nfilters = filter_size;
@@ -63,10 +67,8 @@ gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (float sps, float gain,
set_alpha(gain);
set_beta(0.25*gain*gain);
d_k = d_nfilters / 2;
- d_filtnum = (int)floor(d_k);
d_rate = 0;
- d_start_count = 0;
-
+ d_filtnum = (int)floor(d_k);
d_filters = std::vector<gr_fir_ccf*>(d_nfilters);
d_diff_filters = std::vector<gr_fir_ccf*>(d_nfilters);
@@ -97,7 +99,7 @@ gr_pfb_clock_sync_ccf::set_taps (const std::vector<float> &newtaps,
std::vector< std::vector<float> > &ourtaps,
std::vector<gr_fir_ccf*> &ourfilter)
{
- unsigned int i,j;
+ int i,j;
unsigned int ntaps = newtaps.size();
d_taps_per_filter = (unsigned int)ceil((double)ntaps/(double)d_nfilters);
@@ -233,62 +235,65 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items,
// We need this many to process one output
int nrequired = ninput_items[0] - d_taps_per_filter;
- int i = 0, count = d_start_count;
- float error;
- float error_r, error_i;
+ int i = 0, count = (int)floor(d_sample_num);
+ float error, error_r, error_i;
// produce output as long as we can and there are enough input samples
while((i < noutput_items) && (count < nrequired)) {
-
- // FIXME: prevent this from asserting
- assert(d_filtnum < d_nfilters);
out[i] = d_filters[d_filtnum]->filter(&in[count]);
- error_r = out[i].real() * d_diff_filters[d_filtnum]->filter(&in[count]).real();
- error_i = out[i].imag() * d_diff_filters[d_filtnum]->filter(&in[count]).imag();
+ 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 = error_i + error_r;
d_k = d_k + d_alpha*error + d_rate;
d_rate = d_rate + d_beta*error;
d_filtnum = (int)floor(d_k);
+ // Keep the current filter number in [0, d_nfilters]
+ // If we've run beyond the last filter, wrap around and go to next sample
+ // If we've go below 0, wrap around and go to previous sample
while(d_filtnum >= d_nfilters) {
d_k -= d_nfilters;
d_filtnum -= d_nfilters;
- count++;
+ d_sample_num += 1.0;
}
while(d_filtnum < 0) {
d_k += d_nfilters;
d_filtnum += d_nfilters;
- count--;
+ d_sample_num -= 1.0;
}
// Keep our rate within a good range
- d_rate = gr_branchless_clip(d_rate, 1.5);
+ d_rate = gr_branchless_clip(d_rate, d_max_dev);
i++;
- count += d_sps;
+ d_sample_num += d_sps;
+ count = (int)floor(d_sample_num);
if(output_items.size() > 2) {
err[i] = error;
outrate[i] = d_rate;
outk[i] = d_k;
}
-
- //printf("error: %f k: %f rate: %f\n",
- // error, d_k, d_rate);
}
// Set the start index at the next entrance to the work function
// if we stop because we run out of input items, jump ahead in the
// next call to work. Otherwise, we can start at zero.
+ /*
if(count > nrequired) {
- d_start_count = count - (nrequired);
+ //d_start_count = count - (nrequired);
+ d_sample_num -= nrequired;
consume_each(ninput_items[0]-d_taps_per_filter);
}
else {
- d_start_count = 0;
+ d_sample_num -= floor(d_sample_num);
consume_each(count);
}
-
+ */
+ d_sample_num -= floor(d_sample_num);
+ consume_each(count);
+
return i;
}
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 41e5d7b2a3..84e174b198 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
@@ -31,7 +31,8 @@ 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 (float sps, float gain,
const std::vector<float> &taps,
unsigned int filter_size=32,
- float init_phase=0);
+ float init_phase=0,
+ float max_rate_deviation=1.5);
class gr_fir_ccf;
@@ -53,12 +54,14 @@ class gr_pfb_clock_sync_ccf : public gr_block
friend gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (float sps, float gain,
const std::vector<float> &taps,
unsigned int filter_size,
- float init_phase);
+ float init_phase,
+ float max_rate_deviation);
bool d_updated;
- unsigned int d_sps;
+ float d_sps;
float d_alpha;
float d_beta;
+ float d_sample_num;
int d_nfilters;
std::vector<gr_fir_ccf*> d_filters;
std::vector<gr_fir_ccf*> d_diff_filters;
@@ -66,9 +69,10 @@ class gr_pfb_clock_sync_ccf : public gr_block
std::vector< std::vector<float> > d_dtaps;
float d_k;
float d_rate;
+ float d_max_dev;
int d_filtnum;
+ int d_taps_per_filter;
unsigned int d_start_count;
- unsigned int d_taps_per_filter;
/*!
* Build the polyphase filterbank timing synchronizer.
@@ -76,7 +80,8 @@ class gr_pfb_clock_sync_ccf : public gr_block
gr_pfb_clock_sync_ccf (float sps, float gain,
const std::vector<float> &taps,
unsigned int filter_size,
- float init_phase);
+ float init_phase,
+ float max_rate_deviation);
void create_diff_taps(const std::vector<float> &newtaps,
std::vector<float> &difftaps);
@@ -107,6 +112,11 @@ public:
{
d_beta = beta;
}
+
+ void set_max_rate_deviation(float m)
+ {
+ d_max_dev = m;
+ }
int general_work (int noutput_items,
gr_vector_int &ninput_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 7859154791..9957c33b75 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
@@ -25,7 +25,8 @@ GR_SWIG_BLOCK_MAGIC(gr,pfb_clock_sync_ccf);
gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (float sps, float gain,
const std::vector<float> &taps,
unsigned int filter_size=32,
- float init_phase=0);
+ float init_phase=0,
+ float max_rate_deviation=1.5);
class gr_pfb_clock_sync_ccf : public gr_block
{
@@ -33,7 +34,8 @@ class gr_pfb_clock_sync_ccf : public gr_block
gr_pfb_clock_sync_ccf (float sps, float gain,
const std::vector<float> &taps,
unsigned int filter_size,
- float init_phase);
+ float init_phase,
+ float max_rate_deviation);
public:
~gr_pfb_clock_sync_ccf ();
@@ -48,4 +50,5 @@ class gr_pfb_clock_sync_ccf : public gr_block
void print_diff_taps();
void set_alpha(float alpha);
void set_beta(float beta);
+ void set_max_rate_deviation(float m);
};