Discussion and technical support related to USRP, UHD, RFNoC
View all threadsHi there,
I just started using UHD Python API to implement a simple transmission-reception experiment on an Ettus X310. I have a UBX 160 daughterboard installed on slot B, with its TX (TX/RX port) connected to RX (RX2 port) directly using a SMA cable and a 30dB attenuator. I plan to transmit a sequence of waveforms from TX/RX port and to see the waveforms received at the RX2 port. Ideally the two waveforms should be highly similar with some time shift in between, but the received waveforms turned out to be not quite right (see the diagram below, the upper diagram shows the real part of the transmitted waveform and the lower, the real part of the received.).
Some of the parameters are defined as following:duration = 10 # second, the time length of the transmitter sending the waveformscentre_freq=1e8sample_rate=200000num_samples=200000 # number of samples to be collected by the receiving side.gain_tx=0 #dBgain_rx=20
USRP is defined as:usrp = uhd.usrp.MultiUSRP()usrp.set_tx_subdev_spec(uhd.usrp.SubdevSpec("B:0"))usrp.set_tx_antenna("TX/RX")
usrp.set_rx_subdev_spec(uhd.usrp.SubdevSpec("B:0"))usrp.set_rx_antenna("RX2")usrp.set_rx_bandwidth(sample_rate, 0)
As the transmission and the reception happen at the same time, they are put in two separate threads, as below:threads = []rx_thread = threading.Thread(target=receive_data, args=(usrp, num_samples, centre_freq_rx, sample_rate, gain_rx))threads.append(rx_thread)rx_thread.start()tx_thread = threading.Thread(target=usrp.send_waveform, args=(tx_signal, duration, centre_freq_tx, sample_rate, [0], gain_tx))threads.append(tx_thread)tx_thread.start()
Here the function, receive_data() in the first thread, is a user-defined (by me) function, receiving samples using the uhd provided method, usrp.recv_num_samps() and saving the samples to a .txt file. A little more on the data format saved in the file, I used np.savetxt() function to save the samples (a numpy array) to a text file. As the numpy array has a data type of np.complex64, the real and imaginary of the samples are saved in the same file in the format of np.float32. I can confirm that 200000 complex samples were collected in the file saved, which verifies (partially at least) that data format didn't go wrong.
I have been working on this script for a whole day, but couldn't fix it. I suspect I didn't configure the usrp variable correctly. Any suggestions would be appreciated.
Kind regards,Tom
As the transmission and reception happen simultaneously, the Python scritp
Hi Tom,
I’m also starting to use the X310 with Python, and I’d like to share some ideas.
I’ve noticed that even when using threads, some form of synchronization is necessary. This happens because threads are not executed simultaneously, which can cause a time difference between transmission (Tx) and reception (Rx).
It’s important to ensure that the termination of one thread waits for the others to finish. I recommend looking into thread.join() for this purpose. Here’s an introductory example that might be helpful: https://www.youtube.com/watch?v=IEEhzQoKtQU&t=900s Video on threads. This is particularly relevant because when a thread is terminated, the processing returns to the main thread (i.e., the main program), and other ongoing threads might not be properly closed—this issue is especially common on Windows systems.
In addition to threads, you might also want to explore multiprocessing. This approach can be more efficient depending on your use case. Here’s a practical example (in Portuguese): https://www.youtube.com/watch?v=g3PTQ87UvrE&t=103s Video on multiprocessing. There are also plenty of resources available in English that cover this topic.
If you make any progress, please share it with us. It would be great to exchange experiences!
Best regards,
De: Q W via USRP-users usrp-users@lists.ettus.com
Enviada em: quarta-feira, 11 de dezembro de 2024 08:59
Para: Usrp-users Mailing-list usrp-users@lists.ettus.com
Assunto: [USRP-users] UHD Python API
Hi there,
I just started using UHD Python API to implement a simple transmission-reception experiment on an Ettus X310. I have a UBX 160 daughterboard installed on slot B, with its TX (TX/RX port) connected to RX (RX2 port) directly using a SMA cable and a 30dB attenuator. I plan to transmit a sequence of waveforms from TX/RX port and to see the waveforms received at the RX2 port. Ideally the two waveforms should be highly similar with some time shift in between, but the received waveforms turned out to be not quite right (see the diagram below, the upper diagram shows the real part of the transmitted waveform and the lower, the real part of the received.).
Some of the parameters are defined as following:
duration = 10 # second, the time length of the transmitter sending the waveforms
centre_freq=1e8
sample_rate=200000
num_samples=200000 # number of samples to be collected by the receiving side.
gain_tx=0 #dB
gain_rx=20
USRP is defined as:
usrp = uhd.usrp.MultiUSRP()
usrp.set_tx_subdev_spec(uhd.usrp.SubdevSpec("B:0"))
usrp.set_tx_antenna("TX/RX")
usrp.set_rx_subdev_spec(uhd.usrp.SubdevSpec("B:0"))
usrp.set_rx_antenna("RX2")
usrp.set_rx_bandwidth(sample_rate, 0)
As the transmission and the reception happen at the same time, they are put in two separate threads, as below:
threads = []
rx_thread = threading.Thread(target=receive_data, args=(usrp, num_samples, centre_freq_rx, sample_rate, gain_rx))
threads.append(rx_thread)
rx_thread.start()
tx_thread = threading.Thread(target=usrp.send_waveform, args=(tx_signal, duration, centre_freq_tx, sample_rate, [0], gain_tx))
threads.append(tx_thread)
tx_thread.start()
Here the function, receive_data() in the first thread, is a user-defined (by me) function, receiving samples using the uhd provided method, usrp.recv_num_samps() and saving the samples to a .txt file. A little more on the data format saved in the file, I used np.savetxt() function to save the samples (a numpy array) to a text file. As the numpy array has a data type of np.complex64, the real and imaginary of the samples are saved in the same file in the format of np.float32. I can confirm that 200000 complex samples were collected in the file saved, which verifies (partially at least) that data format didn't go wrong.
I have been working on this script for a whole day, but couldn't fix it. I suspect I didn't configure the usrp variable correctly. Any suggestions would be appreciated.
Kind regards,
Tom
As the transmission and reception happen simultaneously, the Python scritp
Tom,
some pointers:
--M
On Wed, Dec 11, 2024 at 12:58 PM Q W via USRP-users <
usrp-users@lists.ettus.com> wrote:
Hi there,
I just started using UHD Python API to implement a simple
transmission-reception experiment on an Ettus X310. I have a UBX 160
daughterboard installed on slot B, with its TX (TX/RX port) connected to RX
(RX2 port) directly using a SMA cable and a 30dB attenuator. I plan to
transmit a sequence of waveforms from TX/RX port and to see the waveforms
received at the RX2 port. Ideally the two waveforms should be highly
similar with some time shift in between, but the received waveforms turned
out to be not quite right (see the diagram below, the upper diagram shows
the real part of the transmitted waveform and the lower, the real part of
the received.).
[image: Inline image]
Some of the parameters are defined as following:
duration = 10 # second, the time length of the transmitter sending the
waveforms
centre_freq=1e8
sample_rate=200000
num_samples=200000 # number of samples to be collected by the receiving
side.
gain_tx=0 #dB
gain_rx=20
USRP is defined as:
usrp = uhd.usrp.MultiUSRP()
usrp.set_tx_subdev_spec(uhd.usrp.SubdevSpec("B:0"))
usrp.set_tx_antenna("TX/RX")
usrp.set_rx_subdev_spec(uhd.usrp.SubdevSpec("B:0"))
usrp.set_rx_antenna("RX2")
usrp.set_rx_bandwidth(sample_rate, 0)
As the transmission and the reception happen at the same time, they are
put in two separate threads, as below:
threads = []
rx_thread = threading.Thread(target=receive_data, args=(usrp, num_samples,
centre_freq_rx, sample_rate, gain_rx))
threads.append(rx_thread)
rx_thread.start()
tx_thread = threading.Thread(target=usrp.send_waveform, args=(tx_signal,
duration, centre_freq_tx, sample_rate, [0], gain_tx))
threads.append(tx_thread)
tx_thread.start()
Here the function, receive_data() in the first thread, is a user-defined
(by me) function, receiving samples using the uhd provided method,
usrp.recv_num_samps() and saving the samples to a .txt file. A little more
on the data format saved in the file, I used np.savetxt() function to save
the samples (a numpy array) to a text file. As the numpy array has a data
type of np.complex64, the real and imaginary of the samples are saved in
the same file in the format of np.float32. I can confirm that 200000
complex samples were collected in the file saved, which verifies (partially
at least) that data format didn't go wrong.
I have been working on this script for a whole day, but couldn't fix it. I
suspect I didn't configure the usrp variable correctly. Any suggestions
would be appreciated.
Kind regards,
Tom
As the transmission and reception happen simultaneously, the Python scritp
USRP-users mailing list -- usrp-users@lists.ettus.com
To unsubscribe send an email to usrp-users-leave@lists.ettus.com
Hi Martin,
Thanks for your suggestions. I have been playing with the script, and just made a progress. One of the issues in my previous script was that the pulse shaped samples which are stored in a numpy array has a data type (i.e. dtype) of np.complex128 which was supposed to be np.complex64. After a conversion to np.complex64, the waveforms looks a lot better (the shape of the received waveforms looks reasonably similar with those transmitted.). I was focusing on the signal processing within the SDR, suspecting there was aliasing or iq imbalance causing the issue, which turned out to be a wrong direction.
Kind regards,Tom
On Thursday 12 December 2024 at 03:05:52 am AEDT, Martin Braun martin.braun@ettus.com wrote:
Tom,
some pointers:
On Wed, Dec 11, 2024 at 12:58 PM Q W via USRP-users usrp-users@lists.ettus.com wrote:
Hi there,
I just started using UHD Python API to implement a simple transmission-reception experiment on an Ettus X310. I have a UBX 160 daughterboard installed on slot B, with its TX (TX/RX port) connected to RX (RX2 port) directly using a SMA cable and a 30dB attenuator. I plan to transmit a sequence of waveforms from TX/RX port and to see the waveforms received at the RX2 port. Ideally the two waveforms should be highly similar with some time shift in between, but the received waveforms turned out to be not quite right (see the diagram below, the upper diagram shows the real part of the transmitted waveform and the lower, the real part of the received.).
Some of the parameters are defined as following:duration = 10 # second, the time length of the transmitter sending the waveformscentre_freq=1e8sample_rate=200000num_samples=200000 # number of samples to be collected by the receiving side.gain_tx=0 #dBgain_rx=20
USRP is defined as:usrp = uhd.usrp.MultiUSRP()usrp.set_tx_subdev_spec(uhd.usrp.SubdevSpec("B:0"))usrp.set_tx_antenna("TX/RX")
usrp.set_rx_subdev_spec(uhd.usrp.SubdevSpec("B:0"))usrp.set_rx_antenna("RX2")usrp.set_rx_bandwidth(sample_rate, 0)
As the transmission and the reception happen at the same time, they are put in two separate threads, as below:threads = []rx_thread = threading.Thread(target=receive_data, args=(usrp, num_samples, centre_freq_rx, sample_rate, gain_rx))threads.append(rx_thread)rx_thread.start()tx_thread = threading.Thread(target=usrp.send_waveform, args=(tx_signal, duration, centre_freq_tx, sample_rate, [0], gain_tx))threads.append(tx_thread)tx_thread.start()
Here the function, receive_data() in the first thread, is a user-defined (by me) function, receiving samples using the uhd provided method, usrp.recv_num_samps() and saving the samples to a .txt file. A little more on the data format saved in the file, I used np.savetxt() function to save the samples (a numpy array) to a text file. As the numpy array has a data type of np.complex64, the real and imaginary of the samples are saved in the same file in the format of np.float32. I can confirm that 200000 complex samples were collected in the file saved, which verifies (partially at least) that data format didn't go wrong.
I have been working on this script for a whole day, but couldn't fix it. I suspect I didn't configure the usrp variable correctly. Any suggestions would be appreciated.
Kind regards,Tom
As the transmission and reception happen simultaneously, the Python scritp _______________________________________________
USRP-users mailing list -- usrp-users@lists.ettus.com
To unsubscribe send an email to usrp-users-leave@lists.ettus.com
USRP-users mailing list -- usrp-users@lists.ettus.com
To unsubscribe send an email to usrp-users-leave@lists.ettus.com
Hi Pav,
Thanks for your suggestions. I have been playing with the script, and just made a progress. One of the issues in my previous script was that the pulse shaped samples which were stored in a numpy array had a data type (i.e. dtype) of np.complex128 which were supposed to be np.complex64. After a conversion to np.complex64, the waveforms looks a lot better (the shape of the received waveforms looks reasonably similar with those transmitted.). I was focusing on the signal processing within the SDR, suspecting there was aliasing or iq imbalance causing the issue, which turned out to be a wrong direction.
I will consider the synchronization in the next step. The join() method for multi-threads works for me. It seems to be me that we can only use multi-threads other than multi-processing when transmitting and receiving at the same time.
Will keep you posted.
Kind regards,Tom
On Thursday 12 December 2024 at 01:08:06 am AEDT, <pav.vieira@gmail.com> wrote:
<!--#yiv1693360780 filtered {}#yiv1693360780 filtered {}#yiv1693360780 filtered {}#yiv1693360780 p.yiv1693360780MsoNormal, #yiv1693360780 li.yiv1693360780MsoNormal, #yiv1693360780 div.yiv1693360780MsoNormal {margin:0cm;font-size:11.0pt;font-family:"Calibri", sans-serif;}#yiv1693360780 a:link, #yiv1693360780 span.yiv1693360780MsoHyperlink {color:#0563C1;text-decoration:underline;}#yiv1693360780 span.yiv1693360780EstiloDeEmail18 {font-family:"Calibri", sans-serif;color:windowtext;}#yiv1693360780 .yiv1693360780MsoChpDefault {font-size:10.0pt;}#yiv1693360780 filtered {}#yiv1693360780 div.yiv1693360780WordSection1 {}-->
Hi Tom,
I’m also starting to use the X310 with Python, and I’d like to share some ideas.
I’ve noticed that even when using threads, some form of synchronization is necessary. This happens because threads are not executed simultaneously, which can cause a time difference between transmission (Tx) and reception (Rx).
It’s important to ensure that the termination of one thread waits for the others to finish. I recommend looking into thread.join() for this purpose. Here’s an introductory example that might be helpful: Video on threads. This is particularly relevant because when a thread is terminated, the processing returns to the main thread (i.e., the main program), and other ongoing threads might not be properly closed—this issue is especially common on Windows systems.
In addition to threads, you might also want to explore multiprocessing. This approach can be more efficient depending on your use case. Here’s a practical example (in Portuguese): Video on multiprocessing. There are also plenty of resources available in English that cover this topic.
If you make any progress, please share it with us. It would be great to exchange experiences!
Best regards,
De: Q W via USRP-users usrp-users@lists.ettus.com
Enviada em: quarta-feira, 11 de dezembro de 2024 08:59
Para: Usrp-users Mailing-list usrp-users@lists.ettus.com
Assunto: [USRP-users] UHD Python API
Hi there,
I just started using UHD Python API to implement a simple transmission-reception experiment on an Ettus X310. I have a UBX 160 daughterboard installed on slot B, with its TX (TX/RX port) connected to RX (RX2 port) directly using a SMA cable and a 30dB attenuator. I plan to transmit a sequence of waveforms from TX/RX port and to see the waveforms received at the RX2 port. Ideally the two waveforms should be highly similar with some time shift in between, but the received waveforms turned out to be not quite right (see the diagram below, the upper diagram shows the real part of the transmitted waveform and the lower, the real part of the received.).
Some of the parameters are defined as following:
duration = 10 # second, the time length of the transmitter sending the waveforms
centre_freq=1e8
sample_rate=200000
num_samples=200000 # number of samples to be collected by the receiving side.
gain_tx=0 #dB
gain_rx=20
USRP is defined as:
usrp = uhd.usrp.MultiUSRP()
usrp.set_tx_subdev_spec(uhd.usrp.SubdevSpec("B:0"))
usrp.set_tx_antenna("TX/RX")
usrp.set_rx_subdev_spec(uhd.usrp.SubdevSpec("B:0"))
usrp.set_rx_antenna("RX2")
usrp.set_rx_bandwidth(sample_rate, 0)
As the transmission and the reception happen at the same time, they are put in two separate threads, as below:
threads = []
rx_thread = threading.Thread(target=receive_data, args=(usrp, num_samples, centre_freq_rx, sample_rate, gain_rx))
threads.append(rx_thread)
rx_thread.start()
tx_thread = threading.Thread(target=usrp.send_waveform, args=(tx_signal, duration, centre_freq_tx, sample_rate, [0], gain_tx))
threads.append(tx_thread)
tx_thread.start()
Here the function, receive_data() in the first thread, is a user-defined (by me) function, receiving samples using the uhd provided method, usrp.recv_num_samps() and saving the samples to a .txt file. A little more on the data format saved in the file, I used np.savetxt() function to save the samples (a numpy array) to a text file. As the numpy array has a data type of np.complex64, the real and imaginary of the samples are saved in the same file in the format of np.float32. I can confirm that 200000 complex samples were collected in the file saved, which verifies (partially at least) that data format didn't go wrong.
I have been working on this script for a whole day, but couldn't fix it. I suspect I didn't configure the usrp variable correctly. Any suggestions would be appreciated.
Kind regards,
Tom
As the transmission and reception happen simultaneously, the Python scritp
USRP-users mailing list -- usrp-users@lists.ettus.com
To unsubscribe send an email to usrp-users-leave@lists.ettus.com