diff options
-rw-r--r-- | gr-analog/grc/analog_block_tree.xml | 1 | ||||
-rw-r--r-- | gr-analog/grc/analog_rail_ff.xml | 54 | ||||
-rw-r--r-- | gr-analog/include/analog/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-analog/include/analog/rail_ff.h | 54 | ||||
-rw-r--r-- | gr-analog/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-analog/lib/rail_ff_impl.cc | 91 | ||||
-rw-r--r-- | gr-analog/lib/rail_ff_impl.h | 57 | ||||
-rwxr-xr-x | gr-analog/python/qa_rail_ff.py | 79 | ||||
-rw-r--r-- | gr-analog/swig/analog_swig.i | 3 |
9 files changed, 341 insertions, 0 deletions
diff --git a/gr-analog/grc/analog_block_tree.xml b/gr-analog/grc/analog_block_tree.xml index 5c5680744..a25123f4a 100644 --- a/gr-analog/grc/analog_block_tree.xml +++ b/gr-analog/grc/analog_block_tree.xml @@ -37,6 +37,7 @@ <block>analog_ctcss_squelch_ff</block> <block>analog_pwr_squelch_xx</block> <block>analog_simple_squelch_cc</block> + <block>analog_rail_ff</block> </cat> <cat> <name>Modulators</name> diff --git a/gr-analog/grc/analog_rail_ff.xml b/gr-analog/grc/analog_rail_ff.xml new file mode 100644 index 000000000..87dff0977 --- /dev/null +++ b/gr-analog/grc/analog_rail_ff.xml @@ -0,0 +1,54 @@ +<?xml version="1.0"?> +<!-- +# +# 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. +--> + +<!-- +################################################### +##Rail +################################################### + --> +<block> + <name>Rail</name> + <key>analog_rail_ff</key> + <import>from gnuradio import analog</import> + <make>analog.rail_ff($lo, $hi)</make> + <callback>set_lo($lo)</callback> + <callback>set_hi($hi)</callback> + <param> + <name>Low clipping</name> + <key>lo</key> + <type>real</type> + </param> + <param> + <name>Hi clipping</name> + <key>hi</key> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>float</type> + </sink> + <source> + <name>out</name> + <type>float</type> + </source> +</block> diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt index 25ce50dd8..4623fb2dd 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 pwr_squelch_cc.h pwr_squelch_ff.h + rail_ff.h rotator.h sig_source_waveform.h simple_squelch_cc.h diff --git a/gr-analog/include/analog/rail_ff.h b/gr-analog/include/analog/rail_ff.h new file mode 100644 index 000000000..e51b2fc93 --- /dev/null +++ b/gr-analog/include/analog/rail_ff.h @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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_RAIL_FF_H +#define INCLUDED_ANALOG_RAIL_FF_H + +#include <analog/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace analog { + + /*! + * \brief clips input values to min, max + * \ingroup misc + */ + class ANALOG_API rail_ff : virtual public gr_sync_block + { + public: + // gr::analog::rail_ff::sptr + typedef boost::shared_ptr<rail_ff> sptr; + + static sptr make(float lo, float hi); + + virtual float lo() const = 0; + virtual float hi() const = 0; + + virtual void set_lo(float lo) = 0; + virtual void set_hi(float hi) = 0; + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_RAIL_FF_H */ diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt index 9a620133a..f912649d9 100644 --- a/gr-analog/lib/CMakeLists.txt +++ b/gr-analog/lib/CMakeLists.txt @@ -128,6 +128,7 @@ list(APPEND analog_sources probe_avg_mag_sqrd_f_impl.cc pwr_squelch_cc_impl.cc pwr_squelch_ff_impl.cc + rail_ff_impl.cc simple_squelch_cc_impl.cc ) diff --git a/gr-analog/lib/rail_ff_impl.cc b/gr-analog/lib/rail_ff_impl.cc new file mode 100644 index 000000000..106c6353a --- /dev/null +++ b/gr-analog/lib/rail_ff_impl.cc @@ -0,0 +1,91 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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 "rail_ff_impl.h" +#include <gr_io_signature.h> +#include <gr_math.h> + +namespace gr { + namespace analog { + + rail_ff::sptr + rail_ff::make(float lo, float hi) + { + return gnuradio::get_initial_sptr + (new rail_ff_impl(lo, hi)); + } + + rail_ff_impl::rail_ff_impl(float lo, float hi) + : gr_sync_block("rail_ff", + gr_make_io_signature(1, 1, sizeof(float)), + gr_make_io_signature(1, 1, sizeof(float))), + d_lo(lo), d_hi(hi) + { + set_clipping(); + } + + rail_ff_impl::~rail_ff_impl() + { + } + + void + rail_ff_impl::set_lo(float lo) + { + d_lo = lo; + set_clipping(); + } + + void + rail_ff_impl::set_hi(float hi) + { + d_hi = hi; + set_clipping(); + } + + void + rail_ff_impl::set_clipping() + { + d_mid = (d_lo + d_hi)/2; + d_clip = d_hi - d_mid; + } + + int + rail_ff_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]; + float *out = (float*)output_items[0]; + + for(int i = 0; i < noutput_items; i++) { + out[i] = d_mid + gr_branchless_clip(in[i] - d_mid, d_clip); + } + + return noutput_items; + } + + } /* namespace analog */ +} /* namespace gr */ diff --git a/gr-analog/lib/rail_ff_impl.h b/gr-analog/lib/rail_ff_impl.h new file mode 100644 index 000000000..436b10b41 --- /dev/null +++ b/gr-analog/lib/rail_ff_impl.h @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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_RAIL_FF_IMPL_H +#define INCLUDED_ANALOG_RAIL_FF_IMPL_H + +#include <analog/rail_ff.h> + +namespace gr { + namespace analog { + + class rail_ff_impl : public rail_ff + { + private: + float d_lo, d_hi; + float d_mid, d_clip; + + void set_clipping(); + + public: + rail_ff_impl(float lo, float hi); + ~rail_ff_impl(); + + float lo() const { return d_lo; } + float hi() const { return d_hi; } + + void set_lo(float lo); + void set_hi(float hi); + + 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_RAIL_FF_IMPL_H */ diff --git a/gr-analog/python/qa_rail_ff.py b/gr-analog/python/qa_rail_ff.py new file mode 100755 index 000000000..5bcf01c6b --- /dev/null +++ b/gr-analog/python/qa_rail_ff.py @@ -0,0 +1,79 @@ +#!/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 + +def clip(x, lo, hi): + if(x < lo): + return lo + elif(x > hi): + return hi + else: + return x + +class test_rail(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_rail_001(self): + # Test set/gets + + hi1 = 1 + hi2 = 2 + lo1 = -1 + lo2 = -2 + + op = analog.rail_ff(lo1, hi1) + + op.set_hi(hi2) + h = op.hi() + self.assertEqual(hi2, h) + + op.set_lo(lo2) + l = op.lo() + self.assertEqual(lo2, l) + + def test_rail_002(self): + lo = -0.75 + hi = 0.90 + src_data = [-2, -1, -0.5, -0.25, 0, 0.25, 0.5, 1, 2] + expected_result = map(lambda x: clip(x, lo, hi), src_data) + + src = gr.vector_source_f(src_data) + op = analog.rail_ff(lo, hi) + dst = gr.vector_sink_f() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + result_data = dst.data() + self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4) + +if __name__ == '__main__': + gr_unittest.run(test_rail, "test_rail.xml") + diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i index 38063c132..9632b363c 100644 --- a/gr-analog/swig/analog_swig.i +++ b/gr-analog/swig/analog_swig.i @@ -54,6 +54,7 @@ #include "analog/probe_avg_mag_sqrd_f.h" #include "analog/pwr_squelch_cc.h" #include "analog/pwr_squelch_ff.h" +#include "analog/rail_ff.h" #include "analog/sincos.h" #include "analog/sig_source_s.h" #include "analog/sig_source_i.h" @@ -91,6 +92,7 @@ %include "analog/probe_avg_mag_sqrd_f.h" %include "analog/pwr_squelch_cc.h" %include "analog/pwr_squelch_ff.h" +%include "analog/rail_ff.h" %include "analog/sincos.h" %include "analog/sig_source_s.h" %include "analog/sig_source_i.h" @@ -124,6 +126,7 @@ 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, rail_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); |