diff options
Diffstat (limited to 'gr-blocks')
-rw-r--r-- | gr-blocks/grc/blocks_block_tree.xml | 1 | ||||
-rw-r--r-- | gr-blocks/grc/blocks_nlog10_ff.xml | 42 | ||||
-rw-r--r-- | gr-blocks/include/blocks/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/include/blocks/nlog10_ff.h | 55 | ||||
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/lib/nlog10_ff_impl.cc | 64 | ||||
-rw-r--r-- | gr-blocks/lib/nlog10_ff_impl.h | 49 | ||||
-rwxr-xr-x | gr-blocks/python/qa_nlog10.py | 48 | ||||
-rw-r--r-- | gr-blocks/swig/blocks_swig.i | 3 |
9 files changed, 264 insertions, 0 deletions
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 638fb5941..721a6d238 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -39,6 +39,7 @@ <block>blocks_sub_xx</block> <block>blocks_conjugate_cc</block> <block>blocks_integrate_xx</block> + <block>blocks_nlog10_ff</block> </cat> <cat> <name>Stream Type Conversions (New) </name> diff --git a/gr-blocks/grc/blocks_nlog10_ff.xml b/gr-blocks/grc/blocks_nlog10_ff.xml new file mode 100644 index 000000000..884f4a444 --- /dev/null +++ b/gr-blocks/grc/blocks_nlog10_ff.xml @@ -0,0 +1,42 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Log10 Block: +## float in/ float out +################################################### + --> +<block> + <name>Log10</name> + <key>blocks_nlog10_ff</key> + <import>from gnuradio import blocks</import> + <make>blocks.nlog10_ff($n, $vlen, $k)</make> + <param> + <name>n</name> + <key>n</key> + <value>1</value> + <type>real</type> + </param> + <param> + <name>k</name> + <key>k</key> + <value>0</value> + <type>real</type> + </param> + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <check>$vlen >= 1</check> + <sink> + <name>in</name> + <type>float</type> + <vlen>$vlen</vlen> + </sink> + <source> + <name>out</name> + <type>float</type> + <vlen>$vlen</vlen> + </source> +</block> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index f8e775397..b816544be 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -107,6 +107,7 @@ install(FILES multiply_conjugate_cc.h multiply_const_cc.h multiply_const_ff.h + nlog10_ff.h short_to_char.h short_to_float.h uchar_to_float.h diff --git a/gr-blocks/include/blocks/nlog10_ff.h b/gr-blocks/include/blocks/nlog10_ff.h new file mode 100644 index 000000000..cedd620fa --- /dev/null +++ b/gr-blocks/include/blocks/nlog10_ff.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifndef INCLUDED_BLOCKS_NLOG10_FF_H +#define INCLUDED_BLOCKS_NLOG10_FF_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief output = n*log10(input) + k + * \ingroup math_blk + */ + class BLOCKS_API nlog10_ff : virtual public gr_sync_block + { + public: + + // gr::blocks::nlog10_ff::sptr + typedef boost::shared_ptr<nlog10_ff> sptr; + + /*! + * \brief Make an instance of an nlog10_ff block. + * \param n Scalar multiplicative constant + * \param vlen Input vector length + * \param k Scalar additive constant + */ + static sptr make(float n=1.0, size_t vlen=1, float k=0.0); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_BLOCKS_NLOG10_FF_H */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index b73bf2994..cd07cef2f 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -144,6 +144,7 @@ list(APPEND gr_blocks_sources multiply_conjugate_cc_impl.cc multiply_const_cc_impl.cc multiply_const_ff_impl.cc + nlog10_ff_impl.cc short_to_char_impl.cc short_to_float_impl.cc uchar_array_to_float.cc diff --git a/gr-blocks/lib/nlog10_ff_impl.cc b/gr-blocks/lib/nlog10_ff_impl.cc new file mode 100644 index 000000000..f662b8fd5 --- /dev/null +++ b/gr-blocks/lib/nlog10_ff_impl.cc @@ -0,0 +1,64 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "nlog10_ff_impl.h" +#include <gr_io_signature.h> + +namespace gr { + namespace blocks { + + nlog10_ff::sptr nlog10_ff::make(float n, size_t vlen, float k) + { + return gnuradio::get_initial_sptr(new nlog10_ff_impl(n, vlen, k)); + } + + nlog10_ff_impl::nlog10_ff_impl(float n, size_t vlen, float k) + : gr_sync_block("nlog10_ff", + gr_make_io_signature (1, 1, sizeof(float)*vlen), + gr_make_io_signature (1, 1, sizeof(float)*vlen)), + d_n(n), d_vlen(vlen), d_k(k) + { + } + + int + nlog10_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]; + int noi = noutput_items * d_vlen; + float n = d_n; + float k = d_k; + + for (int i = 0; i < noi; i++) + out[i] = n * log10(std::max(in[i], (float) 1e-18)) + k; + + return noutput_items; + } + + } /* namespace blocks */ +}/* namespace gr */ diff --git a/gr-blocks/lib/nlog10_ff_impl.h b/gr-blocks/lib/nlog10_ff_impl.h new file mode 100644 index 000000000..3789bc317 --- /dev/null +++ b/gr-blocks/lib/nlog10_ff_impl.h @@ -0,0 +1,49 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifndef INCLUDED_NLOG10_FF_IMPL_H +#define INCLUDED_NLOG10_FF_IMPL_H + +#include <blocks/nlog10_ff.h> + +namespace gr { + namespace blocks { + + class BLOCKS_API nlog10_ff_impl : public nlog10_ff + { + float d_n; + size_t d_vlen; + float d_k; + + public: + nlog10_ff_impl(float n, size_t vlen, float k); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + + +#endif /* INCLUDED_NLOG10_FF_IMPL_H */ diff --git a/gr-blocks/python/qa_nlog10.py b/gr-blocks/python/qa_nlog10.py new file mode 100755 index 000000000..cc2a3e8cc --- /dev/null +++ b/gr-blocks/python/qa_nlog10.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# +# 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. +# + +from gnuradio import gr, gr_unittest +import blocks_swig + +class test_nlog10(gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001(self): + src_data = (-10, 0, 10, 100, 1000, 10000, 100000) + expected_result = (-180, -180, 10, 20, 30, 40, 50) + src = gr.vector_source_f(src_data) + op = blocks_swig.nlog10_ff(10) + dst = gr.vector_sink_f() + self.tb.connect (src, op, dst) + self.tb.run() + result_data = dst.data() + self.assertFloatTuplesAlmostEqual (expected_result, result_data) + + +if __name__ == '__main__': + gr_unittest.run(test_nlog10, "test_nlog10.xml") + diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index 43225a732..f70e536b2 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -78,6 +78,7 @@ #include "blocks/multiply_const_vii.h" #include "blocks/multiply_const_vff.h" #include "blocks/multiply_const_vcc.h" +#include "blocks/nlog10_ff.h" #include "blocks/short_to_char.h" #include "blocks/short_to_float.h" #include "blocks/sub_ff.h" @@ -137,6 +138,7 @@ %include "blocks/multiply_const_vii.h" %include "blocks/multiply_const_vff.h" %include "blocks/multiply_const_vcc.h" +%include "blocks/nlog10_ff.h" %include "blocks/short_to_char.h" %include "blocks/short_to_float.h" %include "blocks/sub_ff.h" @@ -195,6 +197,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vss); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vii); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vff); GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vcc); +GR_SWIG_BLOCK_MAGIC2(blocks, nlog10_ff); GR_SWIG_BLOCK_MAGIC2(blocks, short_to_char); GR_SWIG_BLOCK_MAGIC2(blocks, short_to_float); GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff); |