commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r3850 - in gnuradio/branches/developers/eb/binstats: g


From: eb
Subject: [Commit-gnuradio] r3850 - in gnuradio/branches/developers/eb/binstats: gnuradio-core/src/lib/general gnuradio-examples/python/usrp
Date: Tue, 24 Oct 2006 15:15:36 -0600 (MDT)

Author: eb
Date: 2006-10-24 15:15:36 -0600 (Tue, 24 Oct 2006)
New Revision: 3850

Added:
   
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/lib/general/gr_peak_detector_f.cc
   
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/lib/general/gr_peak_detector_f.h
   
gnuradio/branches/developers/eb/binstats/gnuradio-examples/python/usrp/usrp_spectrum_sense.py
Log:
merged goodies from power branch

Copied: 
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/lib/general/gr_peak_detector_f.cc
 (from rev 3849, 
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_peak_detector_f.cc)
===================================================================
--- 
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/lib/general/gr_peak_detector_f.cc
                                (rev 0)
+++ 
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/lib/general/gr_peak_detector_f.cc
        2006-10-24 21:15:36 UTC (rev 3850)
@@ -0,0 +1,55 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_peak_detector_f.h>
+#include <gr_io_signature.h>
+
+gr_peak_detector_f_sptr
+gr_make_peak_detector_f(unsigned int vlen,
+                       gr_msg_queue_sptr msgq,
+                       gr_feval_sptr tune,
+                       size_t tune_delay,
+                       size_t dwell_delay)
+{
+  return gr_peak_detector_f_sptr(new gr_peak_detector_f(vlen,
+                                                       msgq,
+                                                       tune,
+                                                       tune_delay,
+                                                       dwell_delay));
+}
+
+gr_peak_detector_f::gr_peak_detector_f(unsigned int vlen,
+                                      gr_msg_queue_sptr msgq,
+                                      gr_feval_sptr tune,
+                                      size_t tune_delay,
+                                      size_t dwell_delay)
+  : gr_sync_block("peak_detector_f",
+                 gr_make_io_signature(1, 1, sizeof(float) * vlen),
+                 gr_make_io_signature(0, 0, 0))
+  // FIXME
+{
+}
+

Copied: 
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/lib/general/gr_peak_detector_f.h
 (from rev 3849, 
gnuradio/branches/developers/eb/power/gnuradio-core/src/lib/general/gr_peak_detector_f.h)
===================================================================
--- 
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/lib/general/gr_peak_detector_f.h
                         (rev 0)
+++ 
gnuradio/branches/developers/eb/binstats/gnuradio-core/src/lib/general/gr_peak_detector_f.h
 2006-10-24 21:15:36 UTC (rev 3850)
@@ -0,0 +1,87 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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_PEAK_DETECTOR_H
+#define INCLUDED_GR_PEAK_DETECTOR_H
+
+#include <gr_sync_block.h>
+#inclue <gr_feval.h>
+#include <gr_message.h>
+#include <gr_msg_queue.h>
+
+class gr_peak_detector_f;
+typedef boost::shared_ptgr<gr_peak_detector_f> gr_peak_detector_f_sptr;
+
+
+gr_peak_detector_f_sptr
+gr_make_peak_detector_f(unsigned int vlen,     // vector length
+                       gr_msg_queue_sptr msgq,
+                       gr_feval_sptr tune,     // callback
+                       size_t tune_delay,      // samples
+                       size_t dwell_delay);    // samples
+                       
+/*!
+ * \brief record peak values in each bin
+ * \ingroup sink
+ */
+class gr_peak_detector_f : public gr_sync_block
+{
+  friend gr_peak_detector_f_sptr
+  gr_make_peak_detector_f(unsigned int vlen,   // vector length
+                         gr_msg_queue_sptr msgq,
+                         gr_feval_sptr tune,   // callback
+                         size_t tune_delay,    // samples
+                         size_t dwell_delay);  // samples
+
+  enum state_t { ST_TUNE_DELAY, ST_DWELL_DELAY };
+
+  gr_msg_queue_sptr  d_msgq;
+  gr_feval_sptr             d_tune;
+  size_t            d_tune_delay;
+  size_t            d_dwell_delay;
+
+  state_t           d_state;
+  size_t            d_delay;   // nsamples remaining to state transition
+  std::vector<float> d_max;    // per bin maxima
+
+  gr_peak_detector_f(unsigned int vlen,
+                    gr_msg_queue_sptr msgq,
+                    gr_feval_sptr tune,
+                    size_t tune_delay,
+                    size_t dwell_delay);
+
+  void enter_tune_delay();
+  void enter_dwell_delay();
+
+public:
+  ~gr_peak_detector_f();
+
+  int work (int noutput_items,
+           gr_vector_const_void_star &input_items,
+           gr_vector_void_star &output_items);
+  
+  void reset();
+
+};
+
+
+#endif

