commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10182 - in gnuradio/trunk: gr-usrp2/src usrp2/host/in


From: jcorgan
Subject: [Commit-gnuradio] r10182 - in gnuradio/trunk: gr-usrp2/src usrp2/host/include/usrp2 usrp2/host/lib
Date: Wed, 31 Dec 2008 15:19:48 -0700 (MST)

Author: jcorgan
Date: 2008-12-31 15:19:48 -0700 (Wed, 31 Dec 2008)
New Revision: 10182

Modified:
   gnuradio/trunk/gr-usrp2/src/usrp2.i
   gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.cc
   gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.h
   gnuradio/trunk/usrp2/host/include/usrp2/usrp2.h
   gnuradio/trunk/usrp2/host/lib/usrp2.cc
   gnuradio/trunk/usrp2/host/lib/usrp2_impl.cc
   gnuradio/trunk/usrp2/host/lib/usrp2_impl.h
Log:
For USRP2, implement auto scaling of TX pipeline such that [-1.0 1.0] input to
usrp2.sink_32fc results in full-scale DAC outputs, regardless of interpolation
rate.


Modified: gnuradio/trunk/gr-usrp2/src/usrp2.i
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2.i 2008-12-31 20:46:29 UTC (rev 10181)
+++ gnuradio/trunk/gr-usrp2/src/usrp2.i 2008-12-31 22:19:48 UTC (rev 10182)
@@ -137,6 +137,8 @@
   bool set_interp(int interp_factor);
   bool set_scale_iq(int scale_i, int scale_q);
   int interp();
+  %rename(_real_default_tx_scale_iq) default_scale_iq;
+  void default_scale_iq(int interp, int *scale_i, int *scale_q);
   %rename(_real_dac_rate) dac_rate;
   bool dac_rate(long *rate);
   double gain_min();
@@ -257,7 +259,7 @@
           self.freq_max()]
 
 def __daughterboard_id(self):
-  dbid = make_int_ptr();
+  dbid = make_int_ptr()
   r = self._real_daughterboard_id(dbid)
   if r:
     result = deref_int_ptr(dbid)
@@ -266,6 +268,12 @@
   free_int_ptr(dbid)
   return result
 
+def __default_tx_scale_iq(self, interp):
+  scale_i = make_int_ptr()
+  scale_q = make_int_ptr()
+  self._real_default_tx_scale_iq(interp, scale_i, scale_q)
+  return (deref_int_ptr(scale_i), deref_int_ptr(scale_q))
+
 usrp2_source_32fc_sptr.set_center_freq = __set_center_freq
 usrp2_source_16sc_sptr.set_center_freq = __set_center_freq
 usrp2_sink_32fc_sptr.set_center_freq = __set_center_freq
@@ -296,4 +304,7 @@
 usrp2_sink_32fc_sptr.daughterboard_id = __daughterboard_id
 usrp2_sink_16sc_sptr.daughterboard_id = __daughterboard_id
 
+usrp2_sink_32fc_sptr.default_scale_iq = __default_tx_scale_iq
+usrp2_sink_16sc_sptr.default_scale_iq = __default_tx_scale_iq
+
 %}

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.cc
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.cc      2008-12-31 20:46:29 UTC 
(rev 10181)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.cc      2008-12-31 22:19:48 UTC 
(rev 10182)
@@ -64,6 +64,12 @@
   return d_u2->set_tx_interp(interp_factor);
 }
 
+void
+usrp2_sink_base::default_scale_iq(int interp_factor, int *scale_i, int 
*scale_q)
+{
+  return d_u2->default_tx_scale_iq(interp_factor, scale_i, scale_q);
+}
+
 bool 
 usrp2_sink_base::set_scale_iq(int scale_i, int scale_q)
 {

Modified: gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.h
===================================================================
--- gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.h       2008-12-31 20:46:29 UTC 
(rev 10181)
+++ gnuradio/trunk/gr-usrp2/src/usrp2_sink_base.h       2008-12-31 22:19:48 UTC 
(rev 10182)
@@ -56,6 +56,11 @@
   bool set_interp(int interp_factor);
 
   /*!
+   * \brief Calculate default scale_iq for given interpolation factor
+   */
+  void default_scale_iq(int interpolation_factor, int *scale_i, int *scale_q);
+
+  /*!
    * \brief Set transmit IQ scale factors
    */
   bool set_scale_iq(int scale_i, int scale_q);

Modified: gnuradio/trunk/usrp2/host/include/usrp2/usrp2.h
===================================================================
--- gnuradio/trunk/usrp2/host/include/usrp2/usrp2.h     2008-12-31 20:46:29 UTC 
(rev 10181)
+++ gnuradio/trunk/usrp2/host/include/usrp2/usrp2.h     2008-12-31 22:19:48 UTC 
(rev 10182)
@@ -219,6 +219,11 @@
     //! Return current interpolation factor
     int tx_interp();
 
+    /*
+     * \brief Calculate default scale_iq for given interpolation rate
+     */
+    void default_tx_scale_iq(int interpolation_factor, int *scale_i, int 
*scale_q);
+
     /*!
      * Set transmit IQ magnitude scaling
      */

Modified: gnuradio/trunk/usrp2/host/lib/usrp2.cc
===================================================================
--- gnuradio/trunk/usrp2/host/lib/usrp2.cc      2008-12-31 20:46:29 UTC (rev 
10181)
+++ gnuradio/trunk/usrp2/host/lib/usrp2.cc      2008-12-31 22:19:48 UTC (rev 
10182)
@@ -309,6 +309,12 @@
     return d_impl->tx_interp();
   }
 
