summaryrefslogtreecommitdiff
path: root/usrp2/host
diff options
context:
space:
mode:
Diffstat (limited to 'usrp2/host')
-rw-r--r--usrp2/host/include/usrp2/usrp2.h5
-rw-r--r--usrp2/host/lib/usrp2.cc6
-rw-r--r--usrp2/host/lib/usrp2_impl.cc37
-rw-r--r--usrp2/host/lib/usrp2_impl.h1
4 files changed, 44 insertions, 5 deletions
diff --git a/usrp2/host/include/usrp2/usrp2.h b/usrp2/host/include/usrp2/usrp2.h
index 82b1c6449..39da63aa5 100644
--- a/usrp2/host/include/usrp2/usrp2.h
+++ b/usrp2/host/include/usrp2/usrp2.h
@@ -219,6 +219,11 @@ namespace usrp2 {
//! 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
*/
diff --git a/usrp2/host/lib/usrp2.cc b/usrp2/host/lib/usrp2.cc
index 2a7fe5963..90a31b220 100644
--- a/usrp2/host/lib/usrp2.cc
+++ b/usrp2/host/lib/usrp2.cc
@@ -309,6 +309,12 @@ namespace usrp2 {
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)
{
diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc
index 04f50f480..2aa430138 100644
--- a/usrp2/host/lib/usrp2_impl.cc
+++ b/usrp2/host/lib/usrp2_impl.cc
@@ -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 @@ namespace usrp2 {
// 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 @@ namespace usrp2 {
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)
{
diff --git a/usrp2/host/lib/usrp2_impl.h b/usrp2/host/lib/usrp2_impl.h
index 0400a108b..b332d65d2 100644
--- a/usrp2/host/lib/usrp2_impl.h
+++ b/usrp2/host/lib/usrp2_impl.h
@@ -146,6 +146,7 @@ namespace usrp2 {
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,