diff options
-rw-r--r-- | gr-digital/include/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-digital/include/Makefile.am | 1 | ||||
-rw-r--r-- | gr-digital/include/digital_impl_mpsk_snr_est.h | 123 | ||||
-rw-r--r-- | gr-digital/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-digital/lib/Makefile.am | 1 | ||||
-rw-r--r-- | gr-digital/lib/digital_impl_mpsk_snr_est.cc | 227 |
6 files changed, 354 insertions, 0 deletions
diff --git a/gr-digital/include/CMakeLists.txt b/gr-digital/include/CMakeLists.txt index ceb4fdfe1..8bac4c991 100644 --- a/gr-digital/include/CMakeLists.txt +++ b/gr-digital/include/CMakeLists.txt @@ -22,6 +22,7 @@ ######################################################################## install(FILES digital_api.h + digital_impl_mpsk_snr_est.h digital_binary_slicer_fb.h digital_clock_recovery_mm_cc.h digital_clock_recovery_mm_ff.h diff --git a/gr-digital/include/Makefile.am b/gr-digital/include/Makefile.am index 8ce3a94e8..9fa619015 100644 --- a/gr-digital/include/Makefile.am +++ b/gr-digital/include/Makefile.am @@ -24,6 +24,7 @@ include $(top_srcdir)/Makefile.common # These headers get installed in ${prefix}/include/gnuradio grinclude_HEADERS = \ digital_api.h \ + digital_impl_mpsk_snr_est.h \ digital_binary_slicer_fb.h \ digital_clock_recovery_mm_cc.h \ digital_clock_recovery_mm_ff.h \ diff --git a/gr-digital/include/digital_impl_mpsk_snr_est.h b/gr-digital/include/digital_impl_mpsk_snr_est.h new file mode 100644 index 000000000..67cf83ec9 --- /dev/null +++ b/gr-digital/include/digital_impl_mpsk_snr_est.h @@ -0,0 +1,123 @@ +/* -*- 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_IMPL_MPSK_SNR_EST_H +#define INCLUDED_DIGITAL_IMPL_MPSK_SNR_EST_H + +#include <digital_api.h> +#include <gr_sync_block.h> + +/*! + * Parent class for SNR Estimators + */ +class DIGITAL_API digital_impl_mpsk_snr_est +{ + protected: + double d_alpha, d_beta; + + public: + digital_impl_mpsk_snr_est(double alpha); + virtual ~digital_impl_mpsk_snr_est(); + + //! Get the running-average coefficient + double alpha() const; + + //! Set the running-average coefficient + void set_alpha(double alpha); + + //! Update the current registers + virtual int update(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + //! Use the register values to compute a new estimate + virtual double snr(); +}; + + +class DIGITAL_API digital_impl_mpsk_snr_est_simple : + public digital_impl_mpsk_snr_est +{ + private: + double d_y1, d_y2; + + public: + digital_impl_mpsk_snr_est_simple(double alpha); + ~digital_impl_mpsk_snr_est_simple() {} + + int update(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + double snr(); +}; + + +class DIGITAL_API digital_impl_mpsk_snr_est_skew : + public digital_impl_mpsk_snr_est +{ + private: + double d_y1, d_y2, d_y3; + + public: + digital_impl_mpsk_snr_est_skew(double alpha); + ~digital_impl_mpsk_snr_est_skew() {} + + int update(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + double snr(); +}; + + +class DIGITAL_API digital_impl_mpsk_snr_est_m2m4 : + public digital_impl_mpsk_snr_est +{ + private: + double d_y1, d_y2; + + public: + digital_impl_mpsk_snr_est_m2m4(double alpha); + ~digital_impl_mpsk_snr_est_m2m4() {} + + int update(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + double snr(); +}; + + +class DIGITAL_API digital_impl_mpsk_snr_est_svn : + public digital_impl_mpsk_snr_est +{ + private: + double d_y1, d_y2; + + public: + digital_impl_mpsk_snr_est_svn(double alpha); + ~digital_impl_mpsk_snr_est_svn() {} + + int update(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + double snr(); +}; + +#endif /* INCLUDED_DIGITAL_IMPL_MPSK_SNR_EST_H */ diff --git a/gr-digital/lib/CMakeLists.txt b/gr-digital/lib/CMakeLists.txt index 73ac5692f..94ef2b64d 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 diff --git a/gr-digital/lib/Makefile.am b/gr-digital/lib/Makefile.am index 2860974ca..b6fea599f 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 \ 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..aa0d4ffb9 --- /dev/null +++ b/gr-digital/lib/digital_impl_mpsk_snr_est.cc @@ -0,0 +1,227 @@ +/* -*- 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, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + 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, + 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_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, + 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_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, + 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_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_mpsk_snr_est_svn::digital_impl_mpsk_snr_est_svn( + double alpha) : + digital_impl_mpsk_snr_est(alpha) +{ + d_y1 = 0; + d_y2 = 0; +} + +int +digital_impl_mpsk_snr_est_svn::update( + 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_impl_mpsk_snr_est_svn::snr() +{ + double x = d_y1 / (d_y2 - d_y1); + return 10.0*log10(2.*((x-1) + sqrt(x*(x-1)))); +} |