commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r9566 - in gnuradio/branches/developers/jcorgan/bert:


From: jcorgan
Subject: [Commit-gnuradio] r9566 - in gnuradio/branches/developers/jcorgan/bert: gnuradio-core/src/lib/general gnuradio-examples/python/digital-bert
Date: Sat, 13 Sep 2008 13:50:06 -0600 (MDT)

Author: jcorgan
Date: 2008-09-13 13:50:01 -0600 (Sat, 13 Sep 2008)
New Revision: 9566

Added:
   
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.cc
   
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.h
   
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.i
Modified:
   
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/Makefile.am
   
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/general.i
   
gnuradio/branches/developers/jcorgan/bert/gnuradio-examples/python/digital-bert/benchmark_rx.py
   
gnuradio/branches/developers/jcorgan/bert/gnuradio-examples/python/digital-bert/receive_path.py
Log:
Work in progress, added SNV-SNR probe

Modified: 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/Makefile.am
 2008-09-13 06:17:22 UTC (rev 9565)
+++ 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/Makefile.am
 2008-09-13 19:50:01 UTC (rev 9566)
@@ -165,7 +165,8 @@
        malloc16.c                      \
        gr_unpack_k_bits_bb.cc          \
        gr_descrambler_bb.cc            \
-       gr_scrambler_bb.cc
+       gr_scrambler_bb.cc              \
+       gr_probe_mpsk_snr_c.cc
 
 libgeneral_qa_la_SOURCES =             \
        qa_general.cc                   \
@@ -324,9 +325,9 @@
        random.h                        \
        gr_unpack_k_bits_bb.h           \
        gr_descrambler_bb.h             \
-       gr_scrambler_bb.h
+       gr_scrambler_bb.h               \
+       gr_probe_mpsk_snr_c.h
 
-
 noinst_HEADERS =                       \
        qa_general.h                    \
        qa_gr_circular_file.h           \
@@ -454,7 +455,8 @@
        gri_agc2_cc.i                   \
        gri_agc2_ff.i                   \
        gr_descrambler_bb.i             \
-       gr_scrambler_bb.i
+       gr_scrambler_bb.i               \
+       gr_probe_mpsk_snr_c.i
 
 
 CLEANFILES = $(BUILT_SOURCES) *.pyc

Modified: 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/general.i
===================================================================
--- 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/general.i
   2008-09-13 06:17:22 UTC (rev 9565)
+++ 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/general.i
   2008-09-13 19:50:01 UTC (rev 9566)
@@ -131,6 +131,7 @@
 #include <gr_decode_ccsds_27_fb.h>
 #include <gr_descrambler_bb.h>
 #include <gr_scrambler_bb.h>
+#include <gr_probe_mpsk_snr_c.h>
 %}
 
 %include "gr_nop.i"
@@ -242,3 +243,4 @@
 %include "gr_decode_ccsds_27_fb.i"
 %include "gr_descrambler_bb.i"
 %include "gr_scrambler_bb.i"
+%include "gr_probe_mpsk_snr_c.i"

Added: 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.cc
                              (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.cc
      2008-09-13 19:50:01 UTC (rev 9566)
@@ -0,0 +1,85 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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 <gr_probe_mpsk_snr_c.h>
+#include <gr_io_signature.h>
+
+gr_probe_mpsk_snr_c_sptr
+gr_make_probe_mpsk_snr_c(double alpha)
+{
+  return gr_probe_mpsk_snr_c_sptr(new gr_probe_mpsk_snr_c(alpha));
+}
+
+gr_probe_mpsk_snr_c::gr_probe_mpsk_snr_c(double alpha)
+  : gr_sync_block ("probe_mpsk_snr_c",
+                  gr_make_io_signature(1, 1, sizeof(gr_complex)),
+                  gr_make_io_signature(0, 0, 0)),
+    d_signal_mean(0.0),
+    d_noise_variance(0.0)
+{
+  set_alpha(alpha);
+}
+
+gr_probe_mpsk_snr_c::~gr_probe_mpsk_snr_c()
+{
+}
+
+int
+gr_probe_mpsk_snr_c::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++){
+    // Update of signal mean estimate
+    double mag = abs(in[i]);
+    d_signal_mean = d_alpha*abs(in[i]) + d_beta*d_signal_mean;
+
+    // Update noise variance estimate
+    double noise = mag-d_signal_mean;
+    double var = noise*noise;
+    d_noise_variance = d_alpha*var + d_beta*d_noise_variance;
+  }
+
+  return noutput_items;
+}
+
+double
+gr_probe_mpsk_snr_c::snr() const
+{
+  if (d_noise_variance == 0.0)
+    return 0.0;
+  else
+    return 10*log10(d_signal_mean*d_signal_mean/d_noise_variance);
+}
+
+void
+gr_probe_mpsk_snr_c::set_alpha(double alpha)
+{
+  d_alpha = alpha;
+  d_beta = 1.0-alpha;
+}

