summaryrefslogtreecommitdiff
path: root/gr-analog
diff options
context:
space:
mode:
Diffstat (limited to 'gr-analog')
-rw-r--r--gr-analog/grc/analog_block_tree.xml3
-rw-r--r--gr-analog/grc/analog_pwr_squelch_xx.xml65
-rw-r--r--gr-analog/include/analog/CMakeLists.txt2
-rw-r--r--gr-analog/include/analog/pwr_squelch_cc.h75
-rw-r--r--gr-analog/include/analog/pwr_squelch_ff.h75
-rw-r--r--gr-analog/include/analog/squelch_base_cc.h2
-rw-r--r--gr-analog/lib/CMakeLists.txt2
-rw-r--r--gr-analog/lib/pwr_squelch_cc_impl.cc73
-rw-r--r--gr-analog/lib/pwr_squelch_cc_impl.h78
-rw-r--r--gr-analog/lib/pwr_squelch_ff_impl.cc73
-rw-r--r--gr-analog/lib/pwr_squelch_ff_impl.h78
-rwxr-xr-xgr-analog/python/qa_ctcss_squelch.py2
-rwxr-xr-xgr-analog/python/qa_pwr_squelch.py128
-rwxr-xr-xgr-analog/python/qa_simple_squelch.py3
-rw-r--r--gr-analog/swig/analog_swig.i6
15 files changed, 660 insertions, 5 deletions
diff --git a/gr-analog/grc/analog_block_tree.xml b/gr-analog/grc/analog_block_tree.xml
index 4cfcb9bc9..5c5680744 100644
--- a/gr-analog/grc/analog_block_tree.xml
+++ b/gr-analog/grc/analog_block_tree.xml
@@ -32,10 +32,11 @@
<name>Level Controls</name>
<block>analog_agc_xx</block>
<block>analog_agc2_xx</block>
+ <block>analog_dpll_bb</block>
<block>analog_feedforward_agc_cc</block>
<block>analog_ctcss_squelch_ff</block>
+ <block>analog_pwr_squelch_xx</block>
<block>analog_simple_squelch_cc</block>
- <block>analog_dpll_bb</block>
</cat>
<cat>
<name>Modulators</name>
diff --git a/gr-analog/grc/analog_pwr_squelch_xx.xml b/gr-analog/grc/analog_pwr_squelch_xx.xml
new file mode 100644
index 000000000..32d9c0e94
--- /dev/null
+++ b/gr-analog/grc/analog_pwr_squelch_xx.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Power Squelch
+###################################################
+ -->
+<block>
+ <name>Power Squelch</name>
+ <key>analog_pwr_squelch_xx</key>
+ <import>from gnuradio import analog</import>
+ <make>analog.pwr_squelch_$(type.fcn)($threshold, $alpha, $ramp, $gate)</make>
+ <callback>set_threshold($threshold)</callback>
+ <callback>set_alpha($alpha)</callback>
+ <param>
+ <name>Type</name>
+ <key>type</key>
+ <type>enum</type>
+ <option>
+ <name>Complex</name>
+ <key>complex</key>
+ <opt>fcn:cc</opt>
+ </option>
+ <option>
+ <name>Float</name>
+ <key>float</key>
+ <opt>fcn:ff</opt>
+ </option>
+ </param>
+ <param>
+ <name>Threshold (dB)</name>
+ <key>threshold</key>
+ <type>real</type>
+ </param>
+ <param>
+ <name>Alpha</name>
+ <key>alpha</key>
+ <type>real</type>
+ </param>
+ <param>
+ <name>Ramp</name>
+ <key>ramp</key>
+ <type>int</type>
+ </param>
+ <param>
+ <name>Gate</name>
+ <key>gate</key>
+ <type>enum</type>
+ <option>
+ <name>Yes</name>
+ <key>True</key>
+ </option>
+ <option>
+ <name>No</name>
+ <key>False</key>
+ </option>
+ </param>
+ <sink>
+ <name>in</name>
+ <type>$type</type>
+ </sink>
+ <source>
+ <name>out</name>
+ <type>$type</type>
+ </source>
+</block>
diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt
index 0d2944c3b..25ce50dd8 100644
--- a/gr-analog/include/analog/CMakeLists.txt
+++ b/gr-analog/include/analog/CMakeLists.txt
@@ -98,6 +98,8 @@ install(FILES
probe_avg_mag_sqrd_c.h
probe_avg_mag_sqrd_cf.h
probe_avg_mag_sqrd_f.h
+ pwr_squelch_cc.h
+ pwr_squelch_ff.h
rotator.h
sig_source_waveform.h
simple_squelch_cc.h
diff --git a/gr-analog/include/analog/pwr_squelch_cc.h b/gr-analog/include/analog/pwr_squelch_cc.h
new file mode 100644
index 000000000..79364a86b
--- /dev/null
+++ b/gr-analog/include/analog/pwr_squelch_cc.h
@@ -0,0 +1,75 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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_PWR_SQUELCH_CC_H
+#define INCLUDED_ANALOG_PWR_SQUELCH_CC_H
+
+#include <analog/api.h>
+#include <analog/squelch_base_cc.h>
+#include <cmath>
+
+namespace gr {
+ namespace analog {
+
+ /*!
+ * \brief gate or zero output when input power below threshold
+ * \ingroup level_blk
+ */
+ class ANALOG_API pwr_squelch_cc :
+ public squelch_base_cc, virtual public gr_block
+ {
+ protected:
+ virtual void update_state(const gr_complex &in) = 0;
+ virtual bool mute() const = 0;
+
+ public:
+ // gr::analog::pwr_squelch_cc::sptr
+ typedef boost::shared_ptr<pwr_squelch_cc> sptr;
+
+ /*!
+ * \brief Make power-based squelch block.
+ *
+ * \param db threshold (in dB) for power squelch
+ * \param alpha Gain of averaging filter
+ * \param ramp
+ * \param gate
+ */
+ static sptr make(double db, double alpha=0.0001,
+ int ramp=0, bool gate=false);
+
+ virtual std::vector<float> squelch_range() const = 0;
+
+ virtual double threshold() const = 0;
+ virtual void set_threshold(double db) = 0;
+ virtual void set_alpha(double alpha) = 0;
+
+ virtual int ramp() const = 0;
+ virtual void set_ramp(int ramp) = 0;
+ virtual bool gate() const = 0;
+ virtual void set_gate(bool gate) = 0;
+ virtual bool unmuted() const = 0;
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_PWR_SQUELCH_CC_H */
diff --git a/gr-analog/include/analog/pwr_squelch_ff.h b/gr-analog/include/analog/pwr_squelch_ff.h
new file mode 100644
index 000000000..6fdebec74
--- /dev/null
+++ b/gr-analog/include/analog/pwr_squelch_ff.h
@@ -0,0 +1,75 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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_PWR_SQUELCH_FF_H
+#define INCLUDED_ANALOG_PWR_SQUELCH_FF_H
+
+#include <analog/api.h>
+#include <analog/squelch_base_ff.h>
+#include <cmath>
+
+namespace gr {
+ namespace analog {
+
+ /*!
+ * \brief gate or zero output when input power below threshold
+ * \ingroup level_blk
+ */
+ class ANALOG_API pwr_squelch_ff :
+ public squelch_base_ff, virtual public gr_block
+ {
+ protected:
+ virtual void update_state(const float &in) = 0;
+ virtual bool mute() const = 0;
+
+ public:
+ // gr::analog::pwr_squelch_ff::sptr
+ typedef boost::shared_ptr<pwr_squelch_ff> sptr;
+
+ /*!
+ * \brief Make power-based squelch block.
+ *
+ * \param db threshold (in dB) for power squelch
+ * \param alpha Gain of averaging filter
+ * \param ramp
+ * \param gate
+ */
+ static sptr make(double db, double alpha=0.0001,
+ int ramp=0, bool gate=false);
+
+ virtual std::vector<float> squelch_range() const = 0;
+
+ virtual double threshold() const = 0;
+ virtual void set_threshold(double db) = 0;
+ virtual void set_alpha(double alpha) = 0;
+
+ virtual int ramp() const = 0;
+ virtual void set_ramp(int ramp) = 0;
+ virtual bool gate() const = 0;
+ virtual void set_gate(bool gate) = 0;
+ virtual bool unmuted() const = 0;
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_PWR_SQUELCH_FF_H */
diff --git a/gr-analog/include/analog/squelch_base_cc.h b/gr-analog/include/analog/squelch_base_cc.h
index 4c2a7b352..11476e7e8 100644
--- a/gr-analog/include/analog/squelch_base_cc.h
+++ b/gr-analog/include/analog/squelch_base_cc.h
@@ -36,7 +36,7 @@ namespace gr {
class ANALOG_API squelch_base_cc : virtual public gr_block
{
protected:
- virtual void update_state(const float &sample) = 0;
+ virtual void update_state(const gr_complex &sample) = 0;
virtual bool mute() const = 0;
public:
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt
index 0aed18405..9a620133a 100644
--- a/gr-analog/lib/CMakeLists.txt
+++ b/gr-analog/lib/CMakeLists.txt
@@ -126,6 +126,8 @@ 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
+ pwr_squelch_cc_impl.cc
+ pwr_squelch_ff_impl.cc
simple_squelch_cc_impl.cc
)
diff --git a/gr-analog/lib/pwr_squelch_cc_impl.cc b/gr-analog/lib/pwr_squelch_cc_impl.cc
new file mode 100644
index 000000000..1bfba6846
--- /dev/null
+++ b/gr-analog/lib/pwr_squelch_cc_impl.cc
@@ -0,0 +1,73 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006,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 "pwr_squelch_cc_impl.h"
+
+namespace gr {
+ namespace analog {
+
+ pwr_squelch_cc::sptr
+ pwr_squelch_cc::make(double threshold, double alpha,
+ int ramp, bool gate)
+ {
+ return gnuradio::get_initial_sptr
+ (new pwr_squelch_cc_impl(threshold, alpha, ramp, gate));
+ }
+
+ pwr_squelch_cc_impl::pwr_squelch_cc_impl(double threshold, double alpha,
+ int ramp, bool gate)
+ : gr_block("pwr_squelch_cc",
+ gr_make_io_signature(1, 1, sizeof(gr_complex)),
+ gr_make_io_signature(1, 1, sizeof(gr_complex))),
+ squelch_base_cc_impl("pwr_squelch_cc", ramp, gate),
+ d_iir(alpha)
+ {
+ set_threshold(threshold);
+ }
+
+ pwr_squelch_cc_impl::~pwr_squelch_cc_impl()
+ {
+ }
+
+ std::vector<float>
+ pwr_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;
+ }
+
+ void
+ pwr_squelch_cc_impl::update_state(const gr_complex &in)
+ {
+ d_pwr = d_iir.filter(in.real()*in.real()+in.imag()*in.imag());
+ }
+
+ } /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/pwr_squelch_cc_impl.h b/gr-analog/lib/pwr_squelch_cc_impl.h
new file mode 100644
index 000000000..72df0f3d2
--- /dev/null
+++ b/gr-analog/lib/pwr_squelch_cc_impl.h
@@ -0,0 +1,78 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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_PWR_SQUELCH_CC_IMPL_H
+#define INCLUDED_ANALOG_PWR_SQUELCH_CC_IMPL_H
+
+#include <analog/pwr_squelch_cc.h>
+#include "squelch_base_cc_impl.h"
+#include <filter/single_pole_iir.h>
+#include <cmath>
+
+namespace gr {
+ namespace analog {
+
+ class ANALOG_API pwr_squelch_cc_impl :
+ public pwr_squelch_cc, squelch_base_cc_impl
+ {
+ private:
+ double d_threshold;
+ double d_pwr;
+ filter::single_pole_iir<double,double,double> d_iir;
+
+ protected:
+ virtual void update_state(const gr_complex &in);
+ virtual bool mute() const { return d_pwr < d_threshold; }
+
+ public:
+ pwr_squelch_cc_impl(double db, double alpha=0.0001,
+ int ramp=0, bool gate=false);
+ ~pwr_squelch_cc_impl();
+
+ std::vector<float> squelch_range() const;
+
+ double threshold() const { return 10*log10(d_threshold); }
+ void set_threshold(double db) { d_threshold = std::pow(10.0, db/10); }
+ void set_alpha(double alpha) { d_iir.set_taps(alpha); }
+
+ int ramp() const { return squelch_base_cc_impl::ramp(); }
+ void set_ramp(int ramp) { squelch_base_cc_impl::set_ramp(ramp); }
+ bool gate() const { return squelch_base_cc_impl::gate(); }
+ void set_gate(bool gate) { squelch_base_cc_impl::set_gate(gate); }
+ bool unmuted() const { return squelch_base_cc_impl::unmuted(); }
+
+ int general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ return squelch_base_cc_impl::general_work(noutput_items,
+ ninput_items,
+ input_items,
+ output_items);
+ }
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_PWR_SQUELCH_CC_IMPL_H */
diff --git a/gr-analog/lib/pwr_squelch_ff_impl.cc b/gr-analog/lib/pwr_squelch_ff_impl.cc
new file mode 100644
index 000000000..c6bb6af90
--- /dev/null
+++ b/gr-analog/lib/pwr_squelch_ff_impl.cc
@@ -0,0 +1,73 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006,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 "pwr_squelch_ff_impl.h"
+
+namespace gr {
+ namespace analog {
+
+ pwr_squelch_ff::sptr
+ pwr_squelch_ff::make(double threshold, double alpha,
+ int ramp, bool gate)
+ {
+ return gnuradio::get_initial_sptr
+ (new pwr_squelch_ff_impl(threshold, alpha, ramp, gate));
+ }
+
+ pwr_squelch_ff_impl::pwr_squelch_ff_impl(double threshold, double alpha,
+ int ramp, bool gate)
+ : gr_block("pwr_squelch_ff",
+ gr_make_io_signature(1, 1, sizeof(float)),
+ gr_make_io_signature(1, 1, sizeof(float))),
+ squelch_base_ff_impl("pwr_squelch_ff", ramp, gate),
+ d_iir(alpha)
+ {
+ set_threshold(threshold);
+ }
+
+ pwr_squelch_ff_impl::~pwr_squelch_ff_impl()
+ {
+ }
+
+ std::vector<float>
+ pwr_squelch_ff_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;
+ }
+
+ void
+ pwr_squelch_ff_impl::update_state(const float &in)
+ {
+ d_pwr = d_iir.filter(in*in);
+ }
+
+ } /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/pwr_squelch_ff_impl.h b/gr-analog/lib/pwr_squelch_ff_impl.h
new file mode 100644
index 000000000..96d959b4d
--- /dev/null
+++ b/gr-analog/lib/pwr_squelch_ff_impl.h
@@ -0,0 +1,78 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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_PWR_SQUELCH_FF_IMPL_H
+#define INCLUDED_ANALOG_PWR_SQUELCH_FF_IMPL_H
+
+#include <analog/pwr_squelch_ff.h>
+#include "squelch_base_ff_impl.h"
+#include <filter/single_pole_iir.h>
+#include <cmath>
+
+namespace gr {
+ namespace analog {
+
+ class ANALOG_API pwr_squelch_ff_impl :
+ public pwr_squelch_ff, squelch_base_ff_impl
+ {
+ private:
+ double d_threshold;
+ double d_pwr;
+ filter::single_pole_iir<double,double,double> d_iir;
+
+ protected:
+ virtual void update_state(const float &in);
+ virtual bool mute() const { return d_pwr < d_threshold; }
+
+ public:
+ pwr_squelch_ff_impl(double db, double alpha=0.0001,
+ int ramp=0, bool gate=false);
+ ~pwr_squelch_ff_impl();
+
+ std::vector<float> squelch_range() const;
+
+ double threshold() const { return 10*log10(d_threshold); }
+ void set_threshold(double db) { d_threshold = std::pow(10.0, db/10); }
+ void set_alpha(double alpha) { d_iir.set_taps(alpha); }
+
+ int ramp() const { return squelch_base_ff_impl::ramp(); }
+ void set_ramp(int ramp) { squelch_base_ff_impl::set_ramp(ramp); }
+ bool gate() const { return squelch_base_ff_impl::gate(); }
+ void set_gate(bool gate) { squelch_base_ff_impl::set_gate(gate); }
+ bool unmuted() const { return squelch_base_ff_impl::unmuted(); }
+
+ int general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ return squelch_base_ff_impl::general_work(noutput_items,
+ ninput_items,
+ input_items,
+ output_items);
+ }
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_PWR_SQUELCH_FF_IMPL_H */
diff --git a/gr-analog/python/qa_ctcss_squelch.py b/gr-analog/python/qa_ctcss_squelch.py
index 4d4fc3077..08d3dbfef 100755
--- a/gr-analog/python/qa_ctcss_squelch.py
+++ b/gr-analog/python/qa_ctcss_squelch.py
@@ -49,7 +49,7 @@ class test_ctcss_squelch(gr_unittest.TestCase):
op.set_ramp(ramp2)
r = op.ramp()
- self.assertEqual(rate2, r)
+ self.assertEqual(ramp2, r)
op.set_gate(gate2)
g = op.gate()
diff --git a/gr-analog/python/qa_pwr_squelch.py b/gr-analog/python/qa_pwr_squelch.py
new file mode 100755
index 000000000..dd42c7fb9
--- /dev/null
+++ b/gr-analog/python/qa_pwr_squelch.py
@@ -0,0 +1,128 @@
+#!/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_pwr_squelch(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_pwr_squelch_001(self):
+ # Test set/gets
+
+ alpha = 0.0001
+
+ thr1 = 10
+ thr2 = 20
+ ramp = 1
+ ramp2 = 2
+ gate = True
+ gate2 = False
+
+ op = analog.pwr_squelch_cc(thr1, alpha, ramp, gate)
+
+ op.set_threshold(thr2)
+ t = op.threshold()
+ self.assertEqual(thr2, t)
+
+ op.set_ramp(ramp2)
+ r = op.ramp()
+ self.assertEqual(ramp2, r)
+
+ op.set_gate(gate2)
+ g = op.gate()
+ self.assertEqual(gate2, g)
+
+ def test_pwr_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.pwr_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.assertComplexTuplesAlmostEqual(expected_result, result_data, 4)
+
+ def test_pwr_squelch_003(self):
+ # Test set/gets
+
+ alpha = 0.0001
+
+ thr1 = 10
+ thr2 = 20
+ ramp = 1
+ ramp2 = 2
+ gate = True
+ gate2 = False
+
+ op = analog.pwr_squelch_ff(thr1, alpha, ramp, gate)
+
+ op.set_threshold(thr2)
+ t = op.threshold()
+ self.assertEqual(thr2, t)
+
+ op.set_ramp(ramp2)
+ r = op.ramp()
+ self.assertEqual(ramp2, r)
+
+ op.set_gate(gate2)
+ g = op.gate()
+ self.assertEqual(gate2, g)
+
+
+ def test_pwr_squelch_004(self):
+ alpha = 0.0001
+ thr = -25
+
+ src_data = map(lambda x: float(x)/10.0, range(1, 40))
+ src = gr.vector_source_f(src_data)
+ op = analog.pwr_squelch_ff(thr, alpha)
+ dst = gr.vector_sink_f()
+
+ 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_pwr_squelch, "test_pwr_squelch.xml")
+
diff --git a/gr-analog/python/qa_simple_squelch.py b/gr-analog/python/qa_simple_squelch.py
index 97deee06c..9fa112864 100755
--- a/gr-analog/python/qa_simple_squelch.py
+++ b/gr-analog/python/qa_simple_squelch.py
@@ -46,7 +46,6 @@ class test_simple_squelch(gr_unittest.TestCase):
self.assertEqual(thr2, t)
def test_simple_squelch_002(self):
- # Test runtime, gate=True
alpha = 0.0001
thr = -25
@@ -63,7 +62,7 @@ class test_simple_squelch(gr_unittest.TestCase):
expected_result[0:20] = 20*[0,]
result_data = dst.data()
- self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4)
+ self.assertComplexTuplesAlmostEqual(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 2e36e4e71..38063c132 100644
--- a/gr-analog/swig/analog_swig.i
+++ b/gr-analog/swig/analog_swig.i
@@ -52,6 +52,8 @@
#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/pwr_squelch_cc.h"
+#include "analog/pwr_squelch_ff.h"
#include "analog/sincos.h"
#include "analog/sig_source_s.h"
#include "analog/sig_source_i.h"
@@ -87,6 +89,8 @@
%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/pwr_squelch_cc.h"
+%include "analog/pwr_squelch_ff.h"
%include "analog/sincos.h"
%include "analog/sig_source_s.h"
%include "analog/sig_source_i.h"
@@ -118,6 +122,8 @@ 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);
+GR_SWIG_BLOCK_MAGIC2(analog, pwr_squelch_cc);
+GR_SWIG_BLOCK_MAGIC2(analog, pwr_squelch_ff);
GR_SWIG_BLOCK_MAGIC2(analog, sig_source_s);
GR_SWIG_BLOCK_MAGIC2(analog, sig_source_i);
GR_SWIG_BLOCK_MAGIC2(analog, sig_source_f);