summaryrefslogtreecommitdiff
path: root/gr-digital
diff options
context:
space:
mode:
authorTom Rondeau <trondeau@vt.edu>2012-08-14 00:00:14 -0400
committerTom Rondeau <trondeau@vt.edu>2012-08-14 00:00:14 -0400
commit48a95b3469febf4929c74f41beac6b33ab77566e (patch)
tree09fcfa18252f4e629f1bdb280b7ef0a12e1f401b /gr-digital
parent509fddb30a70862b31b0488acfbbdf523b48af0d (diff)
digital: converted mpsk snr and probes to new style.
Diffstat (limited to 'gr-digital')
-rw-r--r--gr-digital/include/digital/CMakeLists.txt8
-rw-r--r--gr-digital/include/digital/mpsk_snr_est.h287
-rw-r--r--gr-digital/include/digital/mpsk_snr_est_cc.h96
-rw-r--r--gr-digital/include/digital/probe_density_b.h63
-rw-r--r--gr-digital/include/digital/probe_mpsk_snr_est_c.h94
-rw-r--r--gr-digital/include/digital_impl_mpsk_snr_est.h279
-rw-r--r--gr-digital/include/digital_mpsk_snr_est_cc.h115
-rw-r--r--gr-digital/include/digital_probe_density_b.h75
-rw-r--r--gr-digital/include/digital_probe_mpsk_snr_est_c.h113
-rw-r--r--gr-digital/lib/CMakeLists.txt8
-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_density_b.cc68
-rw-r--r--gr-digital/lib/digital_probe_mpsk_snr_est_c.cc152
-rw-r--r--gr-digital/lib/mpsk_snr_est.cc252
-rw-r--r--gr-digital/lib/mpsk_snr_est_cc_impl.cc192
-rw-r--r--gr-digital/lib/mpsk_snr_est_cc_impl.h79
-rw-r--r--gr-digital/lib/probe_density_b_impl.cc73
-rw-r--r--gr-digital/lib/probe_density_b_impl.h58
-rw-r--r--gr-digital/lib/probe_mpsk_snr_est_c_impl.cc157
-rw-r--r--gr-digital/lib/probe_mpsk_snr_est_c_impl.h78
-rwxr-xr-xgr-digital/python/qa_mpsk_snr_est.py61
-rwxr-xr-xgr-digital/python/qa_probe_density.py20
-rw-r--r--gr-digital/swig/digital_mpsk_snr_est_cc.i45
-rw-r--r--gr-digital/swig/digital_probe_density_b.i33
-rw-r--r--gr-digital/swig/digital_probe_mpsk_snr_est_c.i45
-rw-r--r--gr-digital/swig/digital_swig.i13
27 files changed, 1488 insertions, 1418 deletions
diff --git a/gr-digital/include/digital/CMakeLists.txt b/gr-digital/include/digital/CMakeLists.txt
index 7d8545b185..2445a6fe37 100644
--- a/gr-digital/include/digital/CMakeLists.txt
+++ b/gr-digital/include/digital/CMakeLists.txt
@@ -77,7 +77,7 @@ install(FILES
${digital_generated_includes}
api.h
glfsr.h
-# impl_mpsk_snr_est.h
+ mpsk_snr_est.h
additive_scrambler_bb.h
binary_slicer_fb.h
clock_recovery_mm_cc.h
@@ -105,7 +105,7 @@ install(FILES
map_bb.h
# metric_type.h
# mpsk_receiver_cc.h
-# mpsk_snr_est_cc.h
+ mpsk_snr_est_cc.h
# ofdm_cyclic_prefixer.h
# ofdm_frame_acquisition.h
# ofdm_frame_sink.h
@@ -116,8 +116,8 @@ install(FILES
pfb_clock_sync_ccf.h
pfb_clock_sync_fff.h
pn_correlator_cc.h
-# probe_density_b.h
-# probe_mpsk_snr_est_c.h
+ probe_density_b.h
+ probe_mpsk_snr_est_c.h
scrambler_bb.h
# simple_framer.h
# simple_framer_sync.h
diff --git a/gr-digital/include/digital/mpsk_snr_est.h b/gr-digital/include/digital/mpsk_snr_est.h
new file mode 100644
index 0000000000..80dad77ce3
--- /dev/null
+++ b/gr-digital/include/digital/mpsk_snr_est.h
@@ -0,0 +1,287 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011,2012 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_H
+#define INCLUDED_DIGITAL_MPSK_SNR_EST_H
+
+#include <digital/api.h>
+#include <gr_complex.h>
+
+namespace gr {
+ namespace digital {
+
+ //! Enum for the type of SNR estimator to select
+ /*! \ingroup snr_blk
+ * \anchor ref_snr_est_types
+ *
+ * Below are some ROUGH estimates of what values of SNR each of
+ * these types of estimators is good for. In general, these offer
+ * a trade-off between accuracy and performance.
+ *
+ * \li SNR_EST_SIMPLE: Simple estimator (>= 7 dB)
+ * \li SNR_EST_SKEW: Skewness-base est (>= 5 dB)
+ * \li SNR_EST_M2M4: 2nd & 4th moment est (>= 1 dB)
+ * \li SNR_EST_SVR: SVR-based est (>= 0dB)
+ */
+ 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 (>= 1 dB)
+ SNR_EST_SVR // SVR-based est (>= 0dB)
+ };
+
+ /*! \brief A parent class for SNR estimators, specifically for
+ * M-PSK signals in AWGN channels.
+ * \ingroup snr_blk
+ */
+ class DIGITAL_API mpsk_snr_est
+ {
+ protected:
+ double d_alpha, d_beta;
+
+ public:
+ /*! Constructor
+ *
+ * Parameters:
+ * \param alpha: the update rate of internal running average
+ * calculations.
+ */
+ mpsk_snr_est(double alpha);
+ virtual ~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,
+ const gr_complex *input);
+
+ //! Use the register values to compute a new estimate
+ virtual double snr();
+ };
+
+
+ //! \brief SNR Estimator using simple mean/variance estimates.
+ /*! \ingroup snr_blk
+ *
+ * A very simple SNR estimator that just uses mean and variance
+ * estimates of an M-PSK constellation. This esimator is quick
+ * and cheap and accurate for high SNR (above 7 dB or so) but
+ * quickly starts to overestimate the SNR at low SNR.
+ */
+ class DIGITAL_API mpsk_snr_est_simple :
+ public mpsk_snr_est
+ {
+ private:
+ double d_y1, d_y2;
+
+ public:
+ /*! Constructor
+ *
+ * Parameters:
+ * \param alpha: the update rate of internal running average
+ * calculations.
+ */
+ mpsk_snr_est_simple(double alpha);
+ ~mpsk_snr_est_simple() {}
+
+ int update(int noutput_items,
+ const gr_complex *input);
+ double snr();
+ };
+
+
+ //! \brief SNR Estimator using skewness correction.
+ /*! \ingroup snr_blk
+ *
+ * This is an estimator that came from a discussion between Tom
+ * Rondeau and fred harris with no known paper reference. The
+ * idea is that at low SNR, the variance estimations will be
+ * affected because of fold-over around the decision boundaries,
+ * which results in a skewness to the samples. We estimate the
+ * skewness and use this as a correcting term.
+ */
+ class DIGITAL_API mpsk_snr_est_skew :
+ public mpsk_snr_est
+ {
+ private:
+ double d_y1, d_y2, d_y3;
+
+ public:
+ /*! Constructor
+ *
+ * Parameters:
+ * \param alpha: the update rate of internal running average
+ * calculations.
+ */
+ mpsk_snr_est_skew(double alpha);
+ ~mpsk_snr_est_skew() {}
+
+ int update(int noutput_items,
+ const gr_complex *input);
+ double snr();
+ };
+
+
+ //! \brief SNR Estimator using 2nd and 4th-order moments.
+ /*! \ingroup snr_blk
+ *
+ * An SNR estimator for M-PSK signals that uses 2nd (M2) and 4th
+ * (M4) order moments. This estimator uses knowledge of the
+ * kurtosis of the signal (k_a) and noise (k_w) to make its
+ * estimation. We use Beaulieu's approximations here to M-PSK
+ * signals and AWGN channels such that k_a=1 and k_w=2. These
+ * approximations significantly reduce the complexity of the
+ * calculations (and computations) required.
+ *
+ * Reference:
+ * D. R. Pauluzzi and N. C. Beaulieu, "A comparison of SNR
+ * estimation techniques for the AWGN channel," IEEE
+ * Trans. Communications, Vol. 48, No. 10, pp. 1681-1691, 2000.
+ */
+ class DIGITAL_API mpsk_snr_est_m2m4 :
+ public mpsk_snr_est
+ {
+ private:
+ double d_y1, d_y2;
+
+ public:
+ /*! Constructor
+ *
+ * Parameters:
+ * \param alpha: the update rate of internal running average
+ * calculations.
+ */
+ mpsk_snr_est_m2m4(double alpha);
+ ~mpsk_snr_est_m2m4() {}
+
+ int update(int noutput_items,
+ const gr_complex *input);
+ double snr();
+ };
+
+
+ //! \brief SNR Estimator using 2nd and 4th-order moments.
+ /*! \ingroup snr_blk
+ *
+ * An SNR estimator for M-PSK signals that uses 2nd (M2) and 4th
+ * (M4) order moments. This estimator uses knowledge of the
+ * kurtosis of the signal (k_a) and noise (k_w) to make its
+ * estimation. In this case, you can set your own estimations for
+ * k_a and k_w, the kurtosis of the signal and noise, to fit this
+ * estimation better to your signal and channel conditions.
+ *
+ * A word of warning: this estimator has not been fully tested or
+ * proved with any amount of rigor. The estimation for M4 in
+ * particular might be ignoring effectf of when k_a and k_w are
+ * different. Use this estimator with caution and a copy of the
+ * reference on hand.
+ *
+ * The digital_mpsk_snr_est_m2m4 assumes k_a and k_w to simplify
+ * the computations for M-PSK and AWGN channels. Use that
+ * estimator unless you have a way to guess or estimate these
+ * values here.
+ *
+ * Original paper:
+ * R. Matzner, "An SNR estimation algorithm for complex baseband
+ * signal using higher order statistics," Facta Universitatis
+ * (Nis), no. 6, pp. 41-52, 1993.
+ *
+ * Reference used in derivation:
+ * D. R. Pauluzzi and N. C. Beaulieu, "A comparison of SNR
+ * estimation techniques for the AWGN channel," IEEE
+ * Trans. Communications, Vol. 48, No. 10, pp. 1681-1691, 2000.
+ */
+ class DIGITAL_API snr_est_m2m4 :
+ public mpsk_snr_est
+ {
+ private:
+ double d_y1, d_y2;
+ double d_ka, d_kw;
+
+ public:
+ /*! Constructor
+ *
+ * Parameters:
+ * \param alpha: the update rate of internal running average
+ * calculations.
+ * \param ka: estimate of the signal kurtosis (1 for PSK)
+ * \param kw: estimate of the channel noise kurtosis (2 for AWGN)
+ */
+ snr_est_m2m4(double alpha, double ka, double kw);
+ ~snr_est_m2m4() {}
+
+ int update(int noutput_items,
+ const gr_complex *input);
+ double snr();
+ };
+
+
+ //! \brief Signal-to-Variation Ratio SNR Estimator.
+ /*! \ingroup snr_blk
+ *
+ * This estimator actually comes from an SNR estimator for M-PSK
+ * signals in fading channels, but this implementation is
+ * specifically for AWGN channels. The math was simplified to
+ * assume a signal and noise kurtosis (k_a and k_w) for M-PSK
+ * signals in AWGN. These approximations significantly reduce the
+ * complexity of the calculations (and computations) required.
+ *
+ * Original paper:
+ * A. L. Brandao, L. B. Lopes, and D. C. McLernon, "In-service
+ * monitoring of multipath delay and cochannel interference for
+ * indoor mobile communication systems," Proc. IEEE
+ * Int. Conf. Communications, vol. 3, pp. 1458-1462, May 1994.
+ *
+ * Reference:
+ * D. R. Pauluzzi and N. C. Beaulieu, "A comparison of SNR
+ * estimation techniques for the AWGN channel," IEEE
+ * Trans. Communications, Vol. 48, No. 10, pp. 1681-1691, 2000.
+ */
+ class DIGITAL_API mpsk_snr_est_svr :
+ public mpsk_snr_est
+ {
+ private:
+ double d_y1, d_y2;
+
+ public:
+ /*! Constructor
+ *
+ * Parameters:
+ * \param alpha: the update rate of internal running average
+ * calculations.
+ */
+ mpsk_snr_est_svr(double alpha);
+ ~mpsk_snr_est_svr() {}
+
+ int update(int noutput_items,
+ const gr_complex *input);
+ double snr();
+ };
+
+ } /* namespace digital */
+} /* namespace gr */
+
+#endif /* INCLUDED_DIGITAL_MPSK_SNR_EST_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 0000000000..e6cc511dc7
--- /dev/null
+++ b/gr-digital/include/digital/mpsk_snr_est_cc.h
@@ -0,0 +1,96 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011,2012 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 <digital/mpsk_snr_est.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace digital {
+
+ //! \brief A block for computing SNR of a signal.
+ /*! \ingroup snr_blk
+ *
+ * This block can be used to monitor and retrieve estimations of
+ * the signal SNR. It is designed to work in a flowgraph and
+ * passes all incoming data along to its output.
+ *
+ * The block is designed for use with M-PSK signals
+ * especially. The type of estimator is specified as the \p type
+ * parameter in the constructor. The estimators tend to trade off
+ * performance for accuracy, although experimentation should be
+ * done to figure out the right approach for a given
+ * implementation. Further, the current set of estimators are
+ * designed and proven theoretically under AWGN conditions; some
+ * amount of error should be assumed and/or estimated for real
+ * channel conditions.
+ */
+ class DIGITAL_API mpsk_snr_est_cc : virtual public gr_sync_block
+ {
+ public:
+ // gr::digital::mpsk_snr_est_cc::sptr
+ typedef boost::shared_ptr<mpsk_snr_est_cc> sptr;
+
+ /*! Factory function returning shared pointer of this class
+ *
+ * Parameters:
+ *
+ * \param type: the type of estimator to use \ref ref_snr_est_types
+ * "snr_est_type_t" for details about the available types.
+ * \param tag_nsamples: after this many samples, a tag containing
+ * the SNR (key='snr') will be sent
+ * \param alpha: the update rate of internal running average
+ * calculations.
+ */
+ static sptr make(snr_est_type_t type,
+ int tag_nsamples,
+ double alpha);
+
+ //! Return the estimated signal-to-noise ratio in decibels
+ virtual double snr() = 0;
+
+ //! Return the type of estimator in use
+ virtual snr_est_type_t type() const = 0;
+
+ //! Return how many samples between SNR tags
+ virtual int tag_nsample() const = 0;
+
+ //! Get the running-average coefficient
+ virtual double alpha() const = 0;
+
+ //! Set type of estimator to use
+ virtual void set_type(snr_est_type_t t) = 0;
+
+ //! Set the number of samples between SNR tags
+ virtual void set_tag_nsample(int n) = 0;
+
+ //! Set the running-average coefficient
+ virtual void set_alpha(double alpha) = 0;
+ };
+
+ } /* namespace digital */
+} /* namespace gr */
+
+#endif /* INCLUDED_DIGITAL_MPSK_SNR_EST_CC_H */
diff --git a/gr-digital/include/digital/probe_density_b.h b/gr-digital/include/digital/probe_density_b.h
new file mode 100644
index 0000000000..7459663fe1
--- /dev/null
+++ b/gr-digital/include/digital/probe_density_b.h
@@ -0,0 +1,63 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2012 Free Software Foundation, Inc.
+ *
+ * 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_GR_PROBE_DENSITY_B_H
+#define INCLUDED_GR_PROBE_DENSITY_B_H
+
+#include <digital/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace digital {
+
+ /*!
+ * This block maintains a running average of the input stream and
+ * makes it available as an accessor function. The input stream
+ * is type unsigned char.
+ *
+ * If you send this block a stream of unpacked bytes, it will tell
+ * you what the bit density is.
+ *
+ * \param alpha Average filter constant
+ *
+ */
+ class DIGITAL_API probe_density_b : virtual public gr_sync_block
+ {
+ public:
+ // gr::digital::probe_density_b::sptr
+ typedef boost::shared_ptr<probe_density_b> sptr;
+
+ static sptr make(double alpha);
+
+ /*!
+ * \brief Returns the current density value
+ */
+ virtual double density() const = 0;
+
+ /*!
+ * \brief Set the average filter constant
+ */
+ virtual void set_alpha(double alpha) = 0;
+ };
+
+ } /* namespace digital */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_PROBE_DENSITY_B_H */
diff --git a/gr-digital/include/digital/probe_mpsk_snr_est_c.h b/gr-digital/include/digital/probe_mpsk_snr_est_c.h
new file mode 100644
index 0000000000..d65e8e1b6e
--- /dev/null
+++ b/gr-digital/include/digital/probe_mpsk_snr_est_c.h
@@ -0,0 +1,94 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011,2012 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_PROBE_MPSK_SNR_EST_C_H
+#define INCLUDED_DIGITAL_PROBE_MPSK_SNR_EST_C_H
+
+#include <digital/api.h>
+#include <digital/mpsk_snr_est.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace digital {
+
+ //! \brief A probe for computing SNR of a signal.
+ /*! \ingroup snr_blk
+ *
+ * This is a probe block (a sink) that can be used to monitor and
+ * retrieve estimations of the signal SNR. This probe is designed
+ * for use with M-PSK signals especially. The type of estimator
+ * is specified as the \p type parameter in the constructor. The
+ * estimators tend to trade off performance for accuracy,
+ * although experimentation should be done to figure out the
+ * right approach for a given implementation. Further, the
+ * current set of estimators are designed and proven
+ * theoretically under AWGN conditions; some amount of error
+ * should be assumed and/or estimated for real channel
+ * conditions.
+ */
+ class DIGITAL_API probe_mpsk_snr_est_c : virtual public gr_sync_block
+ {
+ public:
+ // gr::digital::probe_mpsk_snr_est_c::sptr
+ typedef boost::shared_ptr<probe_mpsk_snr_est_c> sptr;
+
+ /*! Make an MPSK SNR probe.
+ *
+ * Parameters:
+ *
+ * \param type: the type of estimator to use \ref ref_snr_est_types
+ * "snr_est_type_t" for details about the available types.
+ * \param msg_nsamples: [not implemented yet] after this many
+ * samples, a message containing the SNR (key='snr') will be sent
+ * \param alpha: the update rate of internal running average
+ * calculations.
+ */
+ static sptr make(snr_est_type_t type,
+ int msg_nsamples,
+ double alpha);
+
+ //! Return the estimated signal-to-noise ratio in decibels
+ virtual double snr() = 0;
+
+ //! Return the type of estimator in use
+ virtual snr_est_type_t type() const = 0;
+
+ //! Return how many samples between SNR messages
+ virtual int msg_nsample() const = 0;
+
+ //! Get the running-average coefficient
+ virtual double alpha() const = 0;
+
+ //! Set type of estimator to use
+ virtual void set_type(snr_est_type_t t) = 0;
+
+ //! Set the number of samples between SNR messages
+ virtual void set_msg_nsample(int n) = 0;
+
+ //! Set the running-average coefficient
+ virtual void set_alpha(double alpha) = 0;
+ };
+
+ } /* namespace digital */
+} /* namespace gr */
+
+#endif /* INCLUDED_DIGITAL_PROBE_MPSK_SNR_EST_C_H */
diff --git a/gr-digital/include/digital_impl_mpsk_snr_est.h b/gr-digital/include/digital_impl_mpsk_snr_est.h
deleted file mode 100644
index df7dbadec1..0000000000
--- a/gr-digital/include/digital_impl_mpsk_snr_est.h
+++ /dev/null
@@ -1,279 +0,0 @@
-/* -*- 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>
-
-//! Enum for the type of SNR estimator to select
-/*! \ingroup snr_blk
- * \anchor ref_snr_est_types
- *
- * Below are some ROUGH estimates of what values of SNR each of these
- * types of estimators is good for. In general, these offer a
- * trade-off between accuracy and performance.
- *
- * \li SNR_EST_SIMPLE: Simple estimator (>= 7 dB)
- * \li SNR_EST_SKEW: Skewness-base est (>= 5 dB)
- * \li SNR_EST_M2M4: 2nd & 4th moment est (>= 1 dB)
- * \li SNR_EST_SVR: SVR-based est (>= 0dB)
-*/
-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 (>= 1 dB)
- SNR_EST_SVR // SVR-based est (>= 0dB)
-};
-
-/*! \brief A parent class for SNR estimators, specifically for M-PSK
- * signals in AWGN channels.
- * \ingroup snr_blk
- */
-class DIGITAL_API digital_impl_mpsk_snr_est
-{
- protected:
- double d_alpha, d_beta;
-
- public:
- /*! Constructor
- *
- * Parameters:
- * \param alpha: the update rate of internal running average
- * calculations.
- */
- 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,
- const gr_complex *in);
-
- //! Use the register values to compute a new estimate
- virtual double snr();
-};
-
-
-//! \brief SNR Estimator using simple mean/variance estimates.
-/*! \ingroup snr_blk
- *
- * A very simple SNR estimator that just uses mean and variance
- * estimates of an M-PSK constellation. This esimator is quick and
- * cheap and accurate for high SNR (above 7 dB or so) but quickly
- * starts to overestimate the SNR at low SNR.
- */
-class DIGITAL_API digital_impl_mpsk_snr_est_simple :
- public digital_impl_mpsk_snr_est
-{
- private:
- double d_y1, d_y2;
-
- public:
- /*! Constructor
- *
- * Parameters:
- * \param alpha: the update rate of internal running average
- * calculations.
- */
- digital_impl_mpsk_snr_est_simple(double alpha);
- ~digital_impl_mpsk_snr_est_simple() {}
-
- int update(int noutput_items,
- const gr_complex *in);
- double snr();
-};
-
-
-//! \brief SNR Estimator using skewness correction.
-/*! \ingroup snr_blk
- *
- * This is an estimator that came from a discussion between Tom
- * Rondeau and fred harris with no known paper reference. The idea is
- * that at low SNR, the variance estimations will be affected because
- * of fold-over around the decision boundaries, which results in a
- * skewness to the samples. We estimate the skewness and use this as
- * a correcting term.
- */
-class DIGITAL_API digital_impl_mpsk_snr_est_skew :
- public digital_impl_mpsk_snr_est
-{
- private:
- double d_y1, d_y2, d_y3;
-
- public:
- /*! Constructor
- *
- * Parameters:
- * \param alpha: the update rate of internal running average
- * calculations.
- */
- digital_impl_mpsk_snr_est_skew(double alpha);
- ~digital_impl_mpsk_snr_est_skew() {}
-
- int update(int noutput_items,
- const gr_complex *in);
- double snr();
-};
-
-
-//! \brief SNR Estimator using 2nd and 4th-order moments.
-/*! \ingroup snr_blk
- *
- * An SNR estimator for M-PSK signals that uses 2nd (M2) and 4th (M4)
- * order moments. This estimator uses knowledge of the kurtosis of
- * the signal (k_a) and noise (k_w) to make its estimation. We use
- * Beaulieu's approximations here to M-PSK signals and AWGN channels
- * such that k_a=1 and k_w=2. These approximations significantly
- * reduce the complexity of the calculations (and computations)
- * required.
- *
- * Reference:
- * D. R. Pauluzzi and N. C. Beaulieu, "A comparison of SNR
- * estimation techniques for the AWGN channel," IEEE
- * Trans. Communications, Vol. 48, No. 10, pp. 1681-1691, 2000.
- */
-class DIGITAL_API digital_impl_mpsk_snr_est_m2m4 :
- public digital_impl_mpsk_snr_est
-{
- private:
- double d_y1, d_y2;
-
- public:
- /*! Constructor
- *
- * Parameters:
- * \param alpha: the update rate of internal running average
- * calculations.
- */
- digital_impl_mpsk_snr_est_m2m4(double alpha);
- ~digital_impl_mpsk_snr_est_m2m4() {}
-
- int update(int noutput_items,
- const gr_complex *in);
- double snr();
-};
-
-
-//! \brief SNR Estimator using 2nd and 4th-order moments.
-/*! \ingroup snr_blk
- *
- * An SNR estimator for M-PSK signals that uses 2nd (M2) and 4th (M4)
- * order moments. This estimator uses knowledge of the kurtosis of
- * the signal (k_a) and noise (k_w) to make its estimation. In this
- * case, you can set your own estimations for k_a and k_w, the
- * kurtosis of the signal and noise, to fit this estimation better to
- * your signal and channel conditions.
- *
- * A word of warning: this estimator has not been fully tested or
- * proved with any amount of rigor. The estimation for M4 in
- * particular might be ignoring effectf of when k_a and k_w are
- * different. Use this estimator with caution and a copy of the
- * reference on hand.
- *
- * The digital_mpsk_snr_est_m2m4 assumes k_a and k_w to simplify the
- * computations for M-PSK and AWGN channels. Use that estimator
- * unless you have a way to guess or estimate these values here.
- *
- * Original paper:
- * R. Matzner, "An SNR estimation algorithm for complex baseband
- * signal using higher order statistics," Facta Universitatis
- * (Nis), no. 6, pp. 41-52, 1993.
- *
- * Reference used in derivation:
- * D. R. Pauluzzi and N. C. Beaulieu, "A comparison of SNR
- * estimation techniques for the AWGN channel," IEEE
- * Trans. Communications, Vol. 48, No. 10, pp. 1681-1691, 2000.
- */
-class DIGITAL_API digital_impl_snr_est_m2m4 :
- public digital_impl_mpsk_snr_est
-{
- private:
- double d_y1, d_y2;
- double d_ka, d_kw;
-
- public:
- /*! Constructor
- *
- * Parameters:
- * \param alpha: the update rate of internal running average
- * calculations.
- * \param ka: estimate of the signal kurtosis (1 for PSK)
- * \param kw: estimate of the channel noise kurtosis (2 for AWGN)
- */
- digital_impl_snr_est_m2m4(double alpha, double ka, double kw);
- ~digital_impl_snr_est_m2m4() {}
-
- int update(int noutput_items,
- const gr_complex *in);
- double snr();
-};
-
-
-//! \brief Signal-to-Variation Ratio SNR Estimator.
-/*! \ingroup snr_blk
- *
- * This estimator actually comes from an SNR estimator for M-PSK
- * signals in fading channels, but this implementation is
- * specifically for AWGN channels. The math was simplified to assume
- * a signal and noise kurtosis (k_a and k_w) for M-PSK signals in
- * AWGN. These approximations significantly reduce the complexity of
- * the calculations (and computations) required.
- *
- * Original paper:
- * A. L. Brandao, L. B. Lopes, and D. C. McLernon, "In-service
- * monitoring of multipath delay and cochannel interference for
- * indoor mobile communication systems," Proc. IEEE
- * Int. Conf. Communications, vol. 3, pp. 1458-1462, May 1994.
- *
- * Reference:
- * D. R. Pauluzzi and N. C. Beaulieu, "A comparison of SNR
- * estimation techniques for the AWGN channel," IEEE
- * Trans. Communications, Vol. 48, No. 10, pp. 1681-1691, 2000.
- */
-class DIGITAL_API digital_impl_mpsk_snr_est_svr :
- public digital_impl_mpsk_snr_est
-{
- private:
- double d_y1, d_y2;
-
- public:
- /*! Constructor
- *
- * Parameters:
- * \param alpha: the update rate of internal running average
- * calculations.
- */
- digital_impl_mpsk_snr_est_svr(double alpha);
- ~digital_impl_mpsk_snr_est_svr() {}
-
- int update(int noutput_items,
- const gr_complex *in);
- double snr();
-};
-
-#endif /* INCLUDED_DIGITAL_IMPL_MPSK_SNR_EST_H */
diff --git a/gr-digital/include/digital_mpsk_snr_est_cc.h b/gr-digital/include/digital_mpsk_snr_est_cc.h
deleted file mode 100644
index 2cbd98bab8..0000000000
--- a/gr-digital/include/digital_mpsk_snr_est_cc.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/* -*- 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>
-#include <digital_impl_mpsk_snr_est.h>
-
-class digital_mpsk_snr_est_cc;
-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.
-/*! \ingroup snr_blk
- *
- * This block can be used to monitor and retrieve estimations of the
- * signal SNR. It is designed to work in a flowgraph and passes all
- * incoming data along to its output.
- *
- * The block is designed for use with M-PSK signals especially. The
- * type of estimator is specified as the \p type parameter in the
- * constructor. The estimators tend to trade off performance for
- * accuracy, although experimentation should be done to figure out
- * the right approach for a given implementation. Further, the
- * current set of estimators are designed and proven theoretically
- * under AWGN conditions; some amount of error should be assumed
- * and/or estimated for real channel conditions.
- */
-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:
- *
- * \param type: the type of estimator to use \ref ref_snr_est_types
- * "snr_est_type_t" for details about the available types.
- * \param tag_nsamples: after this many samples, a tag containing
- * the SNR (key='snr') will be sent
- * \param 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,
- int tag_nsamples,
- double alpha);
-
- // Private constructor
- digital_mpsk_snr_est_cc(snr_est_type_t type,
- int tag_nsamples,
- double alpha);
-
-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;
-
- //! 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);
-};
-
-#endif /* INCLUDED_DIGITAL_MPSK_SNR_EST_CC_H */
diff --git a/gr-digital/include/digital_probe_density_b.h b/gr-digital/include/digital_probe_density_b.h
deleted file mode 100644
index 271ad2a072..0000000000
--- a/gr-digital/include/digital_probe_density_b.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2008,2012 Free Software Foundation, Inc.
- *
- * 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_GR_PROBE_DENSITY_B_H
-#define INCLUDED_GR_PROBE_DENSITY_B_H
-
-#include <digital_api.h>
-#include <gr_sync_block.h>
-
-class digital_probe_density_b;
-
-typedef boost::shared_ptr<digital_probe_density_b> digital_probe_density_b_sptr;
-
-DIGITAL_API digital_probe_density_b_sptr
-digital_make_probe_density_b(double alpha);
-
-/*!
- * This block maintains a running average of the input stream and
- * makes it available as an accessor function. The input stream
- * is type unsigned char.
- *
- * If you send this block a stream of unpacked bytes, it will tell
- * you what the bit density is.
- *
- * \param alpha Average filter constant
- *
- */
-
-class DIGITAL_API digital_probe_density_b : public gr_sync_block
-{
-private:
- friend DIGITAL_API digital_probe_density_b_sptr
- digital_make_probe_density_b(double alpha);
-
- double d_alpha;
- double d_beta;
- double d_density;
-
- digital_probe_density_b(double alpha);
-
-public:
- ~digital_probe_density_b();
-
- /*!
- * \brief Returns the current density value
- */
- double density() const { return d_density; }
-
- /*!
- * \brief Set the average filter constant
- */
- void set_alpha(double alpha);
-
- int work(int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items);
-};
-
-#endif /* INCLUDED_GR_PROBE_DENSITY_B_H */
diff --git a/gr-digital/include/digital_probe_mpsk_snr_est_c.h b/gr-digital/include/digital_probe_mpsk_snr_est_c.h
deleted file mode 100644
index a78e904124..0000000000
--- a/gr-digital/include/digital_probe_mpsk_snr_est_c.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/* -*- 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_PROBE_MPSK_SNR_EST_C_H
-#define INCLUDED_DIGITAL_PROBE_MPSK_SNR_EST_C_H
-
-#include <digital_api.h>
-#include <gr_sync_block.h>
-#include <digital_impl_mpsk_snr_est.h>
-
-class digital_probe_mpsk_snr_est_c;
-typedef boost::shared_ptr<digital_probe_mpsk_snr_est_c> digital_probe_mpsk_snr_est_c_sptr;
-
-DIGITAL_API digital_probe_mpsk_snr_est_c_sptr
-digital_make_probe_mpsk_snr_est_c(snr_est_type_t type,
- int msg_nsamples=10000,
- double alpha=0.001);
-
-//! \brief A probe for computing SNR of a signal.
-/*! \ingroup snr_blk
- *
- * This is a probe block (a sink) that can be used to monitor and
- * retrieve estimations of the signal SNR. This probe is designed for
- * use with M-PSK signals especially. The type of estimator is
- * specified as the \p type parameter in the constructor. The
- * estimators tend to trade off performance for accuracy, although
- * experimentation should be done to figure out the right approach
- * for a given implementation. Further, the current set of estimators
- * are designed and proven theoretically under AWGN conditions; some
- * amount of error should be assumed and/or estimated for real
- * channel conditions.
- */
-class DIGITAL_API digital_probe_mpsk_snr_est_c : 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 message name, 'snr'
- pmt::pmt_t d_key;
-
- /*! Factory function returning shared pointer of this class
- *
- * Parameters:
- *
- * \param type: the type of estimator to use \ref ref_snr_est_types
- * "snr_est_type_t" for details about the available types.
- * \param msg_nsamples: [not implemented yet] after this many
- * samples, a message containing the SNR (key='snr') will be sent
- * \param alpha: the update rate of internal running average
- * calculations.
- */
- friend DIGITAL_API digital_probe_mpsk_snr_est_c_sptr
- digital_make_probe_mpsk_snr_est_c(snr_est_type_t type,
- int msg_nsamples,
- double alpha);
-
- //! Private constructor
- digital_probe_mpsk_snr_est_c(snr_est_type_t type,
- int msg_nsamples,
- double alpha);
-
-public:
-
- ~digital_probe_mpsk_snr_est_c();
-
- 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;
-
- //! Return how many samples between SNR messages
- int msg_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 messages
- void set_msg_nsample(int n);
-
- //! Set the running-average coefficient
- void set_alpha(double alpha);
-};
-
-#endif /* INCLUDED_DIGITAL_PROBE_MPSK_SNR_EST_C_H */
diff --git a/gr-digital/lib/CMakeLists.txt b/gr-digital/lib/CMakeLists.txt
index 937964a3db..0ae9e3d6bd 100644
--- a/gr-digital/lib/CMakeLists.txt
+++ b/gr-digital/lib/CMakeLists.txt
@@ -105,7 +105,7 @@ list(APPEND digital_sources
${generated_sources}
constellation.cc
glfsr.cc
- #impl_mpsk_snr_est.cc
+ mpsk_snr_est.cc
additive_scrambler_bb_impl.cc
binary_slicer_fb_impl.cc
clock_recovery_mm_cc_impl.cc
@@ -131,7 +131,7 @@ list(APPEND digital_sources
#kurtotic_equalizer_cc_impl.cc
map_bb_impl.cc
#mpsk_receiver_cc_impl.cc
- #mpsk_snr_est_cc_impl.cc
+ mpsk_snr_est_cc_impl.cc
#ofdm_cyclic_prefixer_impl.cc
#ofdm_frame_acquisition_impl.cc
#ofdm_frame_sink_impl.cc
@@ -142,8 +142,8 @@ list(APPEND digital_sources
pfb_clock_sync_ccf_impl.cc
pfb_clock_sync_fff_impl.cc
pn_correlator_cc_impl.cc
- #probe_density_b_impl.cc
- #probe_mpsk_snr_est_c_impl.cc
+ probe_density_b_impl.cc
+ probe_mpsk_snr_est_c_impl.cc
scrambler_bb_impl.cc
#simple_framer_impl.cc
)
diff --git a/gr-digital/lib/digital_impl_mpsk_snr_est.cc b/gr-digital/lib/digital_impl_mpsk_snr_est.cc
deleted file mode 100644
index 38177083fc..0000000000
--- a/gr-digital/lib/digital_impl_mpsk_snr_est.cc
+++ /dev/null
@@ -1,256 +0,0 @@
-/* -*- 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
deleted file mode 100644
index b5a60f0d38..0000000000
--- a/gr-digital/lib/digital_mpsk_snr_est_cc.cc
+++ /dev/null
@@ -1,186 +0,0 @@
-/* -*- 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_density_b.cc b/gr-digital/lib/digital_probe_density_b.cc
deleted file mode 100644
index 6b83d2ddb7..0000000000
--- a/gr-digital/lib/digital_probe_density_b.cc
+++ /dev/null
@@ -1,68 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2008,2010,2012 Free Software Foundation, Inc.
- *
- * 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_density_b.h>
-#include <gr_io_signature.h>
-#include <stdexcept>
-#include <iostream>
-
-digital_probe_density_b_sptr
-digital_make_probe_density_b(double alpha)
-{
- return gnuradio::get_initial_sptr(new digital_probe_density_b(alpha));
-}
-
-digital_probe_density_b::digital_probe_density_b(double alpha)
- : gr_sync_block("density_b",
- gr_make_io_signature(1, 1, sizeof(char)),
- gr_make_io_signature(0, 0, 0))
-{
- set_alpha(alpha);
- d_density = 1.0;
-}
-
-digital_probe_density_b::~digital_probe_density_b()
-{
-}
-
-int
-digital_probe_density_b::work(int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
-{
- const char *in = (const char *)input_items[0];
-
- for (int i = 0; i < noutput_items; i++)
- d_density = d_alpha*(double)in[i] + d_beta*d_density;
-
- return noutput_items;
-}
-
-void
-digital_probe_density_b::set_alpha(double alpha)
-{
- d_alpha = alpha;
- d_beta = 1.0-d_alpha;
-}
-
diff --git a/gr-digital/lib/digital_probe_mpsk_snr_est_c.cc b/gr-digital/lib/digital_probe_mpsk_snr_est_c.cc
deleted file mode 100644
index 5cdfea96d1..0000000000
--- a/gr-digital/lib/digital_probe_mpsk_snr_est_c.cc
+++ /dev/null
@@ -1,152 +0,0 @@
-/* -*- 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");
-}
diff --git a/gr-digital/lib/mpsk_snr_est.cc b/gr-digital/lib/mpsk_snr_est.cc
new file mode 100644
index 0000000000..1457a1a918
--- /dev/null
+++ b/gr-digital/lib/mpsk_snr_est.cc
@@ -0,0 +1,252 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011,2012 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.h>
+#include <stdexcept>
+#include <cstdio>
+
+namespace gr {
+ namespace digital {
+
+ mpsk_snr_est::mpsk_snr_est(double alpha)
+ {
+ set_alpha(alpha);
+ }
+
+ mpsk_snr_est::~mpsk_snr_est()
+ {}
+
+ void
+ mpsk_snr_est::set_alpha(double alpha)
+ {
+ d_alpha = alpha;
+ d_beta = 1.0-alpha;
+ }
+
+ double
+ mpsk_snr_est::alpha() const
+ {
+ return d_alpha;
+ }
+
+ int
+ mpsk_snr_est::update(int noutput_items,
+ const gr_complex *input)
+ {
+ throw std::runtime_error("mpsk_snr_est: Unimplemented");
+ }
+
+ double
+ mpsk_snr_est::snr()
+ {
+ throw std::runtime_error("mpsk_snr_est: Unimplemented");
+ }
+
+
+ /*****************************************************************/
+
+
+ mpsk_snr_est_simple::mpsk_snr_est_simple(double alpha) :
+ mpsk_snr_est(alpha)
+ {
+ d_y1 = 0;
+ d_y2 = 0;
+ }
+
+ int
+ mpsk_snr_est_simple::update(int noutput_items,
+ const gr_complex *input)
+ {
+ for(int i = 0; i < noutput_items; i++) {
+ double y1 = abs(input[i]);
+ d_y1 = d_alpha*y1 + d_beta*d_y1;
+
+ double y2 = real(input[i]*input[i]);
+ d_y2 = d_alpha*y2 + d_beta*d_y2;
+ }
+ return noutput_items;
+ }
+
+ double
+ 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);
+ }
+
+
+ /*****************************************************************/
+
+
+ mpsk_snr_est_skew::mpsk_snr_est_skew(double alpha) :
+ mpsk_snr_est(alpha)
+ {
+ d_y1 = 0;
+ d_y2 = 0;
+ d_y3 = 0;
+ }
+
+ int
+ mpsk_snr_est_skew::update(int noutput_items,
+ const gr_complex *input)
+ {
+ for(int i = 0; i < noutput_items; i++) {
+ double y1 = abs(input[i]);
+ d_y1 = d_alpha*y1 + d_beta*d_y1;
+
+ double y2 = real(input[i]*input[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(input[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
+ 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));
+ }
+
+
+ /*****************************************************************/
+
+
+ mpsk_snr_est_m2m4::mpsk_snr_est_m2m4(double alpha) :
+ mpsk_snr_est(alpha)
+ {
+ d_y1 = 0;
+ d_y2 = 0;
+ }
+
+ int
+ mpsk_snr_est_m2m4::update(int noutput_items,
+ const gr_complex *input)
+ {
+ for(int i = 0; i < noutput_items; i++) {
+ double y1 = abs(input[i])*abs(input[i]);
+ d_y1 = d_alpha*y1 + d_beta*d_y1;
+
+ double y2 = abs(input[i])*abs(input[i])*abs(input[i])*abs(input[i]);
+ d_y2 = d_alpha*y2 + d_beta*d_y2;
+ }
+ return noutput_items;
+ }
+
+ double
+ 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)));
+ }
+
+
+ /*****************************************************************/
+
+
+ snr_est_m2m4::snr_est_m2m4(double alpha, double ka, double kw) :
+ mpsk_snr_est(alpha)
+ {
+ d_y1 = 0;
+ d_y2 = 0;
+ d_ka = ka;
+ d_kw = kw;
+ }
+
+ int
+ snr_est_m2m4::update(int noutput_items,
+ const gr_complex *input)
+ {
+ for(int i = 0; i < noutput_items; i++) {
+ double y1 = abs(input[i])*abs(input[i]);
+ d_y1 = d_alpha*y1 + d_beta*d_y1;
+
+ double y2 = abs(input[i])*abs(input[i])*abs(input[i])*abs(input[i]);
+ d_y2 = d_alpha*y2 + d_beta*d_y2;
+ }
+ return noutput_items;
+ }
+
+ double
+ 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);
+ }
+
+
+ /*****************************************************************/
+
+
+ mpsk_snr_est_svr::mpsk_snr_est_svr(double alpha) :
+ mpsk_snr_est(alpha)
+ {
+ d_y1 = 0;
+ d_y2 = 0;
+ }
+
+ int
+ mpsk_snr_est_svr::update(int noutput_items,
+ const gr_complex *input)
+ {
+ for(int i = 0; i < noutput_items; i++) {
+ double x = abs(input[i]);
+ double x1 = abs(input[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
+ mpsk_snr_est_svr::snr()
+ {
+ double x = d_y1 / (d_y2 - d_y1);
+ return 10.0*log10(2.*((x-1) + sqrt(x*(x-1))));
+ }
+
+ } /* namespace digital */
+} /* namespace gr */
diff --git a/gr-digital/lib/mpsk_snr_est_cc_impl.cc b/gr-digital/lib/mpsk_snr_est_cc_impl.cc
new file mode 100644
index 0000000000..efd18ea4f4
--- /dev/null
+++ b/gr-digital/lib/mpsk_snr_est_cc_impl.cc
@@ -0,0 +1,192 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011,2012 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 "mpsk_snr_est_cc_impl.h"
+#include <gr_io_signature.h>
+#include <cstdio>
+
+namespace gr {
+ namespace digital {
+
+ mpsk_snr_est_cc::sptr
+ mpsk_snr_est_cc::make(snr_est_type_t type,
+ int tag_nsamples,
+ double alpha)
+ {
+ return gnuradio::get_initial_sptr
+ (new mpsk_snr_est_cc_impl(type, tag_nsamples, alpha));
+ }
+
+ mpsk_snr_est_cc_impl::mpsk_snr_est_cc_impl(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");
+ }
+
+ mpsk_snr_est_cc_impl::~mpsk_snr_est_cc_impl()
+ {
+ if(d_snr_est)
+ delete d_snr_est;
+ }
+
+ int
+ mpsk_snr_est_cc_impl::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
+ mpsk_snr_est_cc_impl::snr()
+ {
+ if(d_snr_est)
+ return d_snr_est->snr();
+ else
+ throw std::runtime_error("mpsk_snr_est_cc_impl:: No SNR estimator defined.\n");
+ }
+
+ snr_est_type_t
+ mpsk_snr_est_cc_impl::type() const
+ {
+ return d_type;
+ }
+
+ int
+ mpsk_snr_est_cc_impl::tag_nsample() const
+ {
+ return d_nsamples;
+ }
+
+ double
+ mpsk_snr_est_cc_impl::alpha() const
+ {
+ return d_alpha;
+ }
+
+ void
+ mpsk_snr_est_cc_impl::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 mpsk_snr_est_simple(d_alpha);
+ break;
+ case(SNR_EST_SKEW):
+ d_snr_est = new mpsk_snr_est_skew(d_alpha);
+ break;
+ case(SNR_EST_M2M4):
+ d_snr_est = new mpsk_snr_est_m2m4(d_alpha);
+ break;
+ case(SNR_EST_SVR):
+ d_snr_est = new mpsk_snr_est_svr(d_alpha);
+ break;
+ default:
+ throw std::invalid_argument("mpsk_snr_est_cc_impl: unknown type specified.\n");
+ }
+ }
+
+ void
+ mpsk_snr_est_cc_impl::set_tag_nsample(int n)
+ {
+ if(n > 0) {
+ d_nsamples = n;
+ d_count = 0; // reset state
+ }
+ else
+ throw std::invalid_argument("mpsk_snr_est_cc_impl: tag_nsamples can't be <= 0\n");
+ }
+
+ void
+ mpsk_snr_est_cc_impl::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("mpsk_snr_est_cc_impl: alpha must be in [0,1]\n");
+ }
+
+ } /* namespace digital */
+} /* namespace gr */
diff --git a/gr-digital/lib/mpsk_snr_est_cc_impl.h b/gr-digital/lib/mpsk_snr_est_cc_impl.h
new file mode 100644
index 0000000000..99ed066482
--- /dev/null
+++ b/gr-digital/lib/mpsk_snr_est_cc_impl.h
@@ -0,0 +1,79 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011,2012 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_IMPL_H
+#define INCLUDED_DIGITAL_MPSK_SNR_EST_CC_IMPL_H
+
+#include <digital/api.h>
+#include <digital/mpsk_snr_est_cc.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace digital {
+
+ class mpsk_snr_est_cc_impl : public mpsk_snr_est_cc
+ {
+ private:
+ snr_est_type_t d_type;
+ int d_nsamples, d_count;
+ double d_alpha;
+ 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;
+
+ public:
+ mpsk_snr_est_cc_impl(snr_est_type_t type,
+ int tag_nsamples,
+ double alpha);
+ ~mpsk_snr_est_cc_impl();
+
+ 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;
+
+ //! 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);
+ };
+
+ } /* namespace digital */
+} /* namespace gr */
+
+#endif /* INCLUDED_DIGITAL_MPSK_SNR_EST_CC_IMPL_H */
diff --git a/gr-digital/lib/probe_density_b_impl.cc b/gr-digital/lib/probe_density_b_impl.cc
new file mode 100644
index 0000000000..532930ad1b
--- /dev/null
+++ b/gr-digital/lib/probe_density_b_impl.cc
@@ -0,0 +1,73 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2010,2012 Free Software Foundation, Inc.
+ *
+ * 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 "probe_density_b_impl.h"
+#include <gr_io_signature.h>
+#include <iostream>
+
+namespace gr {
+ namespace digital {
+
+ probe_density_b::sptr
+ probe_density_b::make(double alpha)
+ {
+ return gnuradio::get_initial_sptr
+ (new probe_density_b_impl(alpha));
+ }
+
+ probe_density_b_impl::probe_density_b_impl(double alpha)
+ : gr_sync_block("density_b",
+ gr_make_io_signature(1, 1, sizeof(char)),
+ gr_make_io_signature(0, 0, 0))
+ {
+ set_alpha(alpha);
+ d_density = 1.0;
+ }
+
+ probe_density_b_impl::~probe_density_b_impl()
+ {
+ }
+
+ void
+ probe_density_b_impl::set_alpha(double alpha)
+ {
+ d_alpha = alpha;
+ d_beta = 1.0-d_alpha;
+ }
+
+ int
+ probe_density_b_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const char *in = (const char *)input_items[0];
+
+ for(int i = 0; i < noutput_items; i++)
+ d_density = d_alpha*(double)in[i] + d_beta*d_density;
+
+ return noutput_items;
+ }
+
+ } /* namespace digital */
+} /* namespace gr */
diff --git a/gr-digital/lib/probe_density_b_impl.h b/gr-digital/lib/probe_density_b_impl.h
new file mode 100644
index 0000000000..e792403dc5
--- /dev/null
+++ b/gr-digital/lib/probe_density_b_impl.h
@@ -0,0 +1,58 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2012 Free Software Foundation, Inc.
+ *
+ * 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_GR_PROBE_DENSITY_B_IMPL_H
+#define INCLUDED_GR_PROBE_DENSITY_B_IMPL_H
+
+#include <digital/probe_density_b.h>
+
+namespace gr {
+ namespace digital {
+
+ class probe_density_b_impl : public probe_density_b
+ {
+ private:
+ double d_alpha;
+ double d_beta;
+ double d_density;
+
+ public:
+ probe_density_b_impl(double alpha);
+ ~probe_density_b_impl();
+
+ /*!
+ * \brief Returns the current density value
+ */
+ double density() const { return d_density; }
+
+ /*!
+ * \brief Set the average filter constant
+ */
+ void set_alpha(double alpha);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace digital */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_PROBE_DENSITY_B_IMPL_H */
diff --git a/gr-digital/lib/probe_mpsk_snr_est_c_impl.cc b/gr-digital/lib/probe_mpsk_snr_est_c_impl.cc
new file mode 100644
index 0000000000..31de586e05
--- /dev/null
+++ b/gr-digital/lib/probe_mpsk_snr_est_c_impl.cc
@@ -0,0 +1,157 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011,2012 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 "probe_mpsk_snr_est_c_impl.h"
+#include <gr_io_signature.h>
+#include <cstdio>
+
+namespace gr {
+ namespace digital {
+
+ probe_mpsk_snr_est_c::sptr
+ probe_mpsk_snr_est_c::make(snr_est_type_t type,
+ int msg_nsamples,
+ double alpha)
+ {
+ return gnuradio::get_initial_sptr
+ (new probe_mpsk_snr_est_c_impl(type, msg_nsamples, alpha));
+ }
+
+ probe_mpsk_snr_est_c_impl::probe_mpsk_snr_est_c_impl(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");
+ }
+
+ probe_mpsk_snr_est_c_impl::~probe_mpsk_snr_est_c_impl()
+ {
+ if(d_snr_est)
+ delete d_snr_est;
+ }
+
+ int
+ probe_mpsk_snr_est_c_impl::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
+ probe_mpsk_snr_est_c_impl::snr()
+ {
+ if(d_snr_est)
+ return d_snr_est->snr();
+ else
+ throw std::runtime_error("probe_mpsk_snr_est_c_impl:: No SNR estimator defined.\n");
+ }
+
+ snr_est_type_t
+ probe_mpsk_snr_est_c_impl::type() const
+ {
+ return d_type;
+ }
+
+ int
+ probe_mpsk_snr_est_c_impl::msg_nsample() const
+ {
+ return d_nsamples;
+ }
+
+ double
+ probe_mpsk_snr_est_c_impl::alpha() const
+ {
+ return d_alpha;
+ }
+
+ void
+ probe_mpsk_snr_est_c_impl::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 mpsk_snr_est_simple(d_alpha);
+ break;
+ case(SNR_EST_SKEW):
+ d_snr_est = new mpsk_snr_est_skew(d_alpha);
+ break;
+ case(SNR_EST_M2M4):
+ d_snr_est = new mpsk_snr_est_m2m4(d_alpha);
+ break;
+ case(SNR_EST_SVR):
+ d_snr_est = new mpsk_snr_est_svr(d_alpha);
+ break;
+ default:
+ throw std::invalid_argument("probe_mpsk_snr_est_c_impl: unknown type specified.\n");
+ }
+ }
+
+ void
+ probe_mpsk_snr_est_c_impl::set_msg_nsample(int n)
+ {
+ if(n > 0) {
+ d_nsamples = n;
+ d_count = 0; // reset state
+ }
+ else
+ throw std::invalid_argument("probe_mpsk_snr_est_c_impl: msg_nsamples can't be <= 0\n");
+ }
+
+ void
+ probe_mpsk_snr_est_c_impl::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("probe_mpsk_snr_est_c_impl: alpha must be in [0,1]\n");
+ }
+
+ } /* namespace digital */
+} /* namespace gr */
diff --git a/gr-digital/lib/probe_mpsk_snr_est_c_impl.h b/gr-digital/lib/probe_mpsk_snr_est_c_impl.h
new file mode 100644
index 0000000000..2ee25b3617
--- /dev/null
+++ b/gr-digital/lib/probe_mpsk_snr_est_c_impl.h
@@ -0,0 +1,78 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011,2012 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_PROBE_MPSK_SNR_EST_C_IMPL_H
+#define INCLUDED_DIGITAL_PROBE_MPSK_SNR_EST_C_IMPL_H
+
+#include <digital/probe_mpsk_snr_est_c.h>
+
+namespace gr {
+ namespace digital {
+
+ class probe_mpsk_snr_est_c_impl : public probe_mpsk_snr_est_c
+ {
+ private:
+ snr_est_type_t d_type;
+ int d_nsamples, d_count;
+ double d_alpha;
+ mpsk_snr_est *d_snr_est;
+
+ //d_key is the message name, 'snr'
+ pmt::pmt_t d_key;
+
+ public:
+ probe_mpsk_snr_est_c_impl(snr_est_type_t type,
+ int msg_nsamples,
+ double alpha);
+
+ ~probe_mpsk_snr_est_c_impl();
+
+ 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;
+
+ //! Return how many samples between SNR messages
+ int msg_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 messages
+ void set_msg_nsample(int n);
+
+ //! Set the running-average coefficient
+ void set_alpha(double alpha);
+ };
+
+ } /* namespace digital */
+} /* namespace gr */
+
+#endif /* INCLUDED_DIGITAL_PROBE_MPSK_SNR_EST_C_IMPL_H */
diff --git a/gr-digital/python/qa_mpsk_snr_est.py b/gr-digital/python/qa_mpsk_snr_est.py
index d392567bfd..5e3377f7a7 100755
--- a/gr-digital/python/qa_mpsk_snr_est.py
+++ b/gr-digital/python/qa_mpsk_snr_est.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2011 Free Software Foundation, Inc.
+# Copyright 2011,2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -29,94 +29,93 @@ def get_cplx():
def get_n_cplx():
return complex(random.random()-0.5, random.random()-0.5)
-class test_mpsk_snr_est (gr_unittest.TestCase):
- def setUp (self):
- self.tb = gr.top_block ()
+class test_mpsk_snr_est(gr_unittest.TestCase):
+ def setUp(self):
+ self.tb = gr.top_block()
random.seed(0) # make repeatable
N = 10000
self._noise = [get_n_cplx() for i in xrange(N)]
self._bits = [get_cplx() for i in xrange(N)]
- def tearDown (self):
+ def tearDown(self):
self.tb = None
- def mpsk_snr_est_setup (self, op):
+ def mpsk_snr_est_setup(self, op):
result = []
for i in xrange(1,6):
src_data = [b+(i*n) for b,n in zip(self._bits, self._noise)]
- src = gr.vector_source_c (src_data)
- dst = gr.null_sink (gr.sizeof_gr_complex)
+ src = gr.vector_source_c(src_data)
+ dst = gr.null_sink(gr.sizeof_gr_complex)
- tb = gr.top_block ()
- tb.connect (src, op)
- tb.connect (op, dst)
- tb.run () # run the graph and wait for it to finish
+ tb = gr.top_block()
+ tb.connect(src, op)
+ tb.connect(op, dst)
+ tb.run() # run the graph and wait for it to finish
result.append(op.snr())
return result
- def test_mpsk_snr_est_simple (self):
+ def test_mpsk_snr_est_simple(self):
expected_result = [11.48, 5.91, 3.30, 2.08, 1.46]
N = 10000
alpha = 0.001
- op = digital.mpsk_snr_est_cc (digital.SNR_EST_SIMPLE, N, alpha)
+ op = digital.mpsk_snr_est_cc(digital.SNR_EST_SIMPLE, N, alpha)
actual_result = self.mpsk_snr_est_setup(op)
- self.assertFloatTuplesAlmostEqual (expected_result, actual_result, 2)
+ self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 2)
- def test_mpsk_snr_est_skew (self):
+ def test_mpsk_snr_est_skew(self):
expected_result = [11.48, 5.91, 3.30, 2.08, 1.46]
N = 10000
alpha = 0.001
- op = digital.mpsk_snr_est_cc (digital.SNR_EST_SKEW, N, alpha)
+ op = digital.mpsk_snr_est_cc(digital.SNR_EST_SKEW, N, alpha)
actual_result = self.mpsk_snr_est_setup(op)
- self.assertFloatTuplesAlmostEqual (expected_result, actual_result, 2)
+ self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 2)
- def test_mpsk_snr_est_m2m4 (self):
+ def test_mpsk_snr_est_m2m4(self):
expected_result = [11.02, 6.20, 4.98, 5.16, 5.66]
N = 10000
alpha = 0.001
- op = digital.mpsk_snr_est_cc (digital.SNR_EST_M2M4, N, alpha)
+ op = digital.mpsk_snr_est_cc(digital.SNR_EST_M2M4, N, alpha)
actual_result = self.mpsk_snr_est_setup(op)
- self.assertFloatTuplesAlmostEqual (expected_result, actual_result, 2)
+ self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 2)
def test_mpsk_snr_est_svn (self):
expected_result = [10.90, 6.00, 4.76, 4.97, 5.49]
N = 10000
alpha = 0.001
- op = digital.mpsk_snr_est_cc (digital.SNR_EST_SVR, N, alpha)
+ op = digital.mpsk_snr_est_cc(digital.SNR_EST_SVR, N, alpha)
actual_result = self.mpsk_snr_est_setup(op)
- self.assertFloatTuplesAlmostEqual (expected_result, actual_result, 2)
+ self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 2)
- def test_probe_mpsk_snr_est_m2m4 (self):
+ def test_probe_mpsk_snr_est_m2m4(self):
expected_result = [11.02, 6.20, 4.98, 5.16, 5.66]
actual_result = []
for i in xrange(1,6):
src_data = [b+(i*n) for b,n in zip(self._bits, self._noise)]
- src = gr.vector_source_c (src_data)
+ src = gr.vector_source_c(src_data)
N = 10000
alpha = 0.001
- op = digital.probe_mpsk_snr_est_c (digital.SNR_EST_M2M4, N, alpha)
+ op = digital.probe_mpsk_snr_est_c(digital.SNR_EST_M2M4, N, alpha)
- tb = gr.top_block ()
- tb.connect (src, op)
- tb.run () # run the graph and wait for it to finish
+ tb = gr.top_block()
+ tb.connect(src, op)
+ tb.run() # run the graph and wait for it to finish
actual_result.append(op.snr())
- self.assertFloatTuplesAlmostEqual (expected_result, actual_result, 2)
-
+ self.assertFloatTuplesAlmostEqual(expected_result, actual_result, 2)
if __name__ == '__main__':
# Test various SNR estimators; we're not using a Gaussian
diff --git a/gr-digital/python/qa_probe_density.py b/gr-digital/python/qa_probe_density.py
index c5b7e0e7c2..a782ed45a4 100755
--- a/gr-digital/python/qa_probe_density.py
+++ b/gr-digital/python/qa_probe_density.py
@@ -34,37 +34,37 @@ class test_probe_density(gr_unittest.TestCase):
def test_001(self):
src_data = [0, 1, 0, 1]
expected_data = 1
- src = gr.vector_source_b (src_data)
+ src = gr.vector_source_b(src_data)
op = digital.probe_density_b(1)
self.tb.connect (src, op)
self.tb.run ()
result_data = op.density()
- self.assertEqual (expected_data, result_data)
+ self.assertEqual(expected_data, result_data)
def test_002(self):
src_data = [1, 1, 1, 1]
expected_data = 1
- src = gr.vector_source_b (src_data)
+ src = gr.vector_source_b(src_data)
op = digital.probe_density_b(0.01)
- self.tb.connect (src, op)
- self.tb.run ()
+ self.tb.connect(src, op)
+ self.tb.run()
result_data = op.density()
- self.assertEqual (expected_data, result_data)
+ self.assertEqual(expected_data, result_data)
def test_003(self):
src_data = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
expected_data = 0.95243
- src = gr.vector_source_b (src_data)
+ src = gr.vector_source_b(src_data)
op = digital.probe_density_b(0.01)
- self.tb.connect (src, op)
- self.tb.run ()
+ self.tb.connect(src, op)
+ self.tb.run()
result_data = op.density()
print result_data
- self.assertAlmostEqual (expected_data, result_data, 5)
+ self.assertAlmostEqual(expected_data, result_data, 5)
if __name__ == '__main__':
gr_unittest.run(test_probe_density, "test_probe_density.xml")
diff --git a/gr-digital/swig/digital_mpsk_snr_est_cc.i b/gr-digital/swig/digital_mpsk_snr_est_cc.i
deleted file mode 100644
index f0ca13f874..0000000000
--- a/gr-digital/swig/digital_mpsk_snr_est_cc.i
+++ /dev/null
@@ -1,45 +0,0 @@
-/* -*- 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);
-
-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:
- double snr();
- snr_est_type_t type() const;
- int tag_nsample() const;
- double alpha() const;
- void set_type(snr_est_type_t t);
- void set_tag_nsample(int n);
- void set_alpha(double alpha);
-};
diff --git a/gr-digital/swig/digital_probe_density_b.i b/gr-digital/swig/digital_probe_density_b.i
deleted file mode 100644
index b0c8a119ad..0000000000
--- a/gr-digital/swig/digital_probe_density_b.i
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2008,2012 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,probe_density_b);
-
-digital_probe_density_b_sptr
-digital_make_probe_density_b(double alpha);
-
-class digital_probe_density_b : public gr_sync_block
-{
-public:
- double density() const;
- void set_alpha(double alpha);
-};
diff --git a/gr-digital/swig/digital_probe_mpsk_snr_est_c.i b/gr-digital/swig/digital_probe_mpsk_snr_est_c.i
deleted file mode 100644
index 93db4127ac..0000000000
--- a/gr-digital/swig/digital_probe_mpsk_snr_est_c.i
+++ /dev/null
@@ -1,45 +0,0 @@
-/* -*- 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,probe_mpsk_snr_est_c);
-
-digital_probe_mpsk_snr_est_c_sptr
-digital_make_probe_mpsk_snr_est_c(snr_est_type_t type,
- int msg_nsamples=10000,
- double alpha=0.001);
-
-class digital_probe_mpsk_snr_est_c : public gr_sync_block
-{
-private:
- void digital_probe_mpsk_snr_est_c(snr_est_type_t type,
- int msg_nsamples,
- double alpha);
-
-public:
- double snr();
- snr_est_type_t type() const;
- int msg_nsample() const;
- double alpha() const;
- void set_type(snr_est_type_t t);
- void set_msg_nsample(int n);
- void set_alpha(double alpha);
-};
diff --git a/gr-digital/swig/digital_swig.i b/gr-digital/swig/digital_swig.i
index 60da49da93..ab38466a9f 100644
--- a/gr-digital/swig/digital_swig.i
+++ b/gr-digital/swig/digital_swig.i
@@ -26,14 +26,12 @@
//load generated python docstrings
%include "digital_swig_doc.i"
-//#if SWIGPYTHON
//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 (>= 1 dB)
// SNR_EST_SVR // SVR-based est (>= 0dB)
//};
-//#endif
//%include <gri_control_loop.i>
@@ -41,6 +39,7 @@
%template(unsigned_int_vector) std::vector<unsigned int>;
%{
+#include "digital/mpsk_snr_est.h"
#include "digital/additive_scrambler_bb.h"
#include "digital/binary_slicer_fb.h"
#include "digital/chunks_to_symbols_bf.h"
@@ -66,12 +65,16 @@
#include "digital/glfsr_source_b.h"
#include "digital/glfsr_source_f.h"
#include "digital/map_bb.h"
+#include "digital/mpsk_snr_est_cc.h"
#include "digital/pfb_clock_sync_ccf.h"
#include "digital/pfb_clock_sync_fff.h"
#include "digital/pn_correlator_cc.h"
+#include "digital/probe_density_b.h"
+#include "digital/probe_mpsk_snr_est_c.h"
#include "digital/scrambler_bb.h"
%}
+%include "digital/mpsk_snr_est.h"
%include "digital/additive_scrambler_bb.h"
%include "digital/binary_slicer_fb.h"
%include "digital/chunks_to_symbols_bf.h"
@@ -97,9 +100,12 @@
%include "digital/glfsr_source_b.h"
%include "digital/glfsr_source_f.h"
%include "digital/map_bb.h"
+%include "digital/mpsk_snr_est_cc.h"
%include "digital/pfb_clock_sync_ccf.h"
%include "digital/pfb_clock_sync_fff.h"
%include "digital/pn_correlator_cc.h"
+%include "digital/probe_density_b.h"
+%include "digital/probe_mpsk_snr_est_c.h"
%include "digital/scrambler_bb.h"
GR_SWIG_BLOCK_MAGIC2(digital, additive_scrambler_bb);
@@ -126,9 +132,12 @@ GR_SWIG_BLOCK_MAGIC2(digital, fll_band_edge_cc);
GR_SWIG_BLOCK_MAGIC2(digital, glfsr_source_b);
GR_SWIG_BLOCK_MAGIC2(digital, glfsr_source_f);
GR_SWIG_BLOCK_MAGIC2(digital, map_bb);
+GR_SWIG_BLOCK_MAGIC2(digital, mpsk_snr_est_cc);
GR_SWIG_BLOCK_MAGIC2(digital, pfb_clock_sync_ccf);
GR_SWIG_BLOCK_MAGIC2(digital, pfb_clock_sync_fff);
GR_SWIG_BLOCK_MAGIC2(digital, pn_correlator_cc);
+GR_SWIG_BLOCK_MAGIC2(digital, probe_density_b);
+GR_SWIG_BLOCK_MAGIC2(digital, probe_mpsk_snr_est_c);
GR_SWIG_BLOCK_MAGIC2(digital, scrambler_bb);
// Properly package up constellation objects