diff options
author | Tom Rondeau | 2012-10-30 14:46:29 -0400 |
---|---|---|
committer | Tom Rondeau | 2012-10-30 14:46:29 -0400 |
commit | 1eb6dd37acdfb81f7a8602897ac5cb1685c532e8 (patch) | |
tree | e521b2b19e307add497c2cf3728694470f11f593 /gr-analog/lib | |
parent | 11cd6d2dc3e6b3b40474a5a4495d814a7688fe0a (diff) | |
download | gnuradio-1eb6dd37acdfb81f7a8602897ac5cb1685c532e8.tar.gz gnuradio-1eb6dd37acdfb81f7a8602897ac5cb1685c532e8.tar.bz2 gnuradio-1eb6dd37acdfb81f7a8602897ac5cb1685c532e8.zip |
analog: adding probe_avg_mag_sqrd blocks to gr-analog with QA and GRC.
Diffstat (limited to 'gr-analog/lib')
-rw-r--r-- | gr-analog/lib/CMakeLists.txt | 3 | ||||
-rw-r--r-- | gr-analog/lib/probe_avg_mag_sqrd_c_impl.cc | 91 | ||||
-rw-r--r-- | gr-analog/lib/probe_avg_mag_sqrd_c_impl.h | 60 | ||||
-rw-r--r-- | gr-analog/lib/probe_avg_mag_sqrd_cf_impl.cc | 93 | ||||
-rw-r--r-- | gr-analog/lib/probe_avg_mag_sqrd_cf_impl.h | 60 | ||||
-rw-r--r-- | gr-analog/lib/probe_avg_mag_sqrd_f_impl.cc | 92 | ||||
-rw-r--r-- | gr-analog/lib/probe_avg_mag_sqrd_f_impl.h | 60 |
7 files changed, 459 insertions, 0 deletions
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt index 20a86621e..93ab5e83e 100644 --- a/gr-analog/lib/CMakeLists.txt +++ b/gr-analog/lib/CMakeLists.txt @@ -120,6 +120,9 @@ list(APPEND analog_sources pll_carriertracking_cc_impl.cc pll_freqdet_cf_impl.cc pll_refout_cc_impl.cc + probe_avg_mag_sqrd_c_impl.cc + probe_avg_mag_sqrd_cf_impl.cc + probe_avg_mag_sqrd_f_impl.cc ) list(APPEND analog_libs diff --git a/gr-analog/lib/probe_avg_mag_sqrd_c_impl.cc b/gr-analog/lib/probe_avg_mag_sqrd_c_impl.cc new file mode 100644 index 000000000..291809bb2 --- /dev/null +++ b/gr-analog/lib/probe_avg_mag_sqrd_c_impl.cc @@ -0,0 +1,91 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,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 "probe_avg_mag_sqrd_c_impl.h" +#include <gr_io_signature.h> +#include <cmath> + +namespace gr { + namespace analog { + + probe_avg_mag_sqrd_c::sptr + probe_avg_mag_sqrd_c::make(double threshold_db, double alpha) + { + return gnuradio::get_initial_sptr + (new probe_avg_mag_sqrd_c_impl(threshold_db, alpha)); + } + + probe_avg_mag_sqrd_c_impl::probe_avg_mag_sqrd_c_impl(double threshold_db, double alpha) + : gr_sync_block("probe_avg_mag_sqrd_c", + gr_make_io_signature(1, 1, sizeof(gr_complex)), + gr_make_io_signature(0, 0, 0)), + d_unmuted(false), d_level(0), d_iir(alpha) + { + set_threshold(threshold_db); + } + + probe_avg_mag_sqrd_c_impl::~probe_avg_mag_sqrd_c_impl() + { + } + + int + probe_avg_mag_sqrd_c_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const gr_complex *in = (const gr_complex*)input_items[0]; + + for(int i = 0; i < noutput_items; i++) { + double mag_sqrd = in[i].real()*in[i].real() + in[i].imag()*in[i].imag(); + d_iir.filter(mag_sqrd); // computed for side effect: prev_output() + } + + d_unmuted = d_iir.prev_output() >= d_threshold; + d_level = d_iir.prev_output(); + return noutput_items; + } + + double + probe_avg_mag_sqrd_c_impl::threshold() const + { + return 10 * std::log10(d_threshold); + } + + void + probe_avg_mag_sqrd_c_impl::set_threshold(double decibels) + { + // convert to absolute threshold (mag squared) + d_threshold = std::pow(10.0, decibels/10); + } + + void + probe_avg_mag_sqrd_c_impl::set_alpha(double alpha) + { + d_iir.set_taps(alpha); + } + + } /* namespace analog */ +} /* namespace gr */ diff --git a/gr-analog/lib/probe_avg_mag_sqrd_c_impl.h b/gr-analog/lib/probe_avg_mag_sqrd_c_impl.h new file mode 100644 index 000000000..0a2685357 --- /dev/null +++ b/gr-analog/lib/probe_avg_mag_sqrd_c_impl.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2006,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_PROBE_AVG_MAG_SQRD_C_IMPL_H +#define INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_C_IMPL_H + +#include <analog/probe_avg_mag_sqrd_c.h> +#include <filter/single_pole_iir.h> + +namespace gr { + namespace analog { + + class probe_avg_mag_sqrd_c_impl : public probe_avg_mag_sqrd_c + { + private: + double d_threshold; + bool d_unmuted; + double d_level; + filter::single_pole_iir<double,double,double> d_iir; + + public: + probe_avg_mag_sqrd_c_impl(double threshold_db, double alpha = 0.0001); + ~probe_avg_mag_sqrd_c_impl(); + + bool unmuted() const { return d_unmuted; } + double level() const { return d_level; } + + double threshold() const; + + void set_alpha(double alpha); + void set_threshold(double decibels); + + 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_PROBE_AVG_MAG_SQRD_C_IMPL_H */ diff --git a/gr-analog/lib/probe_avg_mag_sqrd_cf_impl.cc b/gr-analog/lib/probe_avg_mag_sqrd_cf_impl.cc new file mode 100644 index 000000000..ceaf5dbf0 --- /dev/null +++ b/gr-analog/lib/probe_avg_mag_sqrd_cf_impl.cc @@ -0,0 +1,93 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "probe_avg_mag_sqrd_cf_impl.h" +#include <gr_io_signature.h> +#include <cmath> + +namespace gr { + namespace analog { + + probe_avg_mag_sqrd_cf::sptr + probe_avg_mag_sqrd_cf::make(double threshold_db, double alpha) + { + return gnuradio::get_initial_sptr + (new probe_avg_mag_sqrd_cf_impl(threshold_db, alpha)); + } + + probe_avg_mag_sqrd_cf_impl::probe_avg_mag_sqrd_cf_impl(double threshold_db, double alpha) + : gr_sync_block("probe_avg_mag_sqrd_cf", + gr_make_io_signature(1, 1, sizeof(gr_complex)), + gr_make_io_signature(1, 1, sizeof(float))), + d_unmuted(false), d_level(0), d_iir(alpha) + { + set_threshold(threshold_db); + } + + probe_avg_mag_sqrd_cf_impl::~probe_avg_mag_sqrd_cf_impl() + { + } + + int + probe_avg_mag_sqrd_cf_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const gr_complex *in = (const gr_complex*)input_items[0]; + float *out = (float*)output_items[0]; + + for(int i = 0; i < noutput_items; i++) { + out[i] = d_iir.prev_output(); + double mag_sqrd = in[i].real()*in[i].real() + in[i].imag()*in[i].imag(); + d_iir.filter(mag_sqrd); // computed for side effect: prev_output() + } + + d_unmuted = d_iir.prev_output() >= d_threshold; + d_level = d_iir.prev_output(); + return noutput_items; + } + + double + probe_avg_mag_sqrd_cf_impl::threshold() const + { + return 10 * std::log10(d_threshold); + } + + void + probe_avg_mag_sqrd_cf_impl::set_threshold(double decibels) + { + // convert to absolute threshold (mag squared) + d_threshold = std::pow(10.0, decibels/10); + } + + void + probe_avg_mag_sqrd_cf_impl::set_alpha(double alpha) + { + d_iir.set_taps(alpha); + } + + } /* namespace analog */ +} /* namespace gr */ diff --git a/gr-analog/lib/probe_avg_mag_sqrd_cf_impl.h b/gr-analog/lib/probe_avg_mag_sqrd_cf_impl.h new file mode 100644 index 000000000..9cd8f8d4c --- /dev/null +++ b/gr-analog/lib/probe_avg_mag_sqrd_cf_impl.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2006,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_PROBE_AVG_MAG_SQRD_CF_IMPL_H +#define INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_CF_IMPL_H + +#include <analog/probe_avg_mag_sqrd_cf.h> +#include <filter/single_pole_iir.h> + +namespace gr { + namespace analog { + + class probe_avg_mag_sqrd_cf_impl : public probe_avg_mag_sqrd_cf + { + private: + double d_threshold; + bool d_unmuted; + double d_level; + filter::single_pole_iir<double,double,double> d_iir; + + public: + probe_avg_mag_sqrd_cf_impl(double threshold_db, double alpha); + ~probe_avg_mag_sqrd_cf_impl(); + + bool unmuted() const { return d_unmuted; } + double level() const { return d_level; } + + double threshold() const; + + void set_alpha(double alpha); + void set_threshold(double decibels); + + 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_PROBE_AVG_MAG_SQRD_CF_IMPL_H */ diff --git a/gr-analog/lib/probe_avg_mag_sqrd_f_impl.cc b/gr-analog/lib/probe_avg_mag_sqrd_f_impl.cc new file mode 100644 index 000000000..4ac7ef06b --- /dev/null +++ b/gr-analog/lib/probe_avg_mag_sqrd_f_impl.cc @@ -0,0 +1,92 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,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 "probe_avg_mag_sqrd_f_impl.h" +#include <gr_io_signature.h> +#include <cmath> + +namespace gr { + namespace analog { + + probe_avg_mag_sqrd_f::sptr + probe_avg_mag_sqrd_f::make(double threshold_db, double alpha) + { + return gnuradio::get_initial_sptr + (new probe_avg_mag_sqrd_f_impl(threshold_db, alpha)); + } + + probe_avg_mag_sqrd_f_impl::probe_avg_mag_sqrd_f_impl(double threshold_db, double alpha) + : gr_sync_block("probe_avg_mag_sqrd_f", + gr_make_io_signature(1, 1, sizeof(float)), + gr_make_io_signature(0, 0, 0)), + d_unmuted(false), d_level(0), d_iir(alpha) + { + set_threshold(threshold_db); + } + + probe_avg_mag_sqrd_f_impl::~probe_avg_mag_sqrd_f_impl() + { + } + + int + probe_avg_mag_sqrd_f_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]; + + for(int i = 0; i < noutput_items; i++) { + double mag_sqrd = in[i]*in[i]; + d_iir.filter(mag_sqrd); // computed for side effect: prev_output() + } + + d_unmuted = d_iir.prev_output() >= d_threshold; + d_level = d_iir.prev_output(); + return noutput_items; + } + + double + probe_avg_mag_sqrd_f_impl::threshold() const + { + return 10 * std::log10(d_threshold); + } + + void + probe_avg_mag_sqrd_f_impl::set_threshold(double decibels) + { + // convert to absolute threshold (mag sqrd) + d_threshold = std::pow(10.0, decibels/10); + } + + void + probe_avg_mag_sqrd_f_impl::set_alpha(double alpha) + { + d_iir.set_taps(alpha); + } + + } /* namespace analog */ +} /* namespace gr */ + diff --git a/gr-analog/lib/probe_avg_mag_sqrd_f_impl.h b/gr-analog/lib/probe_avg_mag_sqrd_f_impl.h new file mode 100644 index 000000000..ba879763c --- /dev/null +++ b/gr-analog/lib/probe_avg_mag_sqrd_f_impl.h @@ -0,0 +1,60 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,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_PROBE_AVG_MAG_SQRD_F_IMPL_H +#define INCLUDED_ANALOG_PROBE_AVG_MAG_SQRD_F_IMPL_H + +#include <analog/probe_avg_mag_sqrd_f.h> +#include <filter/single_pole_iir.h> + +namespace gr { + namespace analog { + + class probe_avg_mag_sqrd_f_impl : public probe_avg_mag_sqrd_f + { + private: + double d_threshold; + bool d_unmuted; + double d_level; + filter::single_pole_iir<double,double,double> d_iir; + + public: + probe_avg_mag_sqrd_f_impl(double threshold_db, double alpha); + ~probe_avg_mag_sqrd_f_impl(); + + bool unmuted() const { return d_unmuted; } + double level() const { return d_level; } + + double threshold() const; + + void set_alpha(double alpha); + void set_threshold(double decibels); + + 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_PROBE_AVG_MAG_SQRD_F_IMPL_H */ |