Copied: 
gnuradio/branches/developers/eb/binstats/gnuradio-examples/python/usrp/usrp_spectrum_sense.py
 (from rev 3849, 
gnuradio/branches/developers/eb/power/gnuradio-examples/python/usrp/usrp_spectrum_sense.py)
===================================================================
--- 
gnuradio/branches/developers/eb/binstats/gnuradio-examples/python/usrp/usrp_spectrum_sense.py
                               (rev 0)
+++ 
gnuradio/branches/developers/eb/binstats/gnuradio-examples/python/usrp/usrp_spectrum_sense.py
       2006-10-24 21:15:36 UTC (rev 3850)
@@ -0,0 +1,123 @@
+#!/usr/bin/env python
+
+from gnuradio import gr, gru, eng_notation, optfir, window
+from gnuradio import audio
+from gnuradio import usrp
+from gnuradio import blks
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
+import usrp_dbid
+import sys
+import math
+
+
+class wfm_rx_graph (gr.flow_graph):
+
+    def __init__(self):
+        gr.flow_graph.__init__(self)
+
+        parser=OptionParser(option_class=eng_option)
+        parser.add_option("-R", "--rx-subdev-spec", type="subdev", 
default=(0,0),
+                          help="select USRP Rx side A or B (default=A)")
+        parser.add_option("-f", "--freq", type="eng_float", default=100.1e6,
+                          help="set frequency to FREQ", metavar="FREQ")
+        parser.add_option("-g", "--gain", type="eng_float", default=None,
+                          help="set gain in dB (default is midpoint)")
+
+        (options, args) = parser.parse_args()
+        if len(args) != 0:
+            parser.print_help()
+            sys.exit(1)
+        
+
+        # build graph
+        
+        self.u = usrp.source_c()                    # usrp is data source
+
+        adc_rate = self.u.adc_rate()                # 64 MS/s
+        #usrp_decim = 8
+        usrp_decim = 16
+        self.u.set_decim_rate(usrp_decim)
+        usrp_rate = adc_rate / usrp_decim           # 8 MS/s
+
+        self.u.set_mux(usrp.determine_rx_mux_value(self.u, 
options.rx_subdev_spec))
+        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
+        print "Using RX d'board %s" % (self.subdev.side_and_name(),)
+
+
+       self.fft_size = 512
+
+       s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
+
+        mywindow = window.blackmanharris(self.fft_size)
+        fft = gr.fft_vcc(self.fft_size, True, mywindow)
+        power = 0
+        for tap in mywindow:
+            power += tap*tap
+            
+        c2mag = gr.complex_to_mag(self.fft_size)
+        #self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size)
+
+        # FIXME  We need to add 3dB to all bins but the DC bin
+        log = gr.nlog10_ff(20, self.fft_size,
+                           
-20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size))
+               
+       sink = gr.null_sink(gr.sizeof_float * self.fft_size)
+
+       self.connect(self.u, s2v, fft, c2mag, log, sink)
+
+        if options.gain is None:
+            # if no gain was specified, use the mid-point in dB
+            g = self.subdev.gain_range()
+            options.gain = float(g[0]+g[1])/2
+
+        if abs(options.freq) < 1e6:
+            options.freq *= 1e6
+
+        # set initial values
+
+        self.set_gain(options.gain)
+       print "gain =", options.gain
+
+        if not(self.set_freq(options.freq)):
+            self._set_status_msg("Failed to set initial frequency")
+
+
+       
+
+
+    def set_freq(self, target_freq):
+        """
+        Set the center frequency we're interested in.
+
+        @param target_freq: frequency in Hz
+        @rypte: bool
+
+        Tuning is a two step process.  First we ask the front-end to
+        tune as close to the desired frequency as it can.  Then we use
+        the result of that operation and our target_frequency to
+        determine the value for the digital down converter.
+        """
+        r = self.u.tune(0, self.subdev, target_freq)
+        
+        if r:
+            self.freq = target_freq
+            self._set_status_msg("OK", 0)
+            return True
+
+        self._set_status_msg("Failed", 0)
+        return False
+
+    def set_gain(self, gain):
+        self.subdev.set_gain(gain)
+
+    def _set_status_msg(self, msg, which=0):
+        print msg
+
+    
+if __name__ == '__main__':
+    fg = wfm_rx_graph()
+    try:
+        fg.run()
+    except KeyboardInterrupt:
+        pass





reply via email to

[Prev in Thread] Current Thread [Next in Thread]