Added: 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.h
                               (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.h
       2008-09-13 19:50:01 UTC (rev 9566)
@@ -0,0 +1,82 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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_GR_PROBE_MPSK_SNR_C_H
+#define INCLUDED_GR_PROBE_MPSK_SNR_C_H
+
+#include <gr_sync_block.h>
+
+class gr_probe_mpsk_snr_c;
+typedef boost::shared_ptr<gr_probe_mpsk_snr_c> gr_probe_mpsk_snr_c_sptr;
+
+gr_probe_mpsk_snr_c_sptr
+gr_make_probe_mpsk_snr_c(double alpha = 0.0001);
+
+/*!
+ * Compute the estimate SNR of an MPSK signal using the Squared Signal
+ * to Noise Variance (SNV) technique.
+ *
+ * This technique assumes an AWGN channel.
+ *
+ * \param alpha  Mean and variance smoothing filter constant
+ * \ingroup sink
+ *
+ * Compute the running average of the signal mean and noise variance.
+ * The estimated signal mean, noise variance, and SNR are available
+ * via accessors.
+ *
+ * This SNR estimator is inaccurate below about 7dB SNR.
+ *
+ */
+class gr_probe_mpsk_snr_c : public gr_sync_block
+{
+  double d_alpha;
+  double d_beta;
+  double d_signal_mean;
+  double d_noise_variance;
+
+  // Factory function returning shared pointer of this class
+  friend gr_probe_mpsk_snr_c_sptr
+  gr_make_probe_mpsk_snr_c(double alpha);
+
+  // Private constructor
+  gr_probe_mpsk_snr_c(double alpha);
+
+public:
+  ~gr_probe_mpsk_snr_c();
+
+  int work (int noutput_items,
+           gr_vector_const_void_star &input_items,
+           gr_vector_void_star &output_items);
+
+  // Return the estimated signal mean
+  double signal_mean() const { return d_signal_mean; }
+
+  // Return the estimated noise variance
+  double noise_variance() const { return d_noise_variance; }
+
+  // Return the estimated signal-to-noise ratio in decibels
+  double snr() const;
+
+  void set_alpha(double alpha);
+};
+
+#endif /* INCLUDED_GR_PROBE_MPSK_SNR_C_H */

Added: 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.i
===================================================================
--- 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.i
                               (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/bert/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.i
       2008-09-13 19:50:01 UTC (rev 9566)
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr,probe_mpsk_snr_c);
+
+gr_probe_mpsk_snr_c_sptr
+gr_make_probe_mpsk_snr_c(double alpha = 0.0001);
+
+class gr_probe_mpsk_snr_c : public gr_sync_block
+{
+private:
+  void gr_probe_mpsk_snr_c(double alpha);
+
+public:
+  double signal_mean();
+  double noise_variance();
+  double snr();
+
+  void set_alpha (double alpha);
+};

Modified: 
gnuradio/branches/developers/jcorgan/bert/gnuradio-examples/python/digital-bert/benchmark_rx.py
===================================================================
--- 
gnuradio/branches/developers/jcorgan/bert/gnuradio-examples/python/digital-bert/benchmark_rx.py
     2008-09-13 06:17:22 UTC (rev 9565)
+++ 
gnuradio/branches/developers/jcorgan/bert/gnuradio-examples/python/digital-bert/benchmark_rx.py
     2008-09-13 19:50:01 UTC (rev 9566)
@@ -24,18 +24,32 @@
 from optparse import OptionParser
 from gnuradio.eng_option import eng_option
 from receive_path import receive_path
+import gnuradio.gr.gr_threading as _threading
+import time
 
 n2s = eng_notation.num_to_str
 
-_adc_rate = 64e6
+class status_thread(_threading.Thread):
+    def __init__(self, tb):
+        _threading.Thread.__init__(self)
+        self.setDaemon(1)
+        self.tb = tb
+        self.done = False
+        self.start()
 
+    def run(self):
+        while not self.done:
+            print "MAG=%5.3f VAR=%5.3f SNR=%4.1fdB" % (tb.mag(), tb.var(), 
tb.snr())
+            try:
+                time.sleep(1.0)
+            except KeyboardInterrupt:
+                self.done = True
+
 class rx_bpsk_block(gr.top_block):
     def __init__(self, options):    
 
        gr.top_block.__init__(self, "rx_mpsk")
 
-        if_rate = _adc_rate/options.decim_rate
-        
         print "USRP decimation rate", options.decim_rate
 
         # Create a USRP source at desired board, sample rate, frequency, and 
gain
@@ -45,16 +59,15 @@
                          options.freq,
                          options.gain)
 
