summaryrefslogtreecommitdiff
path: root/gr-analog
diff options
context:
space:
mode:
Diffstat (limited to 'gr-analog')
-rw-r--r--gr-analog/include/analog/CMakeLists.txt3
-rw-r--r--gr-analog/include/analog/probe_avg_mag_sqrd_c.h67
-rw-r--r--gr-analog/include/analog/probe_avg_mag_sqrd_cf.h69
-rw-r--r--gr-analog/include/analog/probe_avg_mag_sqrd_f.h69
-rw-r--r--gr-analog/lib/CMakeLists.txt3
-rw-r--r--gr-analog/lib/probe_avg_mag_sqrd_c_impl.cc91
-rw-r--r--gr-analog/lib/probe_avg_mag_sqrd_c_impl.h60
-rw-r--r--gr-analog/lib/probe_avg_mag_sqrd_cf_impl.cc93
-rw-r--r--gr-analog/lib/probe_avg_mag_sqrd_cf_impl.h60
-rw-r--r--gr-analog/lib/probe_avg_mag_sqrd_f_impl.cc92
-rw-r--r--gr-analog/lib/probe_avg_mag_sqrd_f_impl.h60
-rw-r--r--gr-analog/python/qa_probe_avg_mag_sqrd.py98
-rw-r--r--gr-analog/swig/analog_swig.i9
13 files changed, 774 insertions, 0 deletions
diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt
index ac1d65932..f2c0f6d6f 100644
--- a/gr-analog/include/analog/CMakeLists.txt
+++ b/gr-analog/include/analog/CMakeLists.txt
@@ -94,6 +94,9 @@ install(FILES
pll_carriertracking_cc.h
pll_freqdet_cf.h
pll_refout_cc.h
+ probe_avg_mag_sqrd_c.h
+ probe_avg_mag_sqrd_cf.h
+ probe_avg_mag_sqrd_f.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/analog
COMPONENT "analog_devel"
)
diff --git a/gr-analog/include/analog/probe_avg_mag_sqrd_c.h b/gr-analog/include/analog/probe_avg_mag_sqrd_c.h
new file mode 100644
index 000000000..9e62732a3
--- /dev/null
+++ b/gr-analog/include/analog/probe_avg_mag_sqrd_c.h
@@ -0,0 +1,67 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2006,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_ANALOG_PROBE_AVG_MAG_SQRD_C_H
+#define INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_C_H
+
+#include <analog/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace analog {
+
+ /*!
+ * \brief compute avg magnitude squared.
+ * \ingroup sink_blk
+ *
+ * Input stream 0: complex
+ *
+ * Compute a running average of the magnitude squared of the the
+ * input. The level and indication as to whether the level exceeds
+ * threshold can be retrieved with the level and unmuted
+ * accessors.
+ */
+ class ANALOG_API probe_avg_mag_sqrd_c : virtual public gr_sync_block
+ {
+ public:
+ // gr::analog::probe_avg_mag_sqrd_c::sptr
+ typedef boost::shared_ptr<probe_avg_mag_sqrd_c> sptr;
+
+ /*!
+ * \brief Make a complex sink that computes avg magnitude squared.
+ *
+ * \param threshold_db Threshold for muting.
+ * \param alpha Gain parameter for the running average filter.
+ */
+ static sptr make(double threshold_db, double alpha = 0.0001);
+
+ virtual bool unmuted() const = 0;
+ virtual double level() const = 0;
+ virtual double threshold() const = 0;
+
+ virtual void set_alpha(double alpha) = 0;
+ virtual void set_threshold(double decibels) = 0;
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_C_H */
diff --git a/gr-analog/include/analog/probe_avg_mag_sqrd_cf.h b/gr-analog/include/analog/probe_avg_mag_sqrd_cf.h
new file mode 100644
index 000000000..b18916ae9
--- /dev/null
+++ b/gr-analog/include/analog/probe_avg_mag_sqrd_cf.h
@@ -0,0 +1,69 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2006,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_ANALOG_PROBE_AVG_MAG_SQRD_CF_H
+#define INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_CF_H
+
+#include <analog/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace analog {
+
+ /*!
+ * \brief compute avg magnitude squared.
+ * \ingroup sink_blk
+ *
+ * Input stream 0: complex
+ * Output stream 0: float
+ *
+ * Compute a running average of the magnitude squared of the the
+ * input. The level and indication as to whether the level exceeds
+ * threshold can be retrieved with the level and unmuted
+ * accessors.
+ */
+ class ANALOG_API probe_avg_mag_sqrd_cf : virtual public gr_sync_block
+ {
+ public:
+ // gr::analog::probe_avg_mag_sqrd_cf::sptr
+ typedef boost::shared_ptr<probe_avg_mag_sqrd_cf> sptr;
+
+ /*!
+ * \brief Make a block that computes avg magnitude squared.
+ *
+ * \param threshold_db Threshold for muting.
+ * \param alpha Gain parameter for the running average filter.
+ */
+ static sptr make(double threshold_db, double alpha = 0.0001);
+
+ virtual bool unmuted() const = 0;
+ virtual double level() const = 0;
+ virtual double threshold() const = 0;
+
+ virtual void set_alpha(double alpha) = 0;
+ virtual void set_threshold(double decibels) = 0;
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_CF_H */
diff --git a/gr-analog/include/analog/probe_avg_mag_sqrd_f.h b/gr-analog/include/analog/probe_avg_mag_sqrd_f.h
new file mode 100644
index 000000000..fe9d27793
--- /dev/null
+++ b/gr-analog/include/analog/probe_avg_mag_sqrd_f.h
@@ -0,0 +1,69 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,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_ANALOG_PROBE_AVG_MAG_SQRD_F_H
+#define INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_F_H
+
+#include <analog/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace analog {
+
+ /*!
+ * \brief compute avg magnitude squared.
+ * \ingroup sink_blk
+ *
+ * input stream 0: float
+ *
+ * Compute a running average of the magnitude squared of the the
+ * input. The level and indication as to whether the level exceeds
+ * threshold can be retrieved with the level and unmuted
+ * accessors.
+ */
+ class ANALOG_API probe_avg_mag_sqrd_f : virtual public gr_sync_block
+ {
+ public:
+ // gr::analog::probe_avg_mag_sqrd_f::sptr
+ typedef boost::shared_ptr<probe_avg_mag_sqrd_f> sptr;
+
+ /*!
+ * \brief Make a float sink that computes avg magnitude squared.
+ *
+ * \param threshold_db Threshold for muting.
+ * \param alpha Gain parameter for the running average filter.
+ */
+ static sptr make(double threshold_db, double alpha = 0.0001);
+
+ virtual bool unmuted() const = 0;
+ virtual double level() const = 0;
+
+ virtual double threshold() const = 0;
+
+ virtual void set_alpha (double alpha) = 0;
+ virtual void set_threshold (double decibels) = 0;
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_F_H */
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt
index 20a86621e..93ab5e83e 100644
--- a/gr-analog/lib/CMakeLists.txt
+++ b/gr-analog/lib/CMakeLists.txt
@@ -120,6 +120,9 @@ list(APPEND analog_sources
pll_carriertracking_cc_impl.cc
pll_freqdet_cf_impl.cc
pll_refout_cc_impl.cc
+ probe_avg_mag_sqrd_c_impl.cc
+ probe_avg_mag_sqrd_cf_impl.cc
+ probe_avg_mag_sqrd_f_impl.cc
)
list(APPEND analog_libs
diff --git a/gr-analog/lib/probe_avg_mag_sqrd_c_impl.cc b/gr-analog/lib/probe_avg_mag_sqrd_c_impl.cc
new file mode 100644
index 000000000..291809bb2
--- /dev/null
+++ b/gr-analog/lib/probe_avg_mag_sqrd_c_impl.cc
@@ -0,0 +1,91 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2010,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_avg_mag_sqrd_c_impl.h"
+#include <gr_io_signature.h>
+#include <cmath>
+
+namespace gr {
+ namespace analog {
+
+ probe_avg_mag_sqrd_c::sptr
+ probe_avg_mag_sqrd_c::make(double threshold_db, double alpha)
+ {
+ return gnuradio::get_initial_sptr
+ (new probe_avg_mag_sqrd_c_impl(threshold_db, alpha));
+ }
+
+ probe_avg_mag_sqrd_c_impl::probe_avg_mag_sqrd_c_impl(double threshold_db, double alpha)
+ : gr_sync_block("probe_avg_mag_sqrd_c",
+ gr_make_io_signature(1, 1, sizeof(gr_complex)),
+ gr_make_io_signature(0, 0, 0)),
+ d_unmuted(false), d_level(0), d_iir(alpha)
+ {
+ set_threshold(threshold_db);
+ }
+
+ probe_avg_mag_sqrd_c_impl::~probe_avg_mag_sqrd_c_impl()
+ {
+ }
+
+ int
+ probe_avg_mag_sqrd_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];
+
+ for(int i = 0; i < noutput_items; i++) {
+ double mag_sqrd = in[i].real()*in[i].real() + in[i].imag()*in[i].imag();
+ d_iir.filter(mag_sqrd); // computed for side effect: prev_output()
+ }
+
+ d_unmuted = d_iir.prev_output() >= d_threshold;
+ d_level = d_iir.prev_output();
+ return noutput_items;
+ }
+
+ double
+ probe_avg_mag_sqrd_c_impl::threshold() const
+ {
+ return 10 * std::log10(d_threshold);
+ }
+
+ void
+ probe_avg_mag_sqrd_c_impl::set_threshold(double decibels)
+ {
+ // convert to absolute threshold (mag squared)
+ d_threshold = std::pow(10.0, decibels/10);
+ }
+
+ void
+ probe_avg_mag_sqrd_c_impl::set_alpha(double alpha)
+ {
+ d_iir.set_taps(alpha);
+ }
+
+ } /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/probe_avg_mag_sqrd_c_impl.h b/gr-analog/lib/probe_avg_mag_sqrd_c_impl.h
new file mode 100644
index 000000000..0a2685357
--- /dev/null
+++ b/gr-analog/lib/probe_avg_mag_sqrd_c_impl.h
@@ -0,0 +1,60 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2006,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_ANALOG_PROBE_AVG_MAG_SQRD_C_IMPL_H
+#define INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_C_IMPL_H
+
+#include <analog/probe_avg_mag_sqrd_c.h>
+#include <filter/single_pole_iir.h>
+
+namespace gr {
+ namespace analog {
+
+ class probe_avg_mag_sqrd_c_impl : public probe_avg_mag_sqrd_c
+ {
+ private:
+ double d_threshold;
+ bool d_unmuted;
+ double d_level;
+ filter::single_pole_iir<double,double,double> d_iir;
+
+ public:
+ probe_avg_mag_sqrd_c_impl(double threshold_db, double alpha = 0.0001);
+ ~probe_avg_mag_sqrd_c_impl();
+
+ bool unmuted() const { return d_unmuted; }
+ double level() const { return d_level; }
+
+ double threshold() const;
+
+ void set_alpha(double alpha);
+ void set_threshold(double decibels);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_C_IMPL_H */
diff --git a/gr-analog/lib/probe_avg_mag_sqrd_cf_impl.cc b/gr-analog/lib/probe_avg_mag_sqrd_cf_impl.cc
new file mode 100644
index 000000000..ceaf5dbf0
--- /dev/null
+++ b/gr-analog/lib/probe_avg_mag_sqrd_cf_impl.cc
@@ -0,0 +1,93 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2007,2010,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_avg_mag_sqrd_cf_impl.h"
+#include <gr_io_signature.h>
+#include <cmath>
+
+namespace gr {
+ namespace analog {
+
+ probe_avg_mag_sqrd_cf::sptr
+ probe_avg_mag_sqrd_cf::make(double threshold_db, double alpha)
+ {
+ return gnuradio::get_initial_sptr
+ (new probe_avg_mag_sqrd_cf_impl(threshold_db, alpha));
+ }
+
+ probe_avg_mag_sqrd_cf_impl::probe_avg_mag_sqrd_cf_impl(double threshold_db, double alpha)
+ : gr_sync_block("probe_avg_mag_sqrd_cf",
+ gr_make_io_signature(1, 1, sizeof(gr_complex)),
+ gr_make_io_signature(1, 1, sizeof(float))),
+ d_unmuted(false), d_level(0), d_iir(alpha)
+ {
+ set_threshold(threshold_db);
+ }
+
+ probe_avg_mag_sqrd_cf_impl::~probe_avg_mag_sqrd_cf_impl()
+ {
+ }
+
+ int
+ probe_avg_mag_sqrd_cf_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];
+ float *out = (float*)output_items[0];
+
+ for(int i = 0; i < noutput_items; i++) {
+ out[i] = d_iir.prev_output();
+ double mag_sqrd = in[i].real()*in[i].real() + in[i].imag()*in[i].imag();
+ d_iir.filter(mag_sqrd); // computed for side effect: prev_output()
+ }
+
+ d_unmuted = d_iir.prev_output() >= d_threshold;
+ d_level = d_iir.prev_output();
+ return noutput_items;
+ }
+
+ double
+ probe_avg_mag_sqrd_cf_impl::threshold() const
+ {
+ return 10 * std::log10(d_threshold);
+ }
+
+ void
+ probe_avg_mag_sqrd_cf_impl::set_threshold(double decibels)
+ {
+ // convert to absolute threshold (mag squared)
+ d_threshold = std::pow(10.0, decibels/10);
+ }
+
+ void
+ probe_avg_mag_sqrd_cf_impl::set_alpha(double alpha)
+ {
+ d_iir.set_taps(alpha);
+ }
+
+ } /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/probe_avg_mag_sqrd_cf_impl.h b/gr-analog/lib/probe_avg_mag_sqrd_cf_impl.h
new file mode 100644
index 000000000..9cd8f8d4c
--- /dev/null
+++ b/gr-analog/lib/probe_avg_mag_sqrd_cf_impl.h
@@ -0,0 +1,60 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2006,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_ANALOG_PROBE_AVG_MAG_SQRD_CF_IMPL_H
+#define INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_CF_IMPL_H
+
+#include <analog/probe_avg_mag_sqrd_cf.h>
+#include <filter/single_pole_iir.h>
+
+namespace gr {
+ namespace analog {
+
+ class probe_avg_mag_sqrd_cf_impl : public probe_avg_mag_sqrd_cf
+ {
+ private:
+ double d_threshold;
+ bool d_unmuted;
+ double d_level;
+ filter::single_pole_iir<double,double,double> d_iir;
+
+ public:
+ probe_avg_mag_sqrd_cf_impl(double threshold_db, double alpha);
+ ~probe_avg_mag_sqrd_cf_impl();
+
+ bool unmuted() const { return d_unmuted; }
+ double level() const { return d_level; }
+
+ double threshold() const;
+
+ void set_alpha(double alpha);
+ void set_threshold(double decibels);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_CF_IMPL_H */
diff --git a/gr-analog/lib/probe_avg_mag_sqrd_f_impl.cc b/gr-analog/lib/probe_avg_mag_sqrd_f_impl.cc
new file mode 100644
index 000000000..4ac7ef06b
--- /dev/null
+++ b/gr-analog/lib/probe_avg_mag_sqrd_f_impl.cc
@@ -0,0 +1,92 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2010,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_avg_mag_sqrd_f_impl.h"
+#include <gr_io_signature.h>
+#include <cmath>
+
+namespace gr {
+ namespace analog {
+
+ probe_avg_mag_sqrd_f::sptr
+ probe_avg_mag_sqrd_f::make(double threshold_db, double alpha)
+ {
+ return gnuradio::get_initial_sptr
+ (new probe_avg_mag_sqrd_f_impl(threshold_db, alpha));
+ }
+
+ probe_avg_mag_sqrd_f_impl::probe_avg_mag_sqrd_f_impl(double threshold_db, double alpha)
+ : gr_sync_block("probe_avg_mag_sqrd_f",
+ gr_make_io_signature(1, 1, sizeof(float)),
+ gr_make_io_signature(0, 0, 0)),
+ d_unmuted(false), d_level(0), d_iir(alpha)
+ {
+ set_threshold(threshold_db);
+ }
+
+ probe_avg_mag_sqrd_f_impl::~probe_avg_mag_sqrd_f_impl()
+ {
+ }
+
+ int
+ probe_avg_mag_sqrd_f_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const float *in = (const float*)input_items[0];
+
+ for(int i = 0; i < noutput_items; i++) {
+ double mag_sqrd = in[i]*in[i];
+ d_iir.filter(mag_sqrd); // computed for side effect: prev_output()
+ }
+
+ d_unmuted = d_iir.prev_output() >= d_threshold;
+ d_level = d_iir.prev_output();
+ return noutput_items;
+ }
+
+ double
+ probe_avg_mag_sqrd_f_impl::threshold() const
+ {
+ return 10 * std::log10(d_threshold);
+ }
+
+ void
+ probe_avg_mag_sqrd_f_impl::set_threshold(double decibels)
+ {
+ // convert to absolute threshold (mag sqrd)
+ d_threshold = std::pow(10.0, decibels/10);
+ }
+
+ void
+ probe_avg_mag_sqrd_f_impl::set_alpha(double alpha)
+ {
+ d_iir.set_taps(alpha);
+ }
+
+ } /* namespace analog */
+} /* namespace gr */
+
diff --git a/gr-analog/lib/probe_avg_mag_sqrd_f_impl.h b/gr-analog/lib/probe_avg_mag_sqrd_f_impl.h
new file mode 100644
index 000000000..ba879763c
--- /dev/null
+++ b/gr-analog/lib/probe_avg_mag_sqrd_f_impl.h
@@ -0,0 +1,60 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,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_ANALOG_PROBE_AVG_MAG_SQRD_F_IMPL_H
+#define INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_F_IMPL_H
+
+#include <analog/probe_avg_mag_sqrd_f.h>
+#include <filter/single_pole_iir.h>
+
+namespace gr {
+ namespace analog {
+
+ class probe_avg_mag_sqrd_f_impl : public probe_avg_mag_sqrd_f
+ {
+ private:
+ double d_threshold;
+ bool d_unmuted;
+ double d_level;
+ filter::single_pole_iir<double,double,double> d_iir;
+
+ public:
+ probe_avg_mag_sqrd_f_impl(double threshold_db, double alpha);
+ ~probe_avg_mag_sqrd_f_impl();
+
+ bool unmuted() const { return d_unmuted; }
+ double level() const { return d_level; }
+
+ double threshold() const;
+
+ void set_alpha(double alpha);
+ void set_threshold(double decibels);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_F_IMPL_H */
diff --git a/gr-analog/python/qa_probe_avg_mag_sqrd.py b/gr-analog/python/qa_probe_avg_mag_sqrd.py
new file mode 100644
index 000000000..5c6c97e45
--- /dev/null
+++ b/gr-analog/python/qa_probe_avg_mag_sqrd.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+#
+# Copyright 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.
+#
+
+from gnuradio import gr, gr_unittest
+import analog_swig as analog
+import math
+
+def avg_mag_sqrd_c(x, alpha):
+ y = [0,]
+ for xi in x:
+ tmp = alpha*(xi.real*xi.real + xi.imag*xi.imag) + (1-alpha)*y[-1]
+ y.append(tmp)
+ return y
+
+def avg_mag_sqrd_f(x, alpha):
+ y = [0,]
+ for xi in x:
+ tmp = alpha*(xi*xi) + (1-alpha)*y[-1]
+ y.append(tmp)
+ return y
+
+class test_probe_avg_mag_sqrd(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_c_001(self):
+ alpha = 0.0001
+ src_data = [1.0+1.0j, 2.0+2.0j, 3.0+3.0j, 4.0+4.0j, 5.0+5.0j,
+ 6.0+6.0j, 7.0+7.0j, 8.0+8.0j, 9.0+9.0j, 10.0+10.0j]
+ expected_result = avg_mag_sqrd_c(src_data, alpha)[-1]
+
+ src = gr.vector_source_c(src_data)
+ op = analog.probe_avg_mag_sqrd_c(0, alpha)
+
+ self.tb.connect(src, op)
+ self.tb.run()
+
+ result_data = op.level()
+ self.assertAlmostEqual(expected_result, result_data, 5)
+
+ def test_cf_002(self):
+ alpha = 0.0001
+ src_data = [1.0+1.0j, 2.0+2.0j, 3.0+3.0j, 4.0+4.0j, 5.0+5.0j,
+ 6.0+6.0j, 7.0+7.0j, 8.0+8.0j, 9.0+9.0j, 10.0+10.0j]
+ expected_result = avg_mag_sqrd_c(src_data, alpha)[0:-1]
+
+ src = gr.vector_source_c(src_data)
+ op = analog.probe_avg_mag_sqrd_cf(0, alpha)
+ dst = gr.vector_sink_f()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ result_data = dst.data()
+ self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5)
+
+ def test_f_003(self):
+ alpha = 0.0001
+ src_data = [1.0, 2.0, 3.0, 4.0, 5.0,
+ 6.0, 7.0, 8.0, 9.0, 10.0]
+ expected_result = avg_mag_sqrd_f(src_data, alpha)[-1]
+
+ src = gr.vector_source_f(src_data)
+ op = analog.probe_avg_mag_sqrd_f(0, alpha)
+
+ self.tb.connect(src, op)
+ self.tb.run()
+
+ result_data = op.level()
+ self.assertAlmostEqual(expected_result, result_data, 5)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_probe_avg_mag_sqrd, "test_probe_avg_mag_sqrd.xml")
+
diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i
index b1bc61d5d..16f32ede7 100644
--- a/gr-analog/swig/analog_swig.i
+++ b/gr-analog/swig/analog_swig.i
@@ -47,6 +47,9 @@
#include "analog/pll_carriertracking_cc.h"
#include "analog/pll_freqdet_cf.h"
#include "analog/pll_refout_cc.h"
+#include "analog/probe_avg_mag_sqrd_c.h"
+#include "analog/probe_avg_mag_sqrd_cf.h"
+#include "analog/probe_avg_mag_sqrd_f.h"
#include "analog/squelch_base_cc.h"
#include "analog/squelch_base_ff.h"
%}
@@ -71,6 +74,9 @@
%include "analog/pll_carriertracking_cc.h"
%include "analog/pll_freqdet_cf.h"
%include "analog/pll_refout_cc.h"
+%include "analog/probe_avg_mag_sqrd_c.h"
+%include "analog/probe_avg_mag_sqrd_cf.h"
+%include "analog/probe_avg_mag_sqrd_f.h"
%include "analog/squelch_base_cc.h"
%include "analog/squelch_base_ff.h"
@@ -92,3 +98,6 @@ GR_SWIG_BLOCK_MAGIC2(analog, phase_modulator_fc);
GR_SWIG_BLOCK_MAGIC2(analog, pll_carriertracking_cc);
GR_SWIG_BLOCK_MAGIC2(analog, pll_freqdet_cf);
GR_SWIG_BLOCK_MAGIC2(analog, pll_refout_cc);
+GR_SWIG_BLOCK_MAGIC2(analog, probe_avg_mag_sqrd_c);
+GR_SWIG_BLOCK_MAGIC2(analog, probe_avg_mag_sqrd_cf);
+GR_SWIG_BLOCK_MAGIC2(analog, probe_avg_mag_sqrd_f);