summaryrefslogtreecommitdiff
path: root/gr-analog
diff options
context:
space:
mode:
authorTom Rondeau2012-10-31 11:42:07 -0400
committerTom Rondeau2012-10-31 11:42:07 -0400
commit54e947e394dcd2bbff2b49968adf7b0861f0851b (patch)
treea1d5d78934e80fce7e2877977cf124f7f484f201 /gr-analog
parent0353e0b56734c62884c7fd6d3634a28bafbae74f (diff)
downloadgnuradio-54e947e394dcd2bbff2b49968adf7b0861f0851b.tar.gz
gnuradio-54e947e394dcd2bbff2b49968adf7b0861f0851b.tar.bz2
gnuradio-54e947e394dcd2bbff2b49968adf7b0861f0851b.zip
analog: adding simple_squelch block to gr-analog with QA and GRC.
Diffstat (limited to 'gr-analog')
-rw-r--r--gr-analog/grc/analog_block_tree.xml1
-rw-r--r--gr-analog/grc/analog_simple_squelch_cc.xml32
-rw-r--r--gr-analog/include/analog/CMakeLists.txt1
-rw-r--r--gr-analog/include/analog/simple_squelch_cc.h62
-rw-r--r--gr-analog/lib/CMakeLists.txt1
-rw-r--r--gr-analog/lib/simple_squelch_cc_impl.cc106
-rw-r--r--gr-analog/lib/simple_squelch_cc_impl.h59
-rwxr-xr-xgr-analog/python/qa_simple_squelch.py70
-rw-r--r--gr-analog/swig/analog_swig.i3
9 files changed, 335 insertions, 0 deletions
diff --git a/gr-analog/grc/analog_block_tree.xml b/gr-analog/grc/analog_block_tree.xml
index 5043e9562..4cfcb9bc9 100644
--- a/gr-analog/grc/analog_block_tree.xml
+++ b/gr-analog/grc/analog_block_tree.xml
@@ -34,6 +34,7 @@
<block>analog_agc2_xx</block>
<block>analog_feedforward_agc_cc</block>
<block>analog_ctcss_squelch_ff</block>
+ <block>analog_simple_squelch_cc</block>
<block>analog_dpll_bb</block>
</cat>
<cat>
diff --git a/gr-analog/grc/analog_simple_squelch_cc.xml b/gr-analog/grc/analog_simple_squelch_cc.xml
new file mode 100644
index 000000000..648921a14
--- /dev/null
+++ b/gr-analog/grc/analog_simple_squelch_cc.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Simple Squelch
+###################################################
+ -->
+<block>
+ <name>Simple Squelch</name>
+ <key>analog_simple_squelch_cc</key>
+ <import>from gnuradio import analog</import>
+ <make>analog.simple_squelch_cc($threshold, $alpha)</make>
+ <callback>set_threshold($threshold)</callback>
+ <callback>set_alpha($alpha)</callback>
+ <param>
+ <name>Threshold (dB)</name>
+ <key>threshold</key>
+ <type>real</type>
+ </param>
+ <param>
+ <name>Alpha</name>
+ <key>alpha</key>
+ <type>real</type>
+ </param>
+ <sink>
+ <name>in</name>
+ <type>complex</type>
+ </sink>
+ <source>
+ <name>out</name>
+ <type>complex</type>
+ </source>
+</block>
diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt
index 99839449b..0d2944c3b 100644
--- a/gr-analog/include/analog/CMakeLists.txt
+++ b/gr-analog/include/analog/CMakeLists.txt
@@ -100,6 +100,7 @@ install(FILES
probe_avg_mag_sqrd_f.h
rotator.h
sig_source_waveform.h
+ simple_squelch_cc.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/analog
COMPONENT "analog_devel"
)
diff --git a/gr-analog/include/analog/simple_squelch_cc.h b/gr-analog/include/analog/simple_squelch_cc.h
new file mode 100644
index 000000000..1e12646e4
--- /dev/null
+++ b/gr-analog/include/analog/simple_squelch_cc.h
@@ -0,0 +1,62 @@
+/* -*- 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_SIMPLE_SQUELCH_CC_H
+#define INCLUDED_ANALOG_SIMPLE_SQUELCH_CC_H
+
+#include <analog/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace analog {
+
+ /*!
+ * \brief simple squelch block based on average signal power and threshold in dB.
+ * \ingroup level_blk
+ */
+ class ANALOG_API simple_squelch_cc : virtual public gr_sync_block
+ {
+ public:
+ // gr::analog::simple_squelch_cc::sptr
+ typedef boost::shared_ptr<simple_squelch_cc> sptr;
+
+ /*!
+ * \brief Make a simple squelch block.
+ *
+ * \param threshold_db Threshold for muting.
+ * \param alpha Gain parameter for the running average filter.
+ */
+ static sptr make(double threshold_db, double alpha);
+
+ virtual bool unmuted() const = 0;
+
+ virtual void set_alpha(double alpha) = 0;
+ virtual void set_threshold(double decibels) = 0;
+
+ virtual double threshold() const = 0;
+ virtual std::vector<float> squelch_range() const = 0;
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_SIMPLE_SQUELCH_CC_H */
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt
index 6b64c019d..0aed18405 100644
--- a/gr-analog/lib/CMakeLists.txt
+++ b/gr-analog/lib/CMakeLists.txt
@@ -126,6 +126,7 @@ list(APPEND analog_sources
probe_avg_mag_sqrd_c_impl.cc
probe_avg_mag_sqrd_cf_impl.cc
probe_avg_mag_sqrd_f_impl.cc
+ simple_squelch_cc_impl.cc
)
list(APPEND analog_libs
diff --git a/gr-analog/lib/simple_squelch_cc_impl.cc b/gr-analog/lib/simple_squelch_cc_impl.cc
new file mode 100644
index 000000000..02ccc535d
--- /dev/null
+++ b/gr-analog/lib/simple_squelch_cc_impl.cc
@@ -0,0 +1,106 @@
+/* -*- 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 "simple_squelch_cc_impl.h"
+#include <gr_io_signature.h>
+#include <cmath>
+
+namespace gr {
+ namespace analog {
+
+ simple_squelch_cc::sptr
+ simple_squelch_cc::make(double threshold_db, double alpha)
+ {
+ return gnuradio::get_initial_sptr
+ (new simple_squelch_cc_impl(threshold_db, alpha));
+ }
+
+ simple_squelch_cc_impl::simple_squelch_cc_impl(double threshold_db, double alpha)
+ : gr_sync_block("simple_squelch_cc",
+ gr_make_io_signature(1, 1, sizeof(gr_complex)),
+ gr_make_io_signature(1, 1, sizeof(gr_complex))),
+ d_unmuted(false), d_iir(alpha)
+ {
+ set_threshold(threshold_db);
+ }
+
+ simple_squelch_cc_impl::~simple_squelch_cc_impl()
+ {
+ }
+
+ void
+ simple_squelch_cc_impl::set_threshold(double decibels)
+ {
+ // convert to absolute threshold (mag squared)
+ d_threshold = std::pow(10.0, decibels/10);
+ }
+
+ double
+ simple_squelch_cc_impl::threshold() const
+ {
+ return 10 * log10(d_threshold);
+ }
+
+ void
+ simple_squelch_cc_impl::set_alpha(double alpha)
+ {
+ d_iir.set_taps(alpha);
+ }
+
+ std::vector<float>
+ simple_squelch_cc_impl::squelch_range() const
+ {
+ std::vector<float> r(3);
+ r[0] = -50.0; // min FIXME
+ r[1] = +50.0; // max FIXME
+ r[2] = (r[1] - r[0]) / 100; // step size
+
+ return r;
+ }
+
+ int
+ simple_squelch_cc_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];
+ gr_complex *out = (gr_complex*)output_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();
+ double f = d_iir.filter(mag_sqrd);
+ if(f >= d_threshold)
+ out[i] = in[i];
+ else
+ out[i] = 0;
+ }
+
+ d_unmuted = d_iir.prev_output() >= d_threshold;
+ return noutput_items;
+ }
+
+ } /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/simple_squelch_cc_impl.h b/gr-analog/lib/simple_squelch_cc_impl.h
new file mode 100644
index 000000000..ba11de91e
--- /dev/null
+++ b/gr-analog/lib/simple_squelch_cc_impl.h
@@ -0,0 +1,59 @@
+/* -*- 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_SIMPLE_SQUELCH_CC_IMPL_H
+#define INCLUDED_ANALOG_SIMPLE_SQUELCH_CC_IMPL_H
+
+#include <analog/simple_squelch_cc.h>
+#include <filter/single_pole_iir.h>
+
+namespace gr {
+ namespace analog {
+
+ class simple_squelch_cc_impl : public simple_squelch_cc
+ {
+ private:
+ double d_threshold;
+ bool d_unmuted;
+ filter::single_pole_iir<double,double,double> d_iir;
+
+ public:
+ simple_squelch_cc_impl(double threshold_db, double alpha);
+ ~simple_squelch_cc_impl();
+
+ bool unmuted() const { return d_unmuted; }
+
+ void set_alpha(double alpha);
+ void set_threshold(double decibels);
+
+ double threshold() const;
+ std::vector<float> squelch_range() const;
+
+ 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_SIMPLE_SQUELCH_CC_IMPL_H */
diff --git a/gr-analog/python/qa_simple_squelch.py b/gr-analog/python/qa_simple_squelch.py
new file mode 100755
index 000000000..97deee06c
--- /dev/null
+++ b/gr-analog/python/qa_simple_squelch.py
@@ -0,0 +1,70 @@
+#!/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
+
+class test_simple_squelch(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_simple_squelch_001(self):
+ # Test set/gets
+
+ alpha = 0.0001
+
+ thr1 = 10
+ thr2 = 20
+
+ op = analog.simple_squelch_cc(thr1, alpha)
+
+ op.set_threshold(thr2)
+ t = op.threshold()
+ self.assertEqual(thr2, t)
+
+ def test_simple_squelch_002(self):
+ # Test runtime, gate=True
+ alpha = 0.0001
+ thr = -25
+
+ src_data = map(lambda x: float(x)/10.0, range(1, 40))
+ src = gr.vector_source_c(src_data)
+ op = analog.simple_squelch_cc(thr, alpha)
+ dst = gr.vector_sink_c()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ expected_result = src_data
+ expected_result[0:20] = 20*[0,]
+
+ result_data = dst.data()
+ self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_simple_squelch, "test_simple_squelch.xml")
+
diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i
index f23fa6d00..2e36e4e71 100644
--- a/gr-analog/swig/analog_swig.i
+++ b/gr-analog/swig/analog_swig.i
@@ -58,6 +58,7 @@
#include "analog/sig_source_f.h"
#include "analog/sig_source_c.h"
#include "analog/sig_source_waveform.h"
+#include "analog/simple_squelch_cc.h"
#include "analog/squelch_base_cc.h"
#include "analog/squelch_base_ff.h"
%}
@@ -92,6 +93,7 @@
%include "analog/sig_source_f.h"
%include "analog/sig_source_c.h"
%include "analog/sig_source_waveform.h"
+%include "analog/simple_squelch_cc.h"
%include "analog/squelch_base_cc.h"
%include "analog/squelch_base_ff.h"
@@ -120,3 +122,4 @@ GR_SWIG_BLOCK_MAGIC2(analog, sig_source_s);
GR_SWIG_BLOCK_MAGIC2(analog, sig_source_i);
GR_SWIG_BLOCK_MAGIC2(analog, sig_source_f);
GR_SWIG_BLOCK_MAGIC2(analog, sig_source_c);
+GR_SWIG_BLOCK_MAGIC2(analog, simple_squelch_cc);