summaryrefslogtreecommitdiff
path: root/gr-digital/lib
diff options
context:
space:
mode:
Diffstat (limited to 'gr-digital/lib')
-rw-r--r--gr-digital/lib/CMakeLists.txt3
-rw-r--r--gr-digital/lib/Makefile.am3
-rw-r--r--gr-digital/lib/digital_impl_mpsk_snr_est.cc256
-rw-r--r--gr-digital/lib/digital_mpsk_snr_est_cc.cc186
-rw-r--r--gr-digital/lib/digital_probe_mpsk_snr_est_c.cc152
5 files changed, 600 insertions, 0 deletions
diff --git a/gr-digital/lib/CMakeLists.txt b/gr-digital/lib/CMakeLists.txt
index b90757111..779972ff3 100644
--- a/gr-digital/lib/CMakeLists.txt
+++ b/gr-digital/lib/CMakeLists.txt
@@ -32,6 +32,7 @@ link_directories(${Boost_LIBRARY_DIRS})
# Setup library
########################################################################
list(APPEND gr_digital_sources
+ digital_impl_mpsk_snr_est.cc
digital_binary_slicer_fb.cc
digital_clock_recovery_mm_cc.cc
digital_clock_recovery_mm_ff.cc
@@ -46,12 +47,14 @@ list(APPEND gr_digital_sources
digital_lms_dd_equalizer_cc.cc
digital_kurtotic_equalizer_cc.cc
digital_mpsk_receiver_cc.cc
+ digital_mpsk_snr_est_cc.cc
digital_ofdm_cyclic_prefixer.cc
digital_ofdm_frame_acquisition.cc
digital_ofdm_frame_sink.cc
digital_ofdm_insert_preamble.cc
digital_ofdm_mapper_bcv.cc
digital_ofdm_sampler.cc
+ digital_probe_mpsk_snr_est_c.cc
digital_gmskmod_bc.cc
digital_cpmmod_bc.cc
)
diff --git a/gr-digital/lib/Makefile.am b/gr-digital/lib/Makefile.am
index 2860974ca..d5ad199e3 100644
--- a/gr-digital/lib/Makefile.am
+++ b/gr-digital/lib/Makefile.am
@@ -27,6 +27,7 @@ AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(PYTHON_CPPFLAGS) \
lib_LTLIBRARIES = libgnuradio-digital.la
libgnuradio_digital_la_SOURCES = \
+ digital_impl_mpsk_snr_est.cc \
digital_binary_slicer_fb.cc \
digital_clock_recovery_mm_cc.cc \
digital_clock_recovery_mm_ff.cc \
@@ -41,12 +42,14 @@ libgnuradio_digital_la_SOURCES = \
digital_lms_dd_equalizer_cc.cc \
digital_kurtotic_equalizer_cc.cc \
digital_mpsk_receiver_cc.cc \
+ digital_mpsk_snr_est_cc.cc \
digital_ofdm_cyclic_prefixer.cc \
digital_ofdm_frame_acquisition.cc \
digital_ofdm_frame_sink.cc \
digital_ofdm_insert_preamble.cc \
digital_ofdm_mapper_bcv.cc \
digital_ofdm_sampler.cc \
+ digital_probe_mpsk_snr_est_c.cc \
digital_gmskmod_bc.cc \
digital_cpmmod_bc.cc
diff --git a/gr-digital/lib/digital_impl_mpsk_snr_est.cc b/gr-digital/lib/digital_impl_mpsk_snr_est.cc
new file mode 100644
index 000000000..38177083f
--- /dev/null
+++ b/gr-digital/lib/digital_impl_mpsk_snr_est.cc
@@ -0,0 +1,256 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <digital_impl_mpsk_snr_est.h>
+#include <cstdio>
+
+digital_impl_mpsk_snr_est::digital_impl_mpsk_snr_est(double alpha)
+{
+ set_alpha(alpha);
+}
+
+digital_impl_mpsk_snr_est::~digital_impl_mpsk_snr_est()
+{}
+
+void
+digital_impl_mpsk_snr_est::set_alpha(double alpha)
+{
+ d_alpha = alpha;
+ d_beta = 1.0-alpha;
+}
+
+double
+digital_impl_mpsk_snr_est::alpha() const
+{
+ return d_alpha;
+}
+
+int
+digital_impl_mpsk_snr_est::update(int noutput_items,
+ const gr_complex *in)
+{
+ throw std::runtime_error("digital_impl_mpsk_snr_est: Unimplemented");
+}
+
+double
+digital_impl_mpsk_snr_est::snr()
+{
+ throw std::runtime_error("digital_impl_mpsk_snr_est: Unimplemented");
+}
+
+
+/********************************************************************/
+
+
+digital_impl_mpsk_snr_est_simple::digital_impl_mpsk_snr_est_simple(
+ double alpha) :
+ digital_impl_mpsk_snr_est(alpha)
+{
+ d_y1 = 0;
+ d_y2 = 0;
+}
+
+int
+digital_impl_mpsk_snr_est_simple::update(
+ int noutput_items,
+ const gr_complex *in)
+{
+ for (int i = 0; i < noutput_items; i++){
+ double y1 = abs(in[i]);
+ d_y1 = d_alpha*y1 + d_beta*d_y1;
+
+ double y2 = real(in[i]*in[i]);
+ d_y2 = d_alpha*y2 + d_beta*d_y2;
+ }
+ return noutput_items;
+}
+
+double
+digital_impl_mpsk_snr_est_simple::snr()
+{
+ double y1_2 = d_y1*d_y1;
+ double y3 = y1_2 - d_y2 + 1e-20;
+ return 10.0*log10(y1_2/y3);
+}
+
+
+/********************************************************************/
+
+
+digital_impl_mpsk_snr_est_skew::digital_impl_mpsk_snr_est_skew(
+ double alpha) :
+ digital_impl_mpsk_snr_est(alpha)
+{
+ d_y1 = 0;
+ d_y2 = 0;
+ d_y3 = 0;
+}
+
+
+int
+digital_impl_mpsk_snr_est_skew::update(
+ int noutput_items,
+ const gr_complex *in)
+{
+ for (int i = 0; i < noutput_items; i++){
+ double y1 = abs(in[i]);
+ d_y1 = d_alpha*y1 + d_beta*d_y1;
+
+ double y2 = real(in[i]*in[i]);
+ d_y2 = d_alpha*y2 + d_beta*d_y2;
+
+ // online algorithm for calculating skewness
+ // See:
+ // http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Higher-order_statistics
+ double d = abs(in[i]) - d_y1;
+ double d_i = d / (i+1);
+ double y3 = (d*d_i*i)*d_i*(i-1) - 3.0*d_i*d_y2;
+ d_y3 = d_alpha*y3 + d_beta*d_y3;
+ }
+ return noutput_items;
+}
+
+double
+digital_impl_mpsk_snr_est_skew::snr()
+{
+ double y3 = d_y3*d_y3 / (d_y2*d_y2*d_y2);
+ double y1_2 = d_y1*d_y1;
+ double x = y1_2 - d_y2;
+ return 10.0*log10(y1_2 / (x + y3*y1_2));
+}
+
+
+/********************************************************************/
+
+
+digital_impl_mpsk_snr_est_m2m4::digital_impl_mpsk_snr_est_m2m4(
+ double alpha) :
+ digital_impl_mpsk_snr_est(alpha)
+{
+ d_y1 = 0;
+ d_y2 = 0;
+}
+
+int
+digital_impl_mpsk_snr_est_m2m4::update(
+ int noutput_items,
+ const gr_complex *in)
+{
+ for (int i = 0; i < noutput_items; i++){
+ double y1 = abs(in[i])*abs(in[i]);
+ d_y1 = d_alpha*y1 + d_beta*d_y1;
+
+ double y2 = abs(in[i])*abs(in[i])*abs(in[i])*abs(in[i]);
+ d_y2 = d_alpha*y2 + d_beta*d_y2;
+ }
+ return noutput_items;
+}
+
+double
+digital_impl_mpsk_snr_est_m2m4::snr()
+{
+ double y1_2 = d_y1*d_y1;
+ return 10.0*log10(2.0*sqrt(2*y1_2 - d_y2) /
+ (d_y1 - sqrt(2*y1_2 - d_y2)));
+}
+
+
+/********************************************************************/
+
+
+digital_impl_snr_est_m2m4::digital_impl_snr_est_m2m4(
+ double alpha, double ka, double kw) :
+ digital_impl_mpsk_snr_est(alpha)
+{
+ d_y1 = 0;
+ d_y2 = 0;
+ d_ka = ka;
+ d_kw = kw;
+}
+
+int
+digital_impl_snr_est_m2m4::update(
+ int noutput_items,
+ const gr_complex *in)
+{
+ for (int i = 0; i < noutput_items; i++) {
+ double y1 = abs(in[i])*abs(in[i]);
+ d_y1 = d_alpha*y1 + d_beta*d_y1;
+
+ double y2 = abs(in[i])*abs(in[i])*abs(in[i])*abs(in[i]);
+ d_y2 = d_alpha*y2 + d_beta*d_y2;
+ }
+ return noutput_items;
+}
+
+double
+digital_impl_snr_est_m2m4::snr()
+{
+ double M2 = d_y1;
+ double M4 = d_y2;
+ double s = M2*(d_kw - 2) +
+ sqrt((4.0-d_ka*d_kw)*M2*M2 + M4*(d_ka+d_kw-4.0)) /
+ (d_ka + d_kw - 4.0);
+ double n = M2 - s;
+
+ return 10.0*log10(s / n);
+}
+
+
+/********************************************************************/
+
+
+digital_impl_mpsk_snr_est_svr::digital_impl_mpsk_snr_est_svr(
+ double alpha) :
+ digital_impl_mpsk_snr_est(alpha)
+{
+ d_y1 = 0;
+ d_y2 = 0;
+}
+
+int
+digital_impl_mpsk_snr_est_svr::update(
+ int noutput_items,
+ const gr_complex *in)
+{
+ for (int i = 0; i < noutput_items; i++){
+ double x = abs(in[i]);
+ double x1 = abs(in[i-1]);
+ double y1 = (x*x)*(x1*x1);
+ d_y1 = d_alpha*y1 + d_beta*d_y1;
+
+ double y2 = x*x*x*x;
+ d_y2 = d_alpha*y2 + d_beta*d_y2;
+ }
+ return noutput_items;
+}
+
+double
+digital_impl_mpsk_snr_est_svr::snr()
+{
+ double x = d_y1 / (d_y2 - d_y1);
+ return 10.0*log10(2.*((x-1) + sqrt(x*(x-1))));
+}
diff --git a/gr-digital/lib/digital_mpsk_snr_est_cc.cc b/gr-digital/lib/digital_mpsk_snr_est_cc.cc
new file mode 100644
index 000000000..b5a60f0d3
--- /dev/null
+++ b/gr-digital/lib/digital_mpsk_snr_est_cc.cc
@@ -0,0 +1,186 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <digital_mpsk_snr_est_cc.h>
+#include <gr_io_signature.h>
+#include <cstdio>
+
+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, 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)),
+ gr_make_io_signature(1, 1, sizeof(gr_complex)))
+{
+ 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()
+{
+ if(d_snr_est)
+ delete d_snr_est;
+}
+
+int
+digital_mpsk_snr_est_cc::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ // This is a pass-through block; copy input to output
+ memcpy(output_items[0], input_items[0],
+ noutput_items * sizeof(gr_complex));
+
+ 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
+digital_mpsk_snr_est_cc::snr()
+{
+ if(d_snr_est)
+ return d_snr_est->snr();
+ else
+ throw std::runtime_error("digital_mpsk_snr_est_cc:: No SNR estimator defined.\n");
+}
+
+snr_est_type_t
+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
+{
+ return d_alpha;
+}
+
+void
+digital_mpsk_snr_est_cc::set_type(snr_est_type_t t)
+{
+ d_type = t;
+
+ if(d_snr_est)
+ delete d_snr_est;
+
+ switch (d_type) {
+ case(SNR_EST_SIMPLE):
+ d_snr_est = new digital_impl_mpsk_snr_est_simple(d_alpha);
+ break;
+ case(SNR_EST_SKEW):
+ d_snr_est = new digital_impl_mpsk_snr_est_skew(d_alpha);
+ break;
+ case(SNR_EST_M2M4):
+ d_snr_est = new digital_impl_mpsk_snr_est_m2m4(d_alpha);
+ break;
+ case(SNR_EST_SVR):
+ d_snr_est = new digital_impl_mpsk_snr_est_svr(d_alpha);
+ break;
+ default:
+ throw std::invalid_argument("digital_mpsk_snr_est_cc: unknown type specified.\n");
+ }
+}
+
+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)
+{
+ 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/lib/digital_probe_mpsk_snr_est_c.cc b/gr-digital/lib/digital_probe_mpsk_snr_est_c.cc
new file mode 100644
index 000000000..5cdfea96d
--- /dev/null
+++ b/gr-digital/lib/digital_probe_mpsk_snr_est_c.cc
@@ -0,0 +1,152 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <digital_probe_mpsk_snr_est_c.h>
+#include <gr_io_signature.h>
+#include <cstdio>
+
+digital_probe_mpsk_snr_est_c_sptr
+digital_make_probe_mpsk_snr_est_c(snr_est_type_t type,
+ int msg_nsamples,
+ double alpha)
+{
+ return gnuradio::get_initial_sptr(
+ new digital_probe_mpsk_snr_est_c(type, msg_nsamples, alpha));
+}
+
+digital_probe_mpsk_snr_est_c::digital_probe_mpsk_snr_est_c(
+ snr_est_type_t type,
+ int msg_nsamples,
+ double alpha)
+ : gr_sync_block ("probe_mpsk_snr_est_c",
+ gr_make_io_signature(1, 1, sizeof(gr_complex)),
+ gr_make_io_signature(0, 0, 0))
+{
+ d_snr_est = NULL;
+
+ d_type = type;
+ d_nsamples = msg_nsamples;
+ d_count = 0;
+ set_alpha(alpha);
+
+ set_type(type);
+
+ // at least 1 estimator has to look back
+ set_history(2);
+
+ d_key = pmt::pmt_string_to_symbol("snr");
+}
+
+digital_probe_mpsk_snr_est_c::~digital_probe_mpsk_snr_est_c()
+{
+ if(d_snr_est)
+ delete d_snr_est;
+}
+
+int
+digital_probe_mpsk_snr_est_c::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ const gr_complex *in = (const gr_complex*)input_items[0];
+ return d_snr_est->update(noutput_items, in);
+}
+
+double
+digital_probe_mpsk_snr_est_c::snr()
+{
+ if(d_snr_est)
+ return d_snr_est->snr();
+ else
+ throw std::runtime_error("digital_probe_mpsk_snr_est_c:: No SNR estimator defined.\n");
+}
+
+snr_est_type_t
+digital_probe_mpsk_snr_est_c::type() const
+{
+ return d_type;
+}
+
+int
+digital_probe_mpsk_snr_est_c::msg_nsample() const
+{
+ return d_nsamples;
+}
+
+double
+digital_probe_mpsk_snr_est_c::alpha() const
+{
+ return d_alpha;
+}
+
+void
+digital_probe_mpsk_snr_est_c::set_type(snr_est_type_t t)
+{
+ d_type = t;
+
+ if(d_snr_est)
+ delete d_snr_est;
+
+ switch (d_type) {
+ case(SNR_EST_SIMPLE):
+ d_snr_est = new digital_impl_mpsk_snr_est_simple(d_alpha);
+ break;
+ case(SNR_EST_SKEW):
+ d_snr_est = new digital_impl_mpsk_snr_est_skew(d_alpha);
+ break;
+ case(SNR_EST_M2M4):
+ d_snr_est = new digital_impl_mpsk_snr_est_m2m4(d_alpha);
+ break;
+ case(SNR_EST_SVR):
+ d_snr_est = new digital_impl_mpsk_snr_est_svr(d_alpha);
+ break;
+ default:
+ throw std::invalid_argument("digital_probe_mpsk_snr_est_c: unknown type specified.\n");
+ }
+}
+
+void
+digital_probe_mpsk_snr_est_c::set_msg_nsample(int n)
+{
+ if(n > 0) {
+ d_nsamples = n;
+ d_count = 0; // reset state
+ }
+ else
+ throw std::invalid_argument("digital_probe_mpsk_snr_est_c: msg_nsamples can't be <= 0\n");
+}
+
+void
+digital_probe_mpsk_snr_est_c::set_alpha(double 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_probe_mpsk_snr_est_c: alpha must be in [0,1]\n");
+}