diff options
author | jcorgan | 2007-05-12 23:50:46 +0000 |
---|---|---|
committer | jcorgan | 2007-05-12 23:50:46 +0000 |
commit | c95b26a7d8f04140d2371c075016c39c45b92580 (patch) | |
tree | e125c5bc08f816ab01cf4fe078e2c07f8de0890c /gnuradio-core/src/lib/general | |
parent | bbc84f59726f2aab25a9647c734208adf744e6d3 (diff) | |
download | gnuradio-c95b26a7d8f04140d2371c075016c39c45b92580.tar.gz gnuradio-c95b26a7d8f04140d2371c075016c39c45b92580.tar.bz2 gnuradio-c95b26a7d8f04140d2371c075016c39c45b92580.zip |
Added ability to log receive path power to file in digital examples.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5461 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-core/src/lib/general')
5 files changed, 203 insertions, 0 deletions
diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index 87e695a60..c76130039 100644 --- a/gnuradio-core/src/lib/general/Makefile.am +++ b/gnuradio-core/src/lib/general/Makefile.am @@ -113,6 +113,7 @@ libgeneral_la_SOURCES = \ gr_prefix.cc \ gr_prefs.cc \ gr_probe_avg_mag_sqrd_c.cc \ + gr_probe_avg_mag_sqrd_cf.cc \ gr_probe_avg_mag_sqrd_f.cc \ gr_probe_signal_f.cc \ gr_pwr_squelch_cc.cc \ @@ -250,6 +251,7 @@ grinclude_HEADERS = \ gr_prefix.h \ gr_prefs.h \ gr_probe_avg_mag_sqrd_c.h \ + gr_probe_avg_mag_sqrd_cf.h \ gr_probe_avg_mag_sqrd_f.h \ gr_probe_signal_f.h \ gr_pwr_squelch_cc.h \ @@ -388,6 +390,7 @@ swiginclude_HEADERS = \ gr_prefix.i \ gr_prefs.i \ gr_probe_avg_mag_sqrd_c.i \ + gr_probe_avg_mag_sqrd_cf.i \ gr_probe_avg_mag_sqrd_f.i \ gr_probe_signal_f.i \ gr_pwr_squelch_cc.i \ diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index c49a01222..64144a05a 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -90,6 +90,7 @@ #include <gr_pll_carriertracking_cc.h> #include <gr_pn_correlator_cc.h> #include <gr_probe_avg_mag_sqrd_c.h> +#include <gr_probe_avg_mag_sqrd_cf.h> #include <gr_probe_avg_mag_sqrd_f.h> #include <gr_probe_signal_f.h> #include <gr_ofdm_correlator.h> @@ -191,6 +192,7 @@ %include "gr_pll_carriertracking_cc.i" %include "gr_pn_correlator_cc.i" %include "gr_probe_avg_mag_sqrd_c.i" +%include "gr_probe_avg_mag_sqrd_cf.i" %include "gr_probe_avg_mag_sqrd_f.i" %include "gr_probe_signal_f.i" %include "gr_ofdm_correlator.i" diff --git a/gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.cc b/gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.cc new file mode 100644 index 000000000..594387e16 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.cc @@ -0,0 +1,86 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2007 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 2, 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_probe_avg_mag_sqrd_cf.h> +#include <gr_io_signature.h> +#include <cmath> + +gr_probe_avg_mag_sqrd_cf_sptr +gr_make_probe_avg_mag_sqrd_cf(double threshold_db, double alpha) +{ + return gr_probe_avg_mag_sqrd_cf_sptr(new gr_probe_avg_mag_sqrd_cf(threshold_db, alpha)); +} + +gr_probe_avg_mag_sqrd_cf::gr_probe_avg_mag_sqrd_cf (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_iir(alpha), d_unmuted(false), d_level(0) +{ + set_threshold (threshold_db); +} + +gr_probe_avg_mag_sqrd_cf::~gr_probe_avg_mag_sqrd_cf() +{ +} + + +int +gr_probe_avg_mag_sqrd_cf::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 +gr_probe_avg_mag_sqrd_cf::threshold() const +{ + return 10 * std::log10(d_threshold); +} + +void +gr_probe_avg_mag_sqrd_cf::set_threshold(double decibels) +{ + // convert to absolute threshold (mag squared) + d_threshold = std::pow(10.0, decibels/10); +} + +void +gr_probe_avg_mag_sqrd_cf::set_alpha(double alpha) +{ + d_iir.set_taps(alpha); +} diff --git a/gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.h b/gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.h new file mode 100644 index 000000000..3fd5b071b --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.h @@ -0,0 +1,76 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2006 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 2, 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_PROBE_AVG_MAG_SQRD_CF_H +#define INCLUDED_GR_PROBE_AVG_MAG_SQRD_CF_H + +#include <gr_sync_block.h> +#include <gr_single_pole_iir.h> + +class gr_probe_avg_mag_sqrd_cf; +typedef boost::shared_ptr<gr_probe_avg_mag_sqrd_cf> gr_probe_avg_mag_sqrd_cf_sptr; + +gr_probe_avg_mag_sqrd_cf_sptr +gr_make_probe_avg_mag_sqrd_cf (double threshold_db, double alpha = 0.0001); + +/*! + * \brief compute avg magnitude squared. + * \ingroup sink + * + * input: gr_complex + * output: gr_float + * + * Compute a running average of the magnitude squared of the the input. + * The level and indication as to whether the level exceeds threshold + * can be retrieved with the level and unmuted accessors. + * + */ +class gr_probe_avg_mag_sqrd_cf : public gr_sync_block +{ + double d_threshold; + gr_single_pole_iir<double,double,double> d_iir; + bool d_unmuted; + double d_level; + + friend gr_probe_avg_mag_sqrd_cf_sptr + gr_make_probe_avg_mag_sqrd_cf (double threshold_db, double alpha); + + gr_probe_avg_mag_sqrd_cf (double threshold_db, double alpha); + +public: + ~gr_probe_avg_mag_sqrd_cf (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + // ACCESSORS + bool unmuted () const { return d_unmuted; } + double level () const { return d_level; } + + double threshold() const; + + // SETTERS + void set_alpha (double alpha); + void set_threshold (double decibels); +}; + +#endif /* INCLUDED_GR_PROBE_AVG_MAG_SQRD_CF_H */ diff --git a/gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.i b/gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.i new file mode 100644 index 000000000..34efcaa41 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.i @@ -0,0 +1,36 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005 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 2, 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,probe_avg_mag_sqrd_cf); + +gr_probe_avg_mag_sqrd_cf_sptr +gr_make_probe_avg_mag_sqrd_cf (double threshold_db, double alpha = 0.0001); + +class gr_probe_avg_mag_sqrd_cf : public gr_sync_block +{ +public: + bool unmuted () const { return d_unmuted; } + double level () const { return d_level; } + void set_alpha (double alpha); + void set_threshold (double decibels); + double threshold(); +}; |