Saving Signal to npy File
Posted: Thu Jun 15, 2023 11:35 am
I'm trying to receive a signal and save it into a npy file using the bladeRF in python. I've been using host/examples/python/txrx/txrx.py from the bladeRF github, and I've tried many different ways to modify the below code (from txrx.py) to save the data as npy, but I'm unable to convert from bytearray to np array, and when I converted into a python list, the values were all real numbers from 0-255.
I also tried using np.fromfile to convert the bin file created by txrx.py into a npy file, but I get NaN values when I use that method.
So, how can I receive a signal from the bladeRF and write it to a npy file in python? Additionally, how do I save the metadata into the npy file? I know I'll need to use bladerf format SC16_Q11_META in device.sync_config, but again, I don't know how to properly save it into the npy file.
Thanks!
Code: Select all
# Create receive buffer
bytes_per_sample = 4
buf = bytearray(1024*bytes_per_sample)
num_samples_read = 0
# Tell TX thread to begin
if( tx_start != None ):
tx_start.set()
# Save the samples
with open(rxfile, 'wb') as outfile:
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
device.sync_rx(buf, num)
num_samples_read += num
# Write to file
outfile.write(buf[:num*bytes_per_sample])
So, how can I receive a signal from the bladeRF and write it to a npy file in python? Additionally, how do I save the metadata into the npy file? I know I'll need to use bladerf format SC16_Q11_META in device.sync_config, but again, I don't know how to properly save it into the npy file.
Thanks!