summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gr-digital/include/digital_mpsk_snr_est_cc.h21
-rw-r--r--gr-digital/lib/digital_mpsk_snr_est_cc.cc71
-rw-r--r--gr-digital/swig/digital_mpsk_snr_est_cc.i2
3 files changed, 86 insertions, 8 deletions
diff --git a/gr-digital/include/digital_mpsk_snr_est_cc.h b/gr-digital/include/digital_mpsk_snr_est_cc.h
index 295c1648b..40c790222 100644
--- a/gr-digital/include/digital_mpsk_snr_est_cc.h
+++ b/gr-digital/include/digital_mpsk_snr_est_cc.h
@@ -31,6 +31,7 @@ typedef boost::shared_ptr<digital_mpsk_snr_est_cc> digital_mpsk_snr_est_cc_sptr;
DIGITAL_API digital_mpsk_snr_est_cc_sptr
digital_make_mpsk_snr_est_cc(snr_est_type_t type,
+ int tag_nsamples=10000,
double alpha=0.001);
//! \brief A block for computing SNR of a signal.
@@ -53,23 +54,33 @@ class DIGITAL_API digital_mpsk_snr_est_cc : public gr_sync_block
{
private:
snr_est_type_t d_type;
+ int d_nsamples, d_count;
double d_alpha;
digital_impl_mpsk_snr_est *d_snr_est;
+ //d_key is the tag name, 'snr', d_me is the block name + unique ID
+ pmt::pmt_t d_key, d_me;
+
/*! Factory function returning shared pointer of this class
*
* Parameters:
*
* \li \p type: the type of estimator to use \ref ref_snr_est_types
* "snr_est_type_t" for details about the available types.
+ * \li \p tag_nsamples: after this many samples, a tag containing
+ * the SNR (key='snr') will be sent
* \li \p alpha: the update rate of internal running average
* calculations.
*/
friend DIGITAL_API digital_mpsk_snr_est_cc_sptr
- digital_make_mpsk_snr_est_cc(snr_est_type_t type, double alpha);
+ digital_make_mpsk_snr_est_cc(snr_est_type_t type,
+ int tag_nsamples,
+ double alpha);
// Private constructor
- digital_mpsk_snr_est_cc(snr_est_type_t type, double alpha);
+ digital_mpsk_snr_est_cc(snr_est_type_t type,
+ int tag_nsamples,
+ double alpha);
public:
@@ -85,12 +96,18 @@ public:
//! Return the type of estimator in use
snr_est_type_t type() const;
+ //! Return how many samples between SNR tags
+ int tag_nsample() const;
+
//! Get the running-average coefficient
double alpha() const;
//! Set type of estimator to use
void set_type(snr_est_type_t t);
+ //! Set the number of samples between SNR tags
+ void set_tag_nsample(int n);
+
//! Set the running-average coefficient
void set_alpha(double alpha);
};
diff --git a/gr-digital/lib/digital_mpsk_snr_est_cc.cc b/gr-digital/lib/digital_mpsk_snr_est_cc.cc
index b71ac0022..b5a60f0d3 100644
--- a/gr-digital/lib/digital_mpsk_snr_est_cc.cc
+++ b/gr-digital/lib/digital_mpsk_snr_est_cc.cc
@@ -30,12 +30,15 @@
digital_mpsk_snr_est_cc_sptr
digital_make_mpsk_snr_est_cc(snr_est_type_t type,
+ int tag_nsamples,
double alpha)
{
- return gnuradio::get_initial_sptr(new digital_mpsk_snr_est_cc(type, alpha));
+ return gnuradio::get_initial_sptr(new digital_mpsk_snr_est_cc(
+ type, tag_nsamples, alpha));
}
digital_mpsk_snr_est_cc::digital_mpsk_snr_est_cc(snr_est_type_t type,
+ int tag_nsamples,
double alpha)
: gr_sync_block ("mpsk_snr_est_cc",
gr_make_io_signature(1, 1, sizeof(gr_complex)),
@@ -44,12 +47,19 @@ digital_mpsk_snr_est_cc::digital_mpsk_snr_est_cc(snr_est_type_t type,
d_snr_est = NULL;
d_type = type;
+ d_nsamples = tag_nsamples;
+ d_count = 0;
set_alpha(alpha);
set_type(type);
// at least 1 estimator has to look back
set_history(2);
+
+ std::stringstream str;
+ str << name() << unique_id();
+ d_me = pmt::pmt_string_to_symbol(str.str());
+ d_key = pmt::pmt_string_to_symbol("snr");
}
digital_mpsk_snr_est_cc::~digital_mpsk_snr_est_cc()
@@ -67,8 +77,36 @@ digital_mpsk_snr_est_cc::work(int noutput_items,
memcpy(output_items[0], input_items[0],
noutput_items * sizeof(gr_complex));
- // Update the SNR estimate registers from the current
- return d_snr_est->update(noutput_items, input_items);
+ const gr_complex *in = (const gr_complex*)input_items[0];
+
+ // Update, calculate, and issue an SNR tag every d_nsamples
+ int index = 0, x = 0;
+ int64_t nwritten = nitems_written(0);
+ while(index + (d_nsamples-d_count) <= noutput_items) {
+ x = d_nsamples - d_count;
+ nwritten += x;
+
+ // Update the SNR estimate registers from the current input
+ d_snr_est->update(x, &in[index]);
+
+ // Issue a tag with the SNR data
+ pmt::pmt_t pmt_snr = pmt::pmt_from_double(d_snr_est->snr());
+ add_item_tag(0, // stream ID
+ nwritten, // tag's sample number
+ d_key, // snr key
+ pmt_snr, // SNR
+ d_me); // block src id
+
+ index += x;
+ d_count = 0;
+ }
+
+ // Keep track of remaining items and update estimators
+ x = noutput_items - index;
+ d_count += x;
+ d_snr_est->update(x, &in[index]);
+
+ return noutput_items;
}
double
@@ -86,6 +124,12 @@ digital_mpsk_snr_est_cc::type() const
return d_type;
}
+int
+digital_mpsk_snr_est_cc::tag_nsample() const
+{
+ return d_nsamples;
+}
+
double
digital_mpsk_snr_est_cc::alpha() const
{
@@ -119,9 +163,24 @@ digital_mpsk_snr_est_cc::set_type(snr_est_type_t t)
}
void
+digital_mpsk_snr_est_cc::set_tag_nsample(int n)
+{
+ if(n > 0) {
+ d_nsamples = n;
+ d_count = 0; // reset state
+ }
+ else
+ throw std::invalid_argument("digital_mpsk_snr_est_cc: tag_nsamples can't be <= 0\n");
+}
+
+void
digital_mpsk_snr_est_cc::set_alpha(double alpha)
{
- d_alpha = alpha;
- if(d_snr_est)
- d_snr_est->set_alpha(d_alpha);
+ if((alpha >= 0) && (alpha <= 1.0)) {
+ d_alpha = alpha;
+ if(d_snr_est)
+ d_snr_est->set_alpha(d_alpha);
+ }
+ else
+ throw std::invalid_argument("digital_mpsk_snr_est_cc: alpha must be in [0,1]\n");
}
diff --git a/gr-digital/swig/digital_mpsk_snr_est_cc.i b/gr-digital/swig/digital_mpsk_snr_est_cc.i
index 947c5ab86..b0fc6bccf 100644
--- a/gr-digital/swig/digital_mpsk_snr_est_cc.i
+++ b/gr-digital/swig/digital_mpsk_snr_est_cc.i
@@ -24,12 +24,14 @@ GR_SWIG_BLOCK_MAGIC(digital,mpsk_snr_est_cc);
digital_mpsk_snr_est_cc_sptr
digital_make_mpsk_snr_est_cc(snr_est_type_t type,
+ int tag_nsamples=10000,
double alpha=0.001);
class digital_mpsk_snr_est_cc : public gr_sync_block
{
private:
void digital_mpsk_snr_est_cc(snr_est_type_t type,
+ int tag_nsamples,
double alpha);
public: