Skip to content

Using the Python API

Benjamin Havens edited this page Jun 6, 2022 · 6 revisions

Preparation

Follow the installation page on this wiki for your platform to install the Python UHD module.

Example: Transmitting a cosine at a frequency offset from the carrier

This has a couple tricks to it. Our initial approach, which worked in MATLAB, did not transmit the proper cosine in python. We had to follow the example from uhd/host/examples/python; using this, we came up with this code to generate the waveform prototype:

# Generator function for low-pass equivalent signal of a cosine
sine = lambda n, freq_offset, rate: exp(n * 2j * pi * freq_offset / rate)

freq_offset = f1 - fc  # Low pass equivalent frequency
n = arange(int(10 * floor(sample_rate / freq_offset)), dtype=complex64)
x_tilde = sine(n, freq_offset, sample_rate)  # One period

We then create a MultiUSRP() object and call send_waveform on it.

Using our code

We made a few changes to the module code itself. They are minute, but allow, at the moment:

  • receiving with different gains on the two channels

To be able to use our receive.py, you must make the following changes.

  • On line 44 and 102 of multi_usrp.py in the ~/uhd/host/python/uhd/usrp folder: change line 44 to read gain=[10, 10], rather than gain=10,. Change line 102 to read super(MultiUSRP, self).set_rx_gain(gain[chan], chan) rather than super(MultiUSRP, self).set_rx_gain(gain, chan). Once this is done, the two channels can have different gains when receiving.