diff options
author | Tom Rondeau | 2013-02-24 14:15:05 -0500 |
---|---|---|
committer | Tom Rondeau | 2013-02-24 14:15:05 -0500 |
commit | ffcaa3436cc8e608cb51bad78ca669b90bd110f2 (patch) | |
tree | 2d5735e89e81c36568c1f5699ff80c5213d7ada9 /gr-blocks/lib | |
parent | 96583a9009478242c51ecfd7bb4321ed3d90e3b8 (diff) | |
download | gnuradio-ffcaa3436cc8e608cb51bad78ca669b90bd110f2.tar.gz gnuradio-ffcaa3436cc8e608cb51bad78ca669b90bd110f2.tar.bz2 gnuradio-ffcaa3436cc8e608cb51bad78ca669b90bd110f2.zip |
blocks: converted peak_detector2 and regenerate to v3.7.
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gr-blocks/lib/peak_detector2_fb_impl.cc | 118 | ||||
-rw-r--r-- | gr-blocks/lib/peak_detector2_fb_impl.h | 64 | ||||
-rw-r--r-- | gr-blocks/lib/regenerate_bb_impl.cc | 103 | ||||
-rw-r--r-- | gr-blocks/lib/regenerate_bb_impl.h | 57 |
5 files changed, 344 insertions, 0 deletions
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 9b076f696..aa87d9c64 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -165,6 +165,8 @@ list(APPEND gr_blocks_sources multiply_const_ff_impl.cc nlog10_ff_impl.cc patterned_interleaver_impl.cc + peak_detector2_fb_impl.cc + regenerate_bb_impl.cc repeat_impl.cc rms_cf_impl.cc rms_ff_impl.cc diff --git a/gr-blocks/lib/peak_detector2_fb_impl.cc b/gr-blocks/lib/peak_detector2_fb_impl.cc new file mode 100644 index 000000000..0d375c3ba --- /dev/null +++ b/gr-blocks/lib/peak_detector2_fb_impl.cc @@ -0,0 +1,118 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2010,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 "peak_detector2_fb_impl.h" +#include <gr_io_signature.h> +#include <string.h> + +namespace gr { + namespace blocks { + + peak_detector2_fb::sptr + peak_detector2_fb::make(float threshold_factor_rise, + int look_ahead, float alpha) + { + return gnuradio::get_initial_sptr + (new peak_detector2_fb_impl(threshold_factor_rise, + look_ahead, alpha)); + } + + peak_detector2_fb_impl::peak_detector2_fb_impl(float threshold_factor_rise, + int look_ahead, float alpha) + : gr_sync_block("peak_detector2_fb", + gr_make_io_signature(1, 1, sizeof(float)), + gr_make_io_signature2(1, 2, sizeof(char), sizeof(float))), + d_threshold_factor_rise(threshold_factor_rise), + d_look_ahead(look_ahead), d_alpha(alpha), d_avg(0.0f), d_found(false) + { + } + + peak_detector2_fb_impl::~peak_detector2_fb_impl() + { + } + + int + peak_detector2_fb_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + float *iptr = (float *)input_items[0]; + char *optr = (char *)output_items[0]; + + assert(noutput_items >= 2); + + memset(optr, 0, noutput_items*sizeof(char)); + + for(int i = 0; i < noutput_items; i++) { + if(!d_found) { + // Have not yet detected presence of peak + if(iptr[i] > d_avg * (1.0f + d_threshold_factor_rise)) { + d_found = true; + d_look_ahead_remaining = d_look_ahead; + d_peak_val = -(float)INFINITY; + } + else { + d_avg = d_alpha*iptr[i] + (1.0f - d_alpha)*d_avg; + } + } + else { + // Detected presence of peak + if(iptr[i] > d_peak_val) { + d_peak_val = iptr[i]; + d_peak_ind = i; + } + else if(d_look_ahead_remaining <= 0) { + optr[d_peak_ind] = 1; + d_found = false; + d_avg = iptr[i]; + } + + // Have not yet located peak, loop and keep searching. + d_look_ahead_remaining--; + } + + // Every iteration of the loop, write debugging signal out if + // connected: + if(output_items.size() == 2) { + float *sigout = (float *)output_items[1]; + sigout[i] = d_avg; + } + } // loop + + if(!d_found) + return noutput_items; + + // else if detected presence, keep searching during the next call to work. + int tmp = d_peak_ind; + d_peak_ind = 1; + + return tmp - 1; + } + + } /* namespace blocks */ +} /* namespace gr */ + + diff --git a/gr-blocks/lib/peak_detector2_fb_impl.h b/gr-blocks/lib/peak_detector2_fb_impl.h new file mode 100644 index 000000000..f03dd36a8 --- /dev/null +++ b/gr-blocks/lib/peak_detector2_fb_impl.h @@ -0,0 +1,64 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,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_GR_PEAK_DETECTOR2_FB_IMPL_H +#define INCLUDED_GR_PEAK_DETECTOR2_FB_IMPL_H + +#include <blocks/peak_detector2_fb.h> + +namespace gr { + namespace blocks { + + class peak_detector2_fb_impl : public peak_detector2_fb + { + private: + float d_threshold_factor_rise; + int d_look_ahead; + int d_look_ahead_remaining; + int d_peak_ind; + float d_peak_val; + float d_alpha; + float d_avg; + bool d_found; + + public: + peak_detector2_fb_impl(float threshold_factor_rise, + int look_ahead, float alpha); + ~peak_detector2_fb_impl(); + + void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; } + void set_look_ahead(int look) { d_look_ahead = look; } + void set_alpha(int alpha) { d_alpha = alpha; } + + float threshold_factor_rise() { return d_threshold_factor_rise; } + int look_ahead() { return d_look_ahead; } + float alpha() { return d_alpha; } + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_PEAK_DETECTOR2_FB_IMPL_H */ diff --git a/gr-blocks/lib/regenerate_bb_impl.cc b/gr-blocks/lib/regenerate_bb_impl.cc new file mode 100644 index 000000000..4472efb6d --- /dev/null +++ b/gr-blocks/lib/regenerate_bb_impl.cc @@ -0,0 +1,103 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2010,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 "regenerate_bb_impl.h" +#include <gr_io_signature.h> + +namespace gr { + namespace blocks { + + regenerate_bb::sptr + regenerate_bb::make(int period, unsigned int max_regen) + { + return gnuradio::get_initial_sptr + (new regenerate_bb_impl(period, max_regen)); + } + + regenerate_bb_impl::regenerate_bb_impl(int period, unsigned int max_regen) + : gr_sync_block("regenerate_bb", + gr_make_io_signature(1, 1, sizeof(char)), + gr_make_io_signature(1, 1, sizeof(char))), + d_period(period), + d_countdown(0), + d_max_regen(max_regen), + d_regen_count(max_regen) + { + } + + regenerate_bb_impl::~regenerate_bb_impl() + { + } + + void + regenerate_bb_impl::set_max_regen(unsigned int regen) + { + d_max_regen = regen; + d_countdown = 0; + d_regen_count = d_max_regen; + } + + void + regenerate_bb_impl::set_period(int period) + { + d_period = period; + d_countdown = 0; + d_regen_count = d_max_regen; + } + + int + regenerate_bb_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const char *iptr = (const char *)input_items[0]; + char *optr = (char *)output_items[0]; + + for(int i = 0; i < noutput_items; i++) { + optr[i] = 0; + + if(d_regen_count < d_max_regen) { + d_countdown--; + + if(d_countdown == 0) { + optr[i] = 1; + d_countdown = d_period; + d_regen_count++; + } + } + + if(iptr[i] == 1) { + d_countdown = d_period; + optr[i] = 1; + d_regen_count = 0; + } + + } + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/regenerate_bb_impl.h b/gr-blocks/lib/regenerate_bb_impl.h new file mode 100644 index 000000000..bcfa18391 --- /dev/null +++ b/gr-blocks/lib/regenerate_bb_impl.h @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,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_GR_REGENERATE_BB_H +#define INCLUDED_GR_REGENERATE_BB_IMPL_H + +#include <blocks/regenerate_bb.h> + +namespace gr { + namespace blocks { + + class regenerate_bb_impl : public regenerate_bb + { + private: + int d_period; + int d_countdown; + unsigned int d_max_regen; + unsigned int d_regen_count; + + public: + regenerate_bb_impl(int period, unsigned int max_regen=500); + ~regenerate_bb_impl(); + + void set_max_regen(unsigned int regen); + void set_period(int period); + + unsigned int max_regen() const { return d_max_regen; }; + int period() const { return d_period; }; + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_REGENERATE_BB_IMPL_H */ |