+        # Create the BERT receiver
+        if_rate = self._usrp.adc_rate()/options.decim_rate
         self._receiver = receive_path(if_rate,
                                       options.rate,
                                       options.excess_bw)
         
         self.connect(self._usrp, self._receiver)
 
-        self._usrp_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat')
-        self.connect(self._usrp, self._usrp_sink)
 
-
     def _setup_usrp(self, which, decim, subdev_spec, freq, gain):
         self._usrp = usrp.source_c(which=which, decim_rate=decim)
        if subdev_spec is None:
@@ -73,7 +86,15 @@
        self._subdev.set_gain(gain)
         print "RX d'board:", self._subdev.side_and_name()
         
+    def snr(self):
+        return self._receiver.snr()
+
+    def mag(self):
+        return self._receiver.signal_mean()
         
+    def var(self):
+        return self._receiver.noise_variance()
+            
 def get_options():
     parser = OptionParser(option_class=eng_option)
     parser.add_option("-w", "--which", type="int", default=0,
@@ -105,7 +126,12 @@
 
     tb = rx_bpsk_block(options)
 
-    try:    
+    print "\nSNR estimator is inaccurate below about 7dB"
+
+    updater = status_thread(tb)
+
+    try:
         tb.run()
     except KeyboardInterrupt:
-        pass
+        updater.done = True
+        updater = None

Modified: 
gnuradio/branches/developers/jcorgan/bert/gnuradio-examples/python/digital-bert/receive_path.py
===================================================================
--- 
gnuradio/branches/developers/jcorgan/bert/gnuradio-examples/python/digital-bert/receive_path.py
     2008-09-13 06:17:22 UTC (rev 9565)
+++ 
gnuradio/branches/developers/jcorgan/bert/gnuradio-examples/python/digital-bert/receive_path.py
     2008-09-13 19:50:01 UTC (rev 9566)
@@ -20,6 +20,8 @@
 #
 
 from gnuradio import gr, eng_notation
+import math
+
 n2s = eng_notation.num_to_str
 
 class receive_path(gr.hier_block2):
@@ -84,6 +86,10 @@
                                            mm_gain_mu,     # First order gain
                                            mm_omega_limit) # Maximum timing 
offset
 
+        # Add an SNR probe on the demodulated constellation
+        self._snr_probe = gr.probe_mpsk_snr_c()
+        self.connect(self._mm, self._snr_probe)
+        
         # Slice the resulting constellation into bits.
         # Get inphase channel and make decision about 0
         self._c2r = gr.complex_to_real()
@@ -91,8 +97,18 @@
         
         # Descramble BERT sequence.  A channel error will create 3 incorrect 
bits
         self._descrambler = gr.descrambler_bb(0x8A, 0x7F, 7) # CCSDS 7-bit 
descrambler
-        self._sink = gr.file_sink(gr.sizeof_char, "descrambler.dat")
 
+        # This will be replaced with the density measurement block
+        self._sink = gr.null_sink(gr.sizeof_char)
+
         self.connect(self, self._agc, self._rrc, self._costas, self._mm, 
                      self._c2r, self._slicer, self._descrambler, self._sink)
 
+    def snr(self):
+        return self._snr_probe.snr()
+
+    def signal_mean(self):
+        return self._snr_probe.signal_mean()
+        
+    def noise_variance(self):
+        return self._snr_probe.noise_variance()





reply via email to

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