+  void
+  usrp2::default_tx_scale_iq(int interpolation_factor, int *scale_i, int 
*scale_q)
+  {
+    d_impl->default_tx_scale_iq(interpolation_factor, scale_i, scale_q);
+  }
+
   bool
   usrp2::set_tx_scale_iq(int scale_i, int scale_q)
   {

Modified: gnuradio/trunk/usrp2/host/lib/usrp2_impl.cc
===================================================================
--- gnuradio/trunk/usrp2/host/lib/usrp2_impl.cc 2008-12-31 20:46:29 UTC (rev 
10181)
+++ gnuradio/trunk/usrp2/host/lib/usrp2_impl.cc 2008-12-31 22:19:48 UTC (rev 
10182)
@@ -46,7 +46,6 @@
 #endif
 
 static const int DEFAULT_RX_SCALE = 1024;
-static const int DEFAULT_TX_SCALE = 3000;
 
 namespace usrp2 {
 
@@ -187,9 +186,6 @@
     // set workable defaults for scaling
     if (!set_rx_scale_iq(DEFAULT_RX_SCALE, DEFAULT_RX_SCALE))
       std::cerr << "usrp2::ctor set_rx_scale_iq failed\n";
-
-    if (!set_tx_scale_iq(DEFAULT_TX_SCALE, DEFAULT_TX_SCALE))
-      std::cerr << "usrp2::ctor set_tx_scale_iq failed\n";
   }
   
   usrp2::impl::~impl()
@@ -768,11 +764,42 @@
       return false;
 
     bool success = (ntohx(reply.ok) == 1);
-    if (success)
+    if (success) {
       d_tx_interp = interpolation_factor;
+
+      // Auto-set TX scaling based on interpolation rate
+      int scale_i, scale_q;
+      default_tx_scale_iq(d_tx_interp, &scale_i, &scale_q);
+      return set_tx_scale_iq(scale_i, scale_q);
+    }
+
     return success;
   }
   
+  void
+  usrp2::impl::default_tx_scale_iq(int interpolation_factor, int *scale_i, int 
*scale_q)
+  {
+    // Calculate CIC interpolation (i.e., without halfband interpolators)
+    int i = interpolation_factor;
+    if (i > 128)
+      i = i >> 1;
+    if (i > 128)
+      i = i >> 1;
+
+    // Calculate dsp_core_tx gain absent scale multipliers
+    float gain = (1.65*i*i*i)/(4096*pow(2, ceil(log2(i*i*i))));
+    
+    // Calculate closest multiplier constant to reverse gain
+    int scale = (int)rint(1.0/gain);
+    // fprintf(stderr, "if=%i i=%i gain=%f scale=%i\n", interpolation_factor, 
i, gain, scale);
+
+    // Both I and Q are identical in this case
+    if (scale_i)
+      *scale_i = scale;
+    if (scale_q)
+      *scale_q = scale;
+  }
+
   bool
   usrp2::impl::set_tx_scale_iq(int scale_i, int scale_q)
   {

Modified: gnuradio/trunk/usrp2/host/lib/usrp2_impl.h
===================================================================
--- gnuradio/trunk/usrp2/host/lib/usrp2_impl.h  2008-12-31 20:46:29 UTC (rev 
10181)
+++ gnuradio/trunk/usrp2/host/lib/usrp2_impl.h  2008-12-31 22:19:48 UTC (rev 
10182)
@@ -146,6 +146,7 @@
     double tx_freq_max() { return d_tx_db_info.freq_max; }
     bool set_tx_interp(int interpolation_factor);
     int tx_interp() { return d_tx_interp; }
+    void default_tx_scale_iq(int interpolation_factor, int *scale_i, int 
*scale_q);
     bool set_tx_scale_iq(int scale_i, int scale_q);
 
     bool tx_32fc(unsigned int channel,





reply via email to

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