Hello all.
I am trying to capture some receiver samples using the Python API of SoapySDR. My code is based on the basic examples of https://github.com/pothosware/SoapySDR/wiki/PythonSupport and https://github.com/pothosware/SoapySDR/blob/master/python/apps/MeasureDelay.py.
In particular I have setup a receive stream active for 10240 samples, and read out bursts of 1024 samples. I am using CF32 precision and store the results in a Numpy Complex64 array. LimeSDR configuration and receive procedure seem to work fine, however when I am trying to see the actual data i get only a few discrete values containing a lot of 0
s and the value -0.000488296151161
. Checkout the attached snapshot:
I am certain that the device is working normally since i’ve tested it using GnuRadio. Initially I was working with the latest master
version, but I got an “NodeMCU error” and downgraded to 17.12-1
.
Has anyone observed similar behavior? I’ll give it a try using the C++ API as well.
Here is my Python code:
import SoapySDR
from SoapySDR import * #SOAPY_SDR_ constants
import numpy as np
import time
import os
#=======================
chan=0
ant='NONE'
gain=8
numSamps = 10240
burstSize = 1024
#=======================
#enumerate devices
results = SoapySDR.Device.enumerate()
for result in results: print(result)
#create device instance
#args can be user defined or from the enumeration result
args = dict(driver="lime")
sdr = SoapySDR.Device(args)
#query device info
print (sdr.listAntennas(SOAPY_SDR_RX, chan))
print "============================================="
#apply settings
sdr.setMasterClockRate(30.72e6)
print("Actual Master Clock Rate %f Msps"%(sdr.getMasterClockRate()/1e6))
sdr.setSampleRate(SOAPY_SDR_RX, chan, 1.92e6)
print("Actual Rx Rate %f Msps"%(sdr.getSampleRate(SOAPY_SDR_RX, chan)/1e6))
sdr.setFrequency(SOAPY_SDR_RX, chan, 1.9e9)
print("Actual Rx Freq %f MHz"%(sdr.getFrequency(SOAPY_SDR_RX, chan)/1e6))
sdr.setAntenna(SOAPY_SDR_RX,chan,ant)
print("Antenna on Channel %i is %s"%(chan,sdr.getAntenna(SOAPY_SDR_RX,chan)))
sdr.setGain(SOAPY_SDR_RX,chan,gain)
print("Actual Rx Gain %f "%(sdr.getGain(SOAPY_SDR_RX, chan)))
#sdr.setBandwidth(SOAPY_SDR_RX, chan, 3.84e6)
#print("Actual Rx BW MHz %f "%(sdr.getBandwidth(SOAPY_SDR_RX, chan)/1e6))
#sampleRates = sdr.getSampleRateRange(SOAPY_SDR_RX, chan)
#for srRange in sampleRates: print(srRange)
print "============================================="
#create rx stream
rxStream = sdr.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32, [chan])
#let things settle
time.sleep(1)
#start streaming
sdr.activateStream(rxStream, 0, 0, numSamps)
# buffer for storing accumulated samples
rxBuffs = np.array([], np.complex64)
#create a re-usable buffer for rx samples
rxBuff = np.array([0]*burstSize, np.complex64)
#receive some samples
while True:
sr = sdr.readStream(rxStream, [rxBuff], len(rxBuff))
print(sr.ret) #num samples or error code
#stash time on first buffer
if sr.ret > 0 and len(rxBuffs) == 0:
rxTime0 = sr.timeNs
if (sr.flags & SOAPY_SDR_HAS_TIME) == 0:
raise Exception('receive fail - no timestamp on first readStream %s'%(str(sr)))
#accumulate buffer or exit loop
if sr.ret > 0:
rxBuffs = np.concatenate((rxBuffs, rxBuff[:sr.ret]))
else: break
#cleanup streams
print("Cleanup streams")
sdr.deactivateStream(rxStream) #stop streaming
sdr.closeStream(rxStream)
# process data
print len(rxBuffs)
print("Captured %i samples in total"%(len(rxBuffs)))
print np.real(rxBuffs[10000]),np.real(rxBuffs[10001]),np.real(rxBuffs[10002])
# dump samples
#np.savetxt('outfile.txt', rxBuffs,'%.10f\t%.10f')