Setting Up GNU Radio & Python with Ettus SDR on Ubuntu 22.04

A software-defined radio (SDR) is not a radio in the traditional sense. Instead of fixed analog components with limited range and ability, an SDR is programmable and highly flexible. Referred to as either SDR or USRP (Universal Software Radio Peripheral), it primarily consists of an FPGA or microcontroller, analog-to-digital and digital-to-analog converters, and a radio frequency (RF) transceiver. Combined, they implement traditional components, like the local oscillator for tuning, the mixer to translate or shift frequencies up or down, and modulation/demodulation for encoding and decoding. Implementing an SDR in programmable circuitry dramatically reduces costs, increases performance, and allows greater flexibility. It is a platform for learning and experimenting with all aspects of radio. 

The following article describes how to install GNU Radio in Ubuntu 22.04. GNU Radio is a block-based programming environment that connects blocks to form a flowgraph program. Instead of writing lines of code, you use higher-level blocks, making it easier to construct a program. Also discussed is installing the SDR board universal hardware driver, UHD, and firmware.  

In the last section, we will build and install the UHD Python module and demonstrate using it. 

The Ettus B200 radio features two channels: one full duplex transmit/receive and a receive only. The B200mini and B205 have two channels, one for receiving signals and the other for transmitting. They have a frequency range of 70 MHz to 6 GHz, a bandwidth of 56 MHz, and USB 3.0 SuperSpeed connectivity. No external power is needed. It features a Spartan 6 FPGA coupled to an Analog Devices 9364 transceiver with built-in 12-bit A/D and D/A converters, elevating the need for separate chips. The maximum sample rate is 61.44 MS/s. The board’s control firmware is held in volatile memory and is loaded upon initial connection. Getting an update is as easy as running the downloader program. 

The B200 antenna connection requires a male SMA antenna connector. When choosing an antenna, please do not confuse it with the male RP-SMA connector. They are not the same. The male SMA has a visible center pin. The RP-SMA does not. A right-angle SMA adapter can be used to change the antenna orientation. 

Sidebar: Dual-Booting Linux on a Windows System

If you are not lucky enough to have a Linux computer handy, converting a Windows computer to run both Linux and Windows is easy. If you require a step-by-step description, I found plenty of online information about making a dual-boot Windows–Linux system. The following outlines my procedure to install Linux from a USB flash drive.

1. Configure the computer’s system bios program so that the computer’s boot sequence will attempt to boot from USB before anything else.

2. Use the Windows Disk Management tool to shrink the main disk drive enough to fit a copy of Linux plus extra room for software. 50 GB should do.

3. Download the Ubuntu 22.04.3 LTS ISO image file. Once this has been done, use a tool like balenaEtcher to put the ISO image onto the USB drive. Do not use File Explorer to copy the ISO image to the USB drive.

With the steps above completed, insert the USB flash drive into the USB port, restart it, and wait for installation options to appear on the screen. Select Install Ubuntu to begin the process. Choose the minimum configuration and download third-party drivers. The process will ask you to create an account with a password. When complete, you will be confronted with a boot menu allowing you to choose between Ubuntu or Windows. Ensure that you have the most up-to-date support. Usually, a prompt will appear shortly after booting Linux, but you could also use Software & Updates found in Show Applications. This will ensure the most up-to-date USB support. Otherwise, you could experience USRP communication issues such as a buffer overrun condition.

