Added ability to log receive path power to file in digital examples.
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Sat, 12 May 2007 23:50:46 +0000 (23:50 +0000)
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Sat, 12 May 2007 23:50:46 +0000 (23:50 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5461 221aa14e-8319-0410-a670-987f0aec2ac5

gnuradio-core/src/lib/general/Makefile.am
gnuradio-core/src/lib/general/general.i
gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.cc [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.h [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_cf.i [new file with mode: 0644]
gnuradio-examples/python/digital/receive_path.py

index 87e695a6043fc2d0902a5fafb76f4f44a7907f82..c76130039b166a574a38847e0ba847c3ad5ea384 100644 (file)
@@ -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             \
index c49a01222f1ac42848188fe0effab82f9bb8f52f..64144a05af91a187c0c0d0b4b034a1adb59eb0ab 100644 (file)
@@ -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>
 %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 (file)
index 0000000..594387e
--- /dev/null
@@ -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 (file)
index 0000000..3fd5b07
--- /dev/null
@@ -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 (file)
index 0000000..34efcaa
--- /dev/null
@@ -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();
+};
index 03e623f9fd5cdf39aad1cf1ae3a10f6454a3bb81..06a63095d3ba5e74edb9740a6e82e22198a7fdb5 100644 (file)
@@ -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