diff options
author | Tom Rondeau <trondeau@vt.edu> | 2013-03-18 17:35:13 -0400 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2013-03-18 17:35:13 -0400 |
commit | e0236f2bf8eb4a069736d69808432348140e576f (patch) | |
tree | d2777ae5756e7cd8bcc656a5dc13f617e260ec1c | |
parent | fa058161019c44b207df3742793e2dc58b2b63dc (diff) |
blocks: copied plateau_detector from analog to blocks.
This will be removed from gr-analog on next, but I already removed it from any GRC categories to discourage its use.
-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 | ||||
-rw-r--r-- | gr-digital/lib/digital_ofdm_sync_sc_cfb.cc | 4 |
11 files changed, 284 insertions, 3 deletions
diff --git a/gr-analog/grc/analog_block_tree.xml b/gr-analog/grc/analog_block_tree.xml index fb2731ae07..b5b2ecd568 100644 --- a/gr-analog/grc/analog_block_tree.xml +++ b/gr-analog/grc/analog_block_tree.xml @@ -56,7 +56,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 4abcbd52b0..e7b7bb2c04 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -121,6 +121,7 @@ <block>blocks_vector_to_streams</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 bb9c1c79df..631a2dff1f 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -164,6 +164,7 @@ install(FILES pdu.h pdu_to_tagged_stream.h peak_detector2_fb.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 67c44b2df9..eb7af51c0b 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -205,6 +205,7 @@ list(APPEND gr_blocks_sources tag_debug_impl.cc pdu_to_tagged_stream_impl.cc peak_detector2_fb_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 2f961c006d..7aa087192d 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -145,6 +145,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" @@ -348,6 +349,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/regenerate_bb.h" %include "blocks/repack_bits_bb.h" @@ -520,6 +522,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); diff --git a/gr-digital/lib/digital_ofdm_sync_sc_cfb.cc b/gr-digital/lib/digital_ofdm_sync_sc_cfb.cc index a3ebd549cb..1085662e1f 100644 --- a/gr-digital/lib/digital_ofdm_sync_sc_cfb.cc +++ b/gr-digital/lib/digital_ofdm_sync_sc_cfb.cc @@ -35,7 +35,7 @@ #include <blocks/multiply_ff.h> #include <blocks/divide_ff.h> #include <blocks/complex_to_arg.h> -#include <analog/plateau_detector_fb.h> +#include <blocks/plateau_detector_fb.h> #include <gr_sample_and_hold_ff.h> // Define this to add a third output for debugging @@ -72,7 +72,7 @@ digital_ofdm_sync_sc_cfb::digital_ofdm_sync_sc_cfb (int fft_len, int cp_len) gr::blocks::complex_to_arg::sptr peak_to_angle(gr::blocks::complex_to_arg::make()); gr_sample_and_hold_ff_sptr sample_and_hold(gr_make_sample_and_hold_ff()); - gr::analog::plateau_detector_fb::sptr plateau_detector(gr::analog::plateau_detector_fb::make(cp_len)); + gr::blocks::plateau_detector_fb::sptr plateau_detector(gr::blocks::plateau_detector_fb::make(cp_len)); // Delay Path connect(self(), 0, delay, 0); |