In the following sections we will do the following: 

  1. Install GNU Radio  
  2. Install UHD (USRP Hardware Driver) tools and drivers.
  3. Download the device firmware, which is loaded dynamically when first initialized. 

        Log into Linux and start by launching a (bash) terminal. Enter the commands listed below in bold. The dollar sign ($) is used as a generic command prompt.  

        Install the GNU Radio software:

        $ sudo apt-get install -y gnuradio 

        Install Ettus UHD (Universal Hardware Driver) support:

        $ sudo apt-get install -y uhd-host 

         Download the firmware images for Ettus boards: 

        $ sudo /usr/lib/uhd/utils/ 

        Plug your b200 into a USB 3.0 port and then use the following command to locate and display information about it:

        $ uhd_find_devices 


        Sample Output: 

        [INFO] [UHD] linux; GNU C++ version 11.2.0; Boost_107400; UHD_4.1.0.5-3 

        [INFO] [B200] Loading firmware image: /usr/share/uhd/images/usrp_b200_fw.hex… 


        — UHD Device 0 


        Device Address: 

        serial: XXXXXXXX 

        name: MyB200 

        product: B200 

        type: b200 

        You can use your Linux desktop interface to start GNU Radio or enter the following command. 

        $ gnuradio-companion & 

        Load the following GNU Radio flowgraph (FM93.3.grc). It programs the SDR to tune in to FM 93.3. If your area does not have a 93.3 FM station, modify the ‘freq’ parameter at the bottom of the screen to change the station. It is recommended not to set the radio’s center frequency to match the radio. If the station is at 96.0 MHz, modify the ‘center_freq’ parameter to 94 MHz. By default, the volume is set low. Move the ‘volume’ slider (top of the screen) to make it louder.  


        Additional information about GNU Radio can be found at here.  

        Now that GNU Radio is working and we can tune in to a radio station, we can do the same with Python instead. Use the following commands to install the Python module:

        $ sudo apt-get install -y python3-uhd 

        Start Python and enter the commands below to test if Python will detect  the b200

        $ python3
        import uhd 
        usrp = uhd.usrp.MultiUSRP()

        The output should indicate the device is detected like the following output. 

        We can plot the USRP output like the GNU Radio Flowgraph example with the following Python script. Copy the code below into IDLE to plot the FFT response center from the B200 centered at 96 MHz

        import uhd
        import numpy as np
        import matplotlib.pyplot as plt
        usrp = uhd.usrp.MultiUSRP()
        N = 4096
        center_freq = 96e6 # Radio Center Frequency in Hz
        rate = 8e6         # Sample Rate in S/s or Hz
        gain = 30          # dB
        usrp.set_rx_rate(rate, 0)
        usrp.set_rx_freq(uhd.types.TuneRequest(center_freq), 0)
        usrp.set_rx_antenna('RX2', 0)
        usrp.set_rx_gain(gain, 0)
        # Set up the stream and receive buffer
        st_args = uhd.usrp.StreamArgs('fc32', 'sc16')
        st_args.channels = [0]
        metadata = uhd.types.RXMetadata()
        streamer = usrp.get_rx_stream(st_args)
        recv_buffer = np.zeros((1, N), dtype=np.complex64)
        # Start Stream
        stream_cmd = uhd.types.StreamCMD(uhd.types.StreamMode.start_cont)
        stream_cmd.stream_now = True
        # Receive Samples
        samples = np.zeros(N, dtype=np.complex64)
        streamer.recv(recv_buffer, metadata)
        samples[0:N] = recv_buffer[0]
        # Stop Stream
        stream_cmd = uhd.types.StreamCMD(uhd.types.StreamMode.stop_cont)
        fft = np.abs(np.fft.fft(samples))**2 / (N*rate)
        log = 10.0*np.log10(fft)
        shifted = np.fft.fftshift(log)
        f = np.arange(center_freq + rate/-2.0, center_freq+rate/2.0, rate/N)
        plt.plot(f, shifted)
        plt.xlabel("Frequency [Hz]")
        plt.ylabel("Magnitude [dB]")

        Our guide equipped you to install GNU Radio and Ettus UHD on Linux, providing a springboard for exploring Software Defined Radio (SDR). While tuning an FM radio station is a great starting point, GNU Radio and UHD offer much more. Dive deeper into signal processing, develop custom applications, and unlock the potential of the radio spectrum. 



        Leave a Reply

        Your email address will not be published. Required fields are marked *