Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SoapySDR
- from SoapySDR import * #SOAPY_SDR_ constants
- from SoapySDR import SOAPY_SDR_RX, SOAPY_SDR_CF32, SOAPY_SDR_CS16
- import numpy as np
- import time
- import os
- import pickle
- import numpy as no
- import matplotlib.pyplot as plt
- import scipy.fftpack
- from numpy import array, ndarray
- #import web_pdb; web_pdb.set_trace() #Start web debugger session
- #=======================
- #SDR Tuning
- freq= 4995e5
- sampRate = 10e6
- bandwidth = 10e6
- #SDR Settings
- chan= 0
- ant= 'LNAL' #Use 'SoapySDRUtil --probe' to discover your devices antenna choices
- gain= 0
- #Stream Parameters
- numSamps = 4096 * 4
- burstSize = 4096 * 4
- numStreams = 10 #how many times readStream() is called
- #=======================
- #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
- #Change driver to use Soapy device of your choice
- #SoapyRemote arguments should be added to setupStream()
- args = dict(driver="lime", loglvl="2")
- sdr = SoapySDR.Device(args)
- #query device info
- print (sdr.listAntennas(SOAPY_SDR_RX, chan))
- print ("=============================================")
- sdr.setSampleRate(SOAPY_SDR_RX, chan, sampRate)
- print("Actual Rx Rate %f Msps"%(sdr.getSampleRate(SOAPY_SDR_RX, chan)/1e6))
- sdr.setFrequency(SOAPY_SDR_RX, chan, freq)
- 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, bandwidth)
- print("Actual Rx BW MHz %f "%(sdr.getBandwidth(SOAPY_SDR_RX, chan)/1e6))
- 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)
- #create a re-usable buffer for rx samples
- rxBuff = np.array([0]*burstSize, np.complex64)
- #Read some short buffers to flush the pipeline
- mtu_size = sdr.getStreamMTU(rxStream)
- for i in range(4):
- sr = sdr.readStream(rxStream, rxBuff, mtu_size)
- #Receive our actual data
- for i in range(numStreams):
- sr = sdr.readStream(rxStream, [rxBuff], burstSize)
- print(rxBuff)
- #Dump raw data into file for testing
- np.ndarray.tofile(rxBuff, 'SDRdatadump.txt', "")
- # data = {'buffers':rxBuff}
- # with open('test1.txt','wb') as fd:
- # pickle.dump( data, fd )
- #Cleanup and close our stream/s
- print("Cleanup streams\n")
- sdr.deactivateStream(rxStream)
- sdr.closeStream(rxStream)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement