diff options
author | Tom Rondeau <trondeau@vt.edu> | 2013-03-18 17:41:12 -0400 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2013-03-18 17:41:12 -0400 |
commit | 644459b0c55987792df3a7b884ace1d0250231f1 (patch) | |
tree | ded5c662890dbccd28b8400aecfa5933600f9520 | |
parent | 04682315bf151fb2c7c24673676cd8e07ab5fe2e (diff) | |
parent | e0236f2bf8eb4a069736d69808432348140e576f (diff) |
Merge branch 'master' into next
Conflicts:
gr-blocks/include/blocks/CMakeLists.txt
gr-blocks/lib/CMakeLists.txt
gr-blocks/swig/blocks_swig.i
gr-digital/lib/digital_ofdm_sync_sc_cfb.cc
-rw-r--r-- | gr-analog/grc/analog_block_tree.xml | 1 | ||||
-rw-r--r-- | gr-blocks/grc/blocks_block_tree.xml | 1 | ||||
-rw-r--r-- | gr-blocks/grc/blocks_plateau_detector_fb.xml | 26 | ||||
-rw-r--r-- | gr-blocks/include/blocks/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/include/blocks/plateau_detector_fb.h | 71 | ||||
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/lib/plateau_detector_fb_impl.cc | 83 | ||||
-rw-r--r-- | gr-blocks/lib/plateau_detector_fb_impl.h | 50 | ||||
-rwxr-xr-x | gr-blocks/python/qa_plateau_detector_fb.py | 46 | ||||
-rw-r--r-- | gr-blocks/swig/blocks_swig.i | 3 |
10 files changed, 282 insertions, 1 deletions
diff --git a/gr-analog/grc/analog_block_tree.xml b/gr-analog/grc/analog_block_tree.xml index fdb6db27ac..0a01d38cd8 100644 --- a/gr-analog/grc/analog_block_tree.xml +++ b/gr-analog/grc/analog_block_tree.xml @@ -67,7 +67,6 @@ <block>analog_pll_carriertracking_cc</block> <block>analog_pll_freqdet_cf</block> <block>analog_pll_refout_cc</block> - <block>analog_plateau_detector_fb</block> </cat> <cat> <name>Probes</name> diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index face908df0..0cd4ac434f 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -123,6 +123,7 @@ <block>blocks_stream_to_vector_decimator</block> <block>blocks_peak_detector_xb</block> <block>blocks_peak_detector2_fb</block> + <block>blocks_plateau_detector_fb</block> <block>blocks_regenerate_bb</block> <block>blocks_stretch_ff</block> <block>blocks_threshold_ff</block> diff --git a/gr-blocks/grc/blocks_plateau_detector_fb.xml b/gr-blocks/grc/blocks_plateau_detector_fb.xml new file mode 100644 index 0000000000..e06c3fe306 --- /dev/null +++ b/gr-blocks/grc/blocks_plateau_detector_fb.xml @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<block> + <name>Plateau Detector</name> + <key>blocks_plateau_detector_fb</key> + <import>from gnuradio import blocks</import> + <make>blocks.plateau_detector_fb($max_len, $threshold)</make> + <param> + <name>Max. plateau length</name> + <key>max_len</key> + <type>int</type> + </param> + <param> + <name>Threshold</name> + <key>threshold</key> + <value>0.9</value> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>real</type> + </sink> + <source> + <name>out</name> + <type>byte</type> + </source> +</block> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index a88eaeeb26..edad5ef526 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -165,6 +165,7 @@ install(FILES pdu_to_tagged_stream.h peak_detector2_fb.h random_pdu.h + plateau_detector_fb.h probe_rate.h regenerate_bb.h repack_bits_bb.h diff --git a/gr-blocks/include/blocks/plateau_detector_fb.h b/gr-blocks/include/blocks/plateau_detector_fb.h new file mode 100644 index 0000000000..041f9c1baf --- /dev/null +++ b/gr-blocks/include/blocks/plateau_detector_fb.h @@ -0,0 +1,71 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-2013 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_PLATEAU_DETECTOR_FB_H +#define INCLUDED_BLOCKS_PLATEAU_DETECTOR_FB_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Detects a plateau and marks the middle. + * + * Detect a plateau of a-priori known height. Input is a stream of floats, + * the output is a stream of bytes. Whenever a plateau is detected, the + * middle of that plateau is marked with a '1' on the output stream (all + * other samples are left at zero). + * + * You can use this in a Schmidl & Cox synchronisation algorithm to interpret + * the output of the normalized correlator. Just pass the length of the cyclic + * prefix (in samples) as the max_len parameter). + * + * Unlike the peak detectors, you must the now the absolute height of the plateau. + * Whenever the amplitude exceeds the given threshold, it starts assuming the + * presence of a plateau. + * + * An implicit hysteresis is provided by the fact that after detecting one plateau, + * it waits at least max_len samples before the next plateau can be detected. + * + * \ingroup level_blk + * + */ + class BLOCKS_API plateau_detector_fb : virtual public gr_sync_block + { + public: + typedef boost::shared_ptr<plateau_detector_fb> sptr; + + /*! + * \param max_len Maximum length of the plateau + * \param threshold Anything above this value is considered a plateau + */ + static sptr make(int max_len, float threshold=0.9); + }; + + } // namespace blocks +} // namespace gr + +#endif /* INCLUDED_BLOCKS_PLATEAU_DETECTOR_FB_H */ + diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index ae3523945e..bbc83ad281 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -211,6 +211,7 @@ list(APPEND gr_blocks_sources pdu_to_tagged_stream_impl.cc peak_detector2_fb_impl.cc random_pdu_impl.cc + plateau_detector_fb_impl.cc probe_rate_impl.cc regenerate_bb_impl.cc repack_bits_bb_impl.cc diff --git a/gr-blocks/lib/plateau_detector_fb_impl.cc b/gr-blocks/lib/plateau_detector_fb_impl.cc new file mode 100644 index 0000000000..f68ef6463f --- /dev/null +++ b/gr-blocks/lib/plateau_detector_fb_impl.cc @@ -0,0 +1,83 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-2013 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 <gr_io_signature.h> +#include "plateau_detector_fb_impl.h" + +namespace gr { + namespace blocks { + + plateau_detector_fb::sptr + plateau_detector_fb::make(int max_len, float threshold) + { + return gnuradio::get_initial_sptr + (new plateau_detector_fb_impl(max_len, threshold)); + } + + plateau_detector_fb_impl::plateau_detector_fb_impl(int max_len, float threshold) + : gr_sync_block("plateau_detector_fb", + gr_make_io_signature(1, 1, sizeof(float)), + gr_make_io_signature(1, 1, sizeof(char))), + d_max_len(max_len), + d_threshold(threshold) + {} + + plateau_detector_fb_impl::~plateau_detector_fb_impl() + { + } + + int + plateau_detector_fb_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]; + unsigned char *out = (unsigned char *) output_items[0]; + int flank_start; + + memset((void *) out, 0x00, noutput_items); + int i; + for(i = 0; i < noutput_items; i++) { + if(in[i] >= d_threshold) { + if(noutput_items-i < 2*d_max_len) { // If we can't finish, come back later + break; + } + flank_start = i; + while(i < noutput_items && in[i] >= d_threshold) + i++; + if((i - flank_start) > 1) { // 1 Sample is not a plateau + out[flank_start + (i-flank_start)/2] = 1; + i = std::min(i+d_max_len, noutput_items-1); + } + } + } + + return i; + } + + } /* namespace blocks */ +} /* namespace gr */ + diff --git a/gr-blocks/lib/plateau_detector_fb_impl.h b/gr-blocks/lib/plateau_detector_fb_impl.h new file mode 100644 index 0000000000..67682d00f3 --- /dev/null +++ b/gr-blocks/lib/plateau_detector_fb_impl.h @@ -0,0 +1,50 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012-2013 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_PLATEAU_DETECTOR_FB_IMPL_H +#define INCLUDED_BLOCKS_PLATEAU_DETECTOR_FB_IMPL_H + +#include <blocks/plateau_detector_fb.h> + +namespace gr { + namespace blocks { + +class plateau_detector_fb_impl : public plateau_detector_fb +{ + private: + int d_max_len; + float d_threshold; + + public: + plateau_detector_fb_impl(int max_len, float threshold); + ~plateau_detector_fb_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + + } // namespace blocks +} // namespace gr + +#endif /* INCLUDED_BLOCKS_PLATEAU_DETECTOR_FB_IMPL_H */ + diff --git a/gr-blocks/python/qa_plateau_detector_fb.py b/gr-blocks/python/qa_plateau_detector_fb.py new file mode 100755 index 0000000000..e45fe028dd --- /dev/null +++ b/gr-blocks/python/qa_plateau_detector_fb.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# +# Copyright 2012-2013 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 as blocks + +class qa_plateau_detector_fb (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001_t (self): + # | Spur spike 1 | Plateau | Spur spike 2 + test_signal = (0, 1, .2, .4, .6, .8, 1, 1, 1, 1, 1, .8, .6, .4, 1, 0) + expected_sig = (0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0) + # | Center of Plateau + sink = gr.vector_sink_b() + self.tb.connect(gr.vector_source_f(test_signal), blocks.plateau_detector_fb(5), sink) + self.tb.run () + self.assertEqual(expected_sig, sink.data()) + + +if __name__ == '__main__': + gr_unittest.run(qa_plateau_detector_fb, "qa_plateau_detector_fb.xml") diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index 9be2281b11..72f70ac475 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -151,6 +151,7 @@ #include "blocks/peak_detector_ib.h" #include "blocks/peak_detector_sb.h" #include "blocks/peak_detector2_fb.h" +#include "blocks/plateau_detector_fb.h" #include "blocks/probe_rate.h" #include "blocks/probe_signal_b.h" #include "blocks/probe_signal_s.h" @@ -362,6 +363,7 @@ %include "blocks/peak_detector_sb.h" %include "blocks/peak_detector2_fb.h" %include "blocks/random_pdu.h" +%include "blocks/plateau_detector_fb.h" %include "blocks/probe_rate.h" %include "blocks/regenerate_bb.h" %include "blocks/repack_bits_bb.h" @@ -539,6 +541,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector_fb); GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector_ib); GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector_sb); GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector2_fb); +GR_SWIG_BLOCK_MAGIC2(blocks, plateau_detector_fb); GR_SWIG_BLOCK_MAGIC2(blocks, pdu_to_tagged_stream); GR_SWIG_BLOCK_MAGIC2(blocks, probe_rate); GR_SWIG_BLOCK_MAGIC2(blocks, or_bb); |