summaryrefslogtreecommitdiff
path: root/gr-digital
diff options
context:
space:
mode:
authorTom Rondeau2011-12-23 13:28:06 -0500
committerTom Rondeau2011-12-23 13:28:06 -0500
commit6a78e0a8ae6dc17a12ab5e397f1452a1a363e7d1 (patch)
tree28e3d86e87a758c1024f30c67b1675a9300cc3cb /gr-digital
parentc1c68974a6677f6dd81b1fb6e3c129e8d08c1fd0 (diff)
downloadgnuradio-6a78e0a8ae6dc17a12ab5e397f1452a1a363e7d1.tar.gz
gnuradio-6a78e0a8ae6dc17a12ab5e397f1452a1a363e7d1.tar.bz2
gnuradio-6a78e0a8ae6dc17a12ab5e397f1452a1a363e7d1.zip
digital: added a class, digital_mpsk_snr_est_cc, that estimates the SNR of an M-ary PSK signal.
This block can calculate the SNR using 1 of 4 different methods specified in the block's constructor. They (tend to) trade off accuracy for computational performnace.
Diffstat (limited to 'gr-digital')
-rw-r--r--gr-digital/include/CMakeLists.txt1
-rw-r--r--gr-digital/include/digital_mpsk_snr_est_cc.h108
-rw-r--r--gr-digital/lib/CMakeLists.txt1
-rw-r--r--gr-digital/lib/digital_mpsk_snr_est_cc.cc226
-rw-r--r--gr-digital/swig/CMakeLists.txt1
-rw-r--r--gr-digital/swig/digital_mpsk_snr_est_cc.i46
-rw-r--r--gr-digital/swig/digital_swig.i2
7 files changed, 385 insertions, 0 deletions
diff --git a/gr-digital/include/CMakeLists.txt b/gr-digital/include/CMakeLists.txt
index cf20bd1e7..ceb4fdfe1 100644
--- a/gr-digital/include/CMakeLists.txt
+++ b/gr-digital/include/CMakeLists.txt
@@ -37,6 +37,7 @@ install(FILES
digital_kurtotic_equalizer_cc.h
digital_metric_type.h
digital_mpsk_receiver_cc.h
+ digital_mpsk_snr_est_cc.h
digital_ofdm_cyclic_prefixer.h
digital_ofdm_frame_acquisition.h
digital_ofdm_frame_sink.h
diff --git a/gr-digital/include/digital_mpsk_snr_est_cc.h b/gr-digital/include/digital_mpsk_snr_est_cc.h
new file mode 100644
index 000000000..9c2d636c4
--- /dev/null
+++ b/gr-digital/include/digital_mpsk_snr_est_cc.h
@@ -0,0 +1,108 @@
+/* -*- 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.
+ */
+#ifndef INCLUDED_DIGITAL_MPSK_SNR_EST_CC_H
+#define INCLUDED_DIGITAL_MPSK_SNR_EST_CC_H
+
+#include <digital_api.h>
+#include <gr_sync_block.h>
+
+class digital_mpsk_snr_est_cc;
+typedef boost::shared_ptr<digital_mpsk_snr_est_cc> digital_mpsk_snr_est_cc_sptr;
+
+enum snr_est_type_t {
+ SNR_EST_SIMPLE = 0, // Simple estimator (>= 7 dB)
+ SNR_EST_SKEW, // Skewness-base est (>= 5 dB)
+ SNR_EST_M2M4, // 2nd & 4th moment est (>= 3 dB)
+ SNR_EST_SVN // SVN-based est (>= 0dB)
+};
+
+DIGITAL_API digital_mpsk_snr_est_cc_sptr
+digital_make_mpsk_snr_est_cc(snr_est_type_t type, double alpha);
+
+/*!
+ * Provides various methods to compute SNR.
+ */
+class DIGITAL_API digital_mpsk_snr_est_cc : public gr_sync_block
+{
+ private:
+ snr_est_type_t d_type;
+ double d_y1, d_y2, d_y3, d_y4;
+ double d_alpha, d_beta;
+
+ // Function pointers to the type of estimator used.
+ int (digital_mpsk_snr_est_cc::*d_estimator)(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ double (digital_mpsk_snr_est_cc::*d_calculator)();
+
+ // Factory function returning shared pointer of this class
+ friend DIGITAL_API digital_mpsk_snr_est_cc_sptr
+ digital_make_mpsk_snr_est_cc(snr_est_type_t type, double alpha);
+
+ // Private constructor
+ digital_mpsk_snr_est_cc(snr_est_type_t type, double alpha);
+
+ int est_simple(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ double est_simple_snr();
+
+ int est_skew(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ double est_skew_snr();
+
+ int est_m2m4(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ double est_m2m4_snr();
+
+ int est_svn(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ double est_svn_snr();
+
+public:
+
+ ~digital_mpsk_snr_est_cc();
+
+ int work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ //! Return the estimated signal-to-noise ratio in decibels
+ double snr();
+
+ //! Return the type of estimator in use
+ snr_est_type_t type() 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 running-average coefficient
+ void set_alpha(double alpha);
+};
+
+#endif /* INCLUDED_DIGITAL_MPSK_SNR_EST_CC_H */
diff --git a/gr-digital/lib/CMakeLists.txt b/gr-digital/lib/CMakeLists.txt
index b90757111..73ac5692f 100644
--- a/gr-digital/lib/CMakeLists.txt
+++ b/gr-digital/lib/CMakeLists.txt
@@ -46,6 +46,7 @@ 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
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..7793eed1d
--- /dev/null
+++ b/gr-digital/lib/digital_mpsk_snr_est_cc.cc
@@ -0,0 +1,226 @@
+/* -*- 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,
+ double alpha)
+{
+ return gnuradio::get_initial_sptr(new digital_mpsk_snr_est_cc(type, alpha));
+}
+
+digital_mpsk_snr_est_cc::digital_mpsk_snr_est_cc(snr_est_type_t type,
+ 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_type(type), d_y1(0), d_y2(0), d_y3(0), d_y4(0)
+{
+ set_type(type);
+ set_alpha(alpha);
+ set_history(2);
+}
+
+digital_mpsk_snr_est_cc::~digital_mpsk_snr_est_cc()
+{
+}
+
+int
+digital_mpsk_snr_est_cc::est_simple(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];
+
+ 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_mpsk_snr_est_cc::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);
+}
+
+int
+digital_mpsk_snr_est_cc::est_skew(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];
+
+ 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_mpsk_snr_est_cc::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));
+}
+
+int
+digital_mpsk_snr_est_cc::est_m2m4(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];
+
+ 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_mpsk_snr_est_cc::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)));
+}
+
+
+int
+digital_mpsk_snr_est_cc::est_svn(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];
+
+ 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_mpsk_snr_est_cc::est_svn_snr()
+{
+ double x = d_y1 / (d_y2 - d_y1);
+ return 10.0*log10(2.*((x-1) + sqrt(x*(x-1))));
+}
+
+int
+digital_mpsk_snr_est_cc::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ return (*this.*d_estimator)(noutput_items, input_items, output_items);
+}
+
+double
+digital_mpsk_snr_est_cc::snr()
+{
+ return (*this.*d_calculator)();
+}
+
+snr_est_type_t
+digital_mpsk_snr_est_cc::type() const
+{
+ return d_type;
+}
+
+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;
+ d_y1 = 0;
+ d_y2 = 0;
+ d_y3 = 0;
+ d_y4 = 0;
+
+ switch (d_type) {
+ case(SNR_EST_SIMPLE):
+ d_estimator = &digital_mpsk_snr_est_cc::est_simple;
+ d_calculator = &digital_mpsk_snr_est_cc::est_simple_snr;
+ break;
+ case(SNR_EST_SKEW):
+ d_estimator = &digital_mpsk_snr_est_cc::est_skew;
+ d_calculator = &digital_mpsk_snr_est_cc::est_skew_snr;
+ break;
+ case(SNR_EST_M2M4):
+ d_estimator = &digital_mpsk_snr_est_cc::est_m2m4;
+ d_calculator = &digital_mpsk_snr_est_cc::est_m2m4_snr;
+ break;
+ case(SNR_EST_SVN):
+ d_estimator = &digital_mpsk_snr_est_cc::est_svn;
+ d_calculator = &digital_mpsk_snr_est_cc::est_svn_snr;
+ break;
+ default:
+ throw std::invalid_argument("digital_mpsk_snr_est_cc: unknown type specified.\n");
+ }
+}
+
+void
+digital_mpsk_snr_est_cc::set_alpha(double alpha)
+{
+ d_alpha = alpha;
+ d_beta = 1.0-alpha;
+}
diff --git a/gr-digital/swig/CMakeLists.txt b/gr-digital/swig/CMakeLists.txt
index dd6097286..136f9e43f 100644
--- a/gr-digital/swig/CMakeLists.txt
+++ b/gr-digital/swig/CMakeLists.txt
@@ -59,6 +59,7 @@ install(
digital_lms_dd_equalizer_cc.i
digital_kurtotic_equalizer_cc.i
digital_mpsk_receiver_cc.i
+ digital_mpsk_snr_est_cc.i
digital_ofdm_cyclic_prefixer.i
digital_ofdm_frame_acquisition.i
digital_ofdm_frame_sink.i
diff --git a/gr-digital/swig/digital_mpsk_snr_est_cc.i b/gr-digital/swig/digital_mpsk_snr_est_cc.i
new file mode 100644
index 000000000..cb61e9482
--- /dev/null
+++ b/gr-digital/swig/digital_mpsk_snr_est_cc.i
@@ -0,0 +1,46 @@
+/* -*- 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.
+ */
+
+GR_SWIG_BLOCK_MAGIC(digital,mpsk_snr_est_cc);
+
+enum snr_est_type_t {
+ SNR_EST_SIMPLE = 0, // Simple estimator (>= 7 dB)
+ SNR_EST_SKEW, // Skewness-base est (>= 5 dB)
+ SNR_EST_M2M4, // 2nd & 4th moment est (>= 3 dB)
+ SNR_EST_SVN // SVN-based est (>= 0dB)
+};
+
+digital_mpsk_snr_est_cc_sptr
+digital_make_mpsk_snr_est_cc(snr_est_type_t type, double alpha);
+
+class digital_mpsk_snr_est_cc : public gr_sync_block
+{
+private:
+ void digital_mpsk_snr_est_cc(snr_est_type_t type, double alpha);
+
+public:
+ double snr();
+ snr_est_type_t type() const;
+ double alpha() const;
+ void set_type(snr_est_type_t t);
+ void set_alpha(double alpha);
+};
diff --git a/gr-digital/swig/digital_swig.i b/gr-digital/swig/digital_swig.i
index 86b5cab13..9182b2b09 100644
--- a/gr-digital/swig/digital_swig.i
+++ b/gr-digital/swig/digital_swig.i
@@ -41,6 +41,7 @@
#include "digital_kurtotic_equalizer_cc.h"
#include "digital_lms_dd_equalizer_cc.h"
#include "digital_mpsk_receiver_cc.h"
+#include "digital_mpsk_snr_est_cc.h"
#include "digital_ofdm_cyclic_prefixer.h"
#include "digital_ofdm_frame_acquisition.h"
#include "digital_ofdm_frame_sink.h"
@@ -65,6 +66,7 @@
%include "digital_kurtotic_equalizer_cc.i"
%include "digital_lms_dd_equalizer_cc.i"
%include "digital_mpsk_receiver_cc.i"
+%include "digital_mpsk_snr_est_cc.i"
%include "digital_ofdm_cyclic_prefixer.i"
%include "digital_ofdm_frame_acquisition.i"
%include "digital_ofdm_frame_sink.i"