From 5bf73ca209108e2ce8f3919d453050d957212779 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Wed, 11 Nov 2015 22:01:36 +0100 Subject: Fix correlation, add keys for usrp gain --- AlignSample.cpp | 14 +------------- OutputUHD.cpp | 18 ++++++++++++++++++ OutputUHD.hpp | 3 +++ main.cpp | 33 +++++++++++++++++++++++++++++++-- pointcloud.cpp | 15 +++++++++++---- pointcloud.hpp | 4 +++- 6 files changed, 67 insertions(+), 20 deletions(-) diff --git a/AlignSample.cpp b/AlignSample.cpp index 50b818e..4f5a8eb 100644 --- a/AlignSample.cpp +++ b/AlignSample.cpp @@ -186,7 +186,7 @@ CorrelationResult AlignSample::crosscorrelate(size_t len) tx_fft_plan.execute(); for (size_t i = 0; i < len; i++) { - ifft_in[i] = rx_fft_out[i] * std::conj(tx_fft_out[i]); + ifft_in[i] = tx_fft_out[i] * std::conj(rx_fft_out[i]); } ifft_plan.execute(); @@ -195,18 +195,6 @@ CorrelationResult AlignSample::crosscorrelate(size_t len) result.correlation[i] = ifft_out[i]; } -#if 0 - // Calculate correlation - for (size_t offset = 0; offset < max_offset; offset++) { - complexf xcorr(0, 0); - - for (size_t i = 0; i < len; i++) { - xcorr += rxsamps[i]/rx_power_f * std::conj(txsamps[i+offset])/tx_power_f; - } - result.correlation[offset] = xcorr; - } -#endif - return result; } diff --git a/OutputUHD.cpp b/OutputUHD.cpp index 9536ebd..255f63f 100644 --- a/OutputUHD.cpp +++ b/OutputUHD.cpp @@ -136,3 +136,21 @@ ssize_t OutputUHD::Receive(complexf *samples, size_t sizeIn, double *first_sampl return num_rx_samps; } +void OutputUHD::SetTxGain(double gain) +{ + m_txgain = gain; + + MDEBUG("OutputUHD:Setting TX Gain: %f ...\n", m_txgain); + m_usrp->set_tx_gain(m_txgain); + MDEBUG("OutputUHD:Actual TX Gain: %f ...\n", m_usrp->get_tx_gain()); +} + +void OutputUHD::SetRxGain(double gain) +{ + m_rxgain = gain; + + MDEBUG("OutputUHD:Setting RX Gain: %f ...\n", m_rxgain); + m_usrp->set_rx_gain(m_rxgain); + MDEBUG("OutputUHD:Actual RX Gain: %f ...\n", m_usrp->get_rx_gain()); +} + diff --git a/OutputUHD.hpp b/OutputUHD.hpp index b3169c6..b0288b8 100644 --- a/OutputUHD.hpp +++ b/OutputUHD.hpp @@ -36,6 +36,9 @@ class OutputUHD { size_t Transmit(const complexf *samples, size_t sizeIn, double transmit_time); ssize_t Receive(complexf *samples, size_t sizeIn, double *first_sample_time); + void SetTxGain(double gain); + void SetRxGain(double gain); + private: double m_txgain; double m_rxgain; diff --git a/main.cpp b/main.cpp index 46137f7..ee12d0a 100644 --- a/main.cpp +++ b/main.cpp @@ -94,9 +94,11 @@ size_t do_receive(OutputUHD* output_uhd) const size_t correlation_length = 16 * 1024; // 8ms at 2048000 +long user_delay = 0; + void push_to_point_cloud(size_t rx_delay) { - auto points = aligner.get_samples(correlation_length, rx_delay); + auto points = aligner.get_samples(correlation_length, rx_delay + user_delay); if (points.first.size() > 0) { cloud.push_samples(points); @@ -332,7 +334,34 @@ int main(int argc, char **argv) total_samps_read += samps_read; try { - cloud.handle_event(); + std::string keyname = cloud.handle_event(); + if (keyname == "l") { + user_delay += 1; + std::cerr << "User delay: " << user_delay << std::endl; + } + else if (keyname == "e") { + user_delay -= 1; + std::cerr << "User delay: " << user_delay << std::endl; + } + else if (keyname == "z") { + rxgain -= 1; + output_uhd.SetRxGain(rxgain); + } + else if (keyname == "a") { + rxgain += 1; + output_uhd.SetRxGain(rxgain); + } + else if (keyname == "x") { + txgain -= 1; + output_uhd.SetTxGain(txgain); + } + else if (keyname == "s") { + txgain += 1; + output_uhd.SetTxGain(txgain); + } + else if (not keyname.empty()) { + std::cerr << "Press L for later, E for earlier, Z/A to decrease/increase RX gain, X/S for TX gain" << std::endl; + } } catch (sdl_quit &e) { running = false; diff --git a/pointcloud.cpp b/pointcloud.cpp index 417c31c..7c92d16 100644 --- a/pointcloud.cpp +++ b/pointcloud.cpp @@ -96,9 +96,10 @@ void PointCloud::push_samples(std::pair, std::vector arg_tx) { - int corr = 255 - 10 * (arg_rx - arg_tx); + int corr = 255 - 20 * (arg_rx - arg_tx); if (corr < 0) { corr = 0; @@ -107,7 +108,7 @@ void PointCloud::push_samples(std::pair, std::vector, std::vector, std::vector > &data); -- cgit v1.2.3