Advertisement
Guest User

Untitled

a guest
Aug 11th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. import SoapySDR
  2. from SoapySDR import * #SOAPY_SDR_ constants
  3. from SoapySDR import SOAPY_SDR_RX, SOAPY_SDR_CF32, SOAPY_SDR_CS16
  4. import numpy as np
  5. import time
  6. import os
  7. import pickle
  8.  
  9. import numpy as no
  10. import matplotlib.pyplot as plt
  11. import scipy.fftpack
  12. from numpy import array, ndarray
  13.  
  14. #import web_pdb; web_pdb.set_trace() #Start web debugger session
  15.  
  16. #=======================
  17. #SDR Tuning
  18. freq= 4995e5
  19. sampRate = 10e6
  20. bandwidth = 10e6
  21. #SDR Settings
  22. chan= 0
  23. ant= 'LNAL' #Use 'SoapySDRUtil --probe' to discover your devices antenna choices
  24. gain= 0
  25. #Stream Parameters
  26. numSamps = 4096 * 4
  27. burstSize = 4096 * 4
  28. numStreams = 10 #how many times readStream() is called
  29. #=======================
  30.  
  31. #enumerate devices
  32. results = SoapySDR.Device.enumerate()
  33. for result in results: print(result)
  34.  
  35. #create device instance
  36. #args can be user defined or from the enumeration result
  37. #Change driver to use Soapy device of your choice
  38. #SoapyRemote arguments should be added to setupStream()
  39. args = dict(driver="lime", loglvl="2")
  40. sdr = SoapySDR.Device(args)
  41.  
  42. #query device info
  43. print (sdr.listAntennas(SOAPY_SDR_RX, chan))
  44.  
  45. print ("=============================================")
  46. sdr.setSampleRate(SOAPY_SDR_RX, chan, sampRate)
  47. print("Actual Rx Rate %f Msps"%(sdr.getSampleRate(SOAPY_SDR_RX, chan)/1e6))
  48.  
  49. sdr.setFrequency(SOAPY_SDR_RX, chan, freq)
  50. print("Actual Rx Freq %f MHz"%(sdr.getFrequency(SOAPY_SDR_RX, chan)/1e6))
  51.  
  52. sdr.setAntenna(SOAPY_SDR_RX,chan,ant)
  53. print("Antenna on Channel %i is %s"%(chan,sdr.getAntenna(SOAPY_SDR_RX,chan)))
  54.  
  55. sdr.setGain(SOAPY_SDR_RX,chan,gain)
  56. print("Actual Rx Gain %f "%(sdr.getGain(SOAPY_SDR_RX, chan)))
  57.  
  58. sdr.setBandwidth(SOAPY_SDR_RX, chan, bandwidth)
  59. print("Actual Rx BW MHz %f "%(sdr.getBandwidth(SOAPY_SDR_RX, chan)/1e6))
  60. print ("=============================================")
  61.  
  62. #create rx stream
  63. rxStream = sdr.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32, [chan])
  64.  
  65. #let things settle
  66. time.sleep(1)
  67.  
  68. #start streaming
  69. sdr.activateStream(rxStream, 0, 0, numSamps)
  70.  
  71. #create a re-usable buffer for rx samples
  72. rxBuff = np.array([0]*burstSize, np.complex64)
  73.  
  74. #Read some short buffers to flush the pipeline
  75. mtu_size = sdr.getStreamMTU(rxStream)
  76. for i in range(4):
  77. sr = sdr.readStream(rxStream, rxBuff, mtu_size)
  78.  
  79. #Receive our actual data
  80. for i in range(numStreams):
  81. sr = sdr.readStream(rxStream, [rxBuff], burstSize)
  82. print(rxBuff)
  83.  
  84. #Dump raw data into file for testing
  85. np.ndarray.tofile(rxBuff, 'SDRdatadump.txt', "")
  86. # data = {'buffers':rxBuff}
  87. # with open('test1.txt','wb') as fd:
  88. # pickle.dump( data, fd )
  89.  
  90. #Cleanup and close our stream/s
  91. print("Cleanup streams\n")
  92. sdr.deactivateStream(rxStream)
  93. sdr.closeStream(rxStream)
  94.  
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement