From c95b26a7d8f04140d2371c075016c39c45b92580 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 12 May 2007 23:50:46 +0000 Subject: [PATCH] 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 --- gnuradio-core/src/lib/general/Makefile.am | 3 + gnuradio-core/src/lib/general/general.i | 2 + .../lib/general/gr_probe_avg_mag_sqrd_cf.cc | 86 +++++++++++++++++++ .../lib/general/gr_probe_avg_mag_sqrd_cf.h | 76 ++++++++++++++++ .../lib/general/gr_probe_avg_mag_sqrd_cf.i | 36 ++++++++ .../python/digital/receive_path.py | 14 ++- 6 files changed, 214 insertions(+), 3 deletions(-) create mode 100644 gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.cc create mode 100644 gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.h create mode 100644 gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.i diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index 87e695a6..c7613003 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 c49a0122..64144a05 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -90,6 +90,7 @@ #include #include #include +#include #include #include #include @@ -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 00000000..594387e1 --- /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 +#include +#include + +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 00000000..3fd5b071 --- /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 +#include + +class gr_probe_avg_mag_sqrd_cf; +typedef boost::shared_ptr 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 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 00000000..34efcaa4 --- /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(); +}; diff --git a/gnuradio-examples/python/digital/receive_path.py b/gnuradio-examples/python/digital/receive_path.py index 03e623f9..06a63095 100644 --- a/gnuradio-examples/python/digital/receive_path.py +++ b/gnuradio-examples/python/digital/receive_path.py @@ -105,8 +105,14 @@ class receive_path(gr.hier_block): # Carrier Sensing Blocks alpha = 0.001 thresh = 30 # in dB, will have to adjust - self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha) - fg.connect(self.chan_filt, self.probe) + + if options.log_rx_power == True: + self.probe = gr.probe_avg_mag_sqrd_cf(thresh,alpha) + self.power_sink = gr.file_sink(gr.sizeof_float, "rxpower.dat") + fg.connect(self.chan_filt, self.probe, self.power_sink) + else: + self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha) + fg.connect(self.chan_filt, self.probe) # Display some information about the setup if self._verbose: @@ -220,6 +226,8 @@ class receive_path(gr.hier_block): help="set fpga decimation rate to DECIM [default=%default]") expert.add_option("", "--log", action="store_true", default=False, help="Log all parts of flow graph to files (CAUTION: lots of data)") + expert.add_option("", "--log-rx-power", action="store_true", default=False, + help="Log receive signal power to file (CAUTION: lots of data)") # Make a static method to call before instantiation add_options = staticmethod(add_options) @@ -238,7 +246,7 @@ class receive_path(gr.hier_block): print "decim: %3d" % (self._decim) print "Rx Frequency: %s" % (eng_notation.num_to_str(self._rx_freq)) # print "Rx Frequency: %f" % (self._rx_freq) - + def add_freq_option(parser): """ Hackery that has the -f / --freq option set both tx_freq and rx_freq -- 2.30.2