I recently purchased a BladeRF radio defined radio board. It was quite a challenge to get some of the basics working. However, after tweaking and installing and deleting drivers, I finally got it to work. Here's some sample code I found to test it out.

The BladeRF SDR (Software-Defined Radio) board, developed by Nuand, is a highly versatile and powerful tool for radio frequency (RF) communication enthusiasts and professionals. First introduced in 2013, the BladeRF board has garnered attention for its flexibility, performance, and affordability in the world of SDR.

The BladeRF board is designed to cover a wide frequency range, from 300 MHz to 3.8 GHz, making it suitable for a vast array of applications, including cellular communication, satellite reception, and emergency services. Its broad frequency range, combined with its ability to handle various modulation schemes, enables users to explore and experiment with different RF technologies.

One of the standout features of the BladeRF board is its use of a Field-Programmable Gate Array (FPGA) to handle signal processing tasks. This FPGA, coupled with a high-speed USB 3.0 interface, allows for real-time processing of complex signals and data transfer rates up to 5 Gbps. The FPGA's programmability ensures that users can customize and optimize the board for specific applications, making it a highly adaptable tool.

The BladeRF's open-source nature is another key advantage. The board is supported by a comprehensive suite of open-source software tools, including drivers, libraries, and development frameworks. This open-source ecosystem not only fosters a collaborative community but also allows users to modify and enhance the software to meet their specific needs.

In addition to its technical capabilities, the BladeRF board is known for its robust and user-friendly design. The hardware is compact and durable, making it suitable for both lab environments and field deployments. Its straightforward setup and extensive documentation make it accessible to both beginners and experienced users.

The BladeRF has been used in various innovative projects and research initiatives, demonstrating its versatility and reliability. It has become a popular choice for academic institutions, hobbyists, and industry professionals looking to explore the possibilities of SDR.

In summary, the BladeRF SDR board stands out for its wide frequency range, FPGA-based signal processing, high-speed USB 3.0 interface, and robust open-source support. Its adaptability, performance, and user-friendly design have made it a valuable tool for a wide range of RF communication applications.

Below is a sample code in Python that demonstrates how to interact with a BladeRF SDR using the pyblade library. This example sets up the BladeRF device, configures its parameters, and starts transmitting a simple sine wave signal.

First, ensure you have the pyblade library installed. You can install it using pip if you don't have it already:

pip install pyblade

Here is the sample code:

import numpy as np
import pyblade

# Initialize the BladeRF device
dev = pyblade.BladeRF()

# Configure device parameters
dev.frequency = 2.4e9  # Set frequency to 2.4 GHz
dev.samplerate = 1e6   # Set sample rate to 1 MHz
dev.bandwidth = 1e6    # Set bandwidth to 1 MHz
dev.gain = 40          # Set gain to 40 dB

# Create a sine wave signal
duration = 1.0            # Signal duration in seconds
sample_rate = dev.samplerate
t = np.arange(0, duration, 1 / sample_rate)
frequency = 1e3           # Sine wave frequency of 1 kHz
signal = 0.5 * np.sin(2 * np.pi * frequency * t)

# Convert the signal to complex IQ samples
iq_signal = signal + 1j * signal

# Transmit the signal
dev.transmit(iq_signal)

# Stop transmitting after the duration
dev.stop()

# Close the device
dev.close()

print("Transmission complete.")

Here is another example code:

Explanation:

  1. Initialize the BladeRF device: The pyblade.BladeRF() initializes the BladeRF SDR device.
  2. Configure device parameters: You set the frequency, sample rate, bandwidth, and gain for the SDR.
  3. Create a sine wave signal: The code generates a simple 1 kHz sine wave signal for a duration of 1 second.
  4. Convert the signal to IQ samples: The sine wave is converted into complex In-phase (I) and Quadrature (Q) samples, which are necessary for transmission.
  5. Transmit the signal: The dev.transmit(iq_signal) function sends the IQ samples through the SDR.
  6. Stop transmitting: After the signal duration, the transmission is stopped using dev.stop().
  7. Close the device: Finally, the device is closed with dev.close() to clean up resources.

This example demonstrates basic usage of the BladeRF SDR for transmitting a sine wave signal. You can expand this code to include more complex signal processing and handling based on your requirements as seen in the below example.

# -----------------  BladeRF communication with Python 3.7 ----------------------------------------
# -----------------  Developed by: Farzan Farhangian ----------------------------------------------
# -----------------  Email: [email protected] -----------------------------------
# ----------------- Based on: https://github.com/Nuand/bladeRF/wiki -------------------------------
import bladerf
import sys
import numpy as np
from scipy.io import loadmat
from bladerf import _bladerf
import argparse
import csv
import struct
import sys
from   pathlib import Path

def chunked_read( fobj, chunk_bytes = 4*1024 ):
    while True:
        data = fobj.read(chunk_bytes)
        if( not data ):
            break
        else:
            yield data


def bin2csv( binfile = None, csvfile = None, chunk_bytes = 4*1024 ):
    with open(binfile, 'rb') as b:
        with open(csvfile, 'w') as c:
            csvwriter = csv.writer(c, delimiter=',')
            count = 0
            for data in chunked_read(b, chunk_bytes = chunk_bytes):
                count += len(data)
                for i in range(0, len(data), 4):
                    sig_i, = struct.unpack('<h', data[i:i+2])
                    sig_q, = struct.unpack('<h', data[i+2:i+4])
                    csvwriter.writerow( [sig_i, sig_q] )
    print( "Processed", str(count//2//2), "samples." )


d = bladerf.BladeRF()
rx = d.Channel(bladerf.CHANNEL_RX(0))
info=d.get_devinfo()
print(info)
d.set_sample_rate(0, int(2000000))                        # enter your sampling rate in Hz
fs = d.get_sample_rate(0)
print("Sampling rate: {:d} Hz".format(fs))
d.set_frequency(0, int(137500000))                        # enter your center frequency in Hz
f=d.get_frequency(0)
print("Frequency: {:d} Hz".format(f))


rx.frequency = 137500000  # enter your center frequency in Hz
rx.sample_rate = 2000000  # enter your sampling rate in Hz
rx.gain = 1               # enter your gain
d.sync_config(layout=_bladerf.ChannelLayout.RX_X1,
                  fmt=_bladerf.Format.SC16_Q11,
                  num_buffers=16,
                  buffer_size=8192,
                  num_transfers=8,
                  stream_timeout=3500)
rx.enable = True
bytes_per_sample = 4
buf = bytearray(1024*bytes_per_sample)
num_samples_read = 0
num_samples = 200                 # enter number of samples you want to receive
try:
    while True:
        if num_samples > 0 and num_samples_read == num_samples:
            break
        elif num_samples > 0:
            num = min(len(buf)//bytes_per_sample,
                        num_samples-num_samples_read)
        else:
            num = len(buf)//bytes_per_sample

        # Read into buffer
        d.sync_rx(buf, num)
        num_samples_read += num

        # Write to file
        f= open("samples_bin.bin", "wb")
        f.write(buf[:num*bytes_per_sample])
        f.close()
        d.close()
except KeyboardInterrupt:
    pass
# the bin and csv files will be saved in your directory automatically
bin2csv("samples_bin.bin", "samples_scv.csv", chunk_bytes = 4*1024)