本文整理匯總了Python中rtlsdr.RtlSdr類的典型用法代碼示例。如果您正苦於以下問題:Python RtlSdr類的具體用法?Python RtlSdr怎麽用?Python RtlSdr使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了RtlSdr類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Rtl_threading
class Rtl_threading(threading.Thread):
def __init__(self, addr, fc, fs, size, corr):
'''Add one more augument, corr'''
threading.Thread.__init__(self)
self.sdr = RtlSdr(addr)
# configure device
self.sdr.sample_rate = fs; # Hz
self.sdr.center_freq = fc; # Hz
# self.freq_correction = corr; # PPM
if addr==1:
self.sdr.gain = 32.8
else: #0
self.sdr.gain = 32.8
# init param
self.addr = addr;
self.size = size
self.counter = 0;
#0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6
def run(self):
# start lock to avoid reading the same data
global event, output; #init the synchronization
if event.isSet():
event.clear()
event.wait()
else:
event.set()
output[self.addr] = self.sdr.read_samples(self.size);
def close(self):
self.sdr.close();
示例2: main
async def main():
import math
sdr = RtlSdr()
print('Configuring SDR...')
sdr.rs = 2.4e6
sdr.fc = 100e6
sdr.gain = 10
print(' sample rate: %0.6f MHz' % (sdr.rs/1e6))
print(' center frequency %0.6f MHz' % (sdr.fc/1e6))
print(' gain: %d dB' % sdr.gain)
print('Streaming samples...')
i = 0
async for samples in sdr.stream():
power = sum(abs(s)**2 for s in samples) / len(samples)
print('Relative power:', 10*math.log10(power), 'dB')
i += 1
if i > 100:
sdr.stop()
break
print('Done')
sdr.close()
示例3: main
def main():
sdr = RtlSdr()
print 'Configuring SDR...'
sdr.rs = 2.4e6
sdr.fc = 100e6
sdr.gain = 10
print ' sample rate: %0.6f MHz' % (sdr.rs/1e6)
print ' center frequency %0.6f MHz' % (sdr.fc/1e6)
print ' gain: %d dB' % sdr.gain
print 'Reading samples...'
samples = sdr.read_samples(256*1024)
print ' signal mean:', sum(samples)/len(samples)
print 'Testing callback...'
sdr.read_samples_async(test_callback, 256*1024)
try:
import pylab as mpl
print 'Testing spectrum plotting...'
mpl.figure()
mpl.psd(samples, NFFT=1024, Fc=sdr.fc/1e6, Fs=sdr.rs/1e6)
mpl.show()
except:
# matplotlib not installed/working
pass
print 'Done\n'
sdr.close()
示例4: __init__
class SDR:
def __init__(self,freq):
self.sample_rate = 1e6
self.center_freq = freq
self.gain = 36
self.sdr = RtlSdr()
self.sdr.direct_sampling = 1
self.sdr.sample_rate = self.sample_rate
self.sdr.center_freq = self.center_freq
self.sdr.gain = self.gain
def __del__(self):
self.sdr.close()
示例5: get_sdr
def get_sdr():
sdr = RtlSdr()
#configure device
#sdr.sample_rate = 2.048e6 #Hz
#sdr.center_freq = 70e6 #Hz
#sdr.freq_correction = 60 # PPM
#sdr.gain = 'auto'
sdr.sample_rate = 200000
sdr.center_freq = 907 * 1000 * 1000
sdr.freq_correction = 60 # PPM
sdr.gain = 'auto'
return sdr
示例6: Rtl_threading
class Rtl_threading(threading.Thread):
def __init__(self, addr, fc, fs, size, times, corr):
threading.Thread.__init__(self)
self.sdr = RtlSdr(addr)
# configure device
self.sdr.sample_rate = fs
# Hz
self.sdr.center_freq = fc
# Hz
# self.freq_correction = corr; # PPM
self.gain_index = 21
# self.sdr.gain='auto'
# 36.4 the stdev=0.04
# init param
self.addr = addr
self.size = size
self.times = times
self.counter = 0
self.output = np.array(maxn * [0.0], dtype=np.float64)
self.keep = True
def run(self):
# start lock to avoid reading the same data
# self.tlock.acquire()
while self.keep:
self.sdr.gain = gain_list[self.gain_index]
output = self.sdr.read_samples(self.size)
self.output = output
time.sleep(0.05)
示例7: __init__
def __init__(self,freq,N_samples):
self.sample_rate = 1e6
self.decim_r1 = 1e6/2e5 # for wideband fm
self.decim_r2 = 2e5/44100 # for baseband recovery
self.center_freq = freq+250e3
self.gain = 36
self.N_samples = N_samples
self.sdr = RtlSdr()
self.sdr.direct_sampling = 1
self.sdr.sample_rate = self.sample_rate
self.sdr.center_freq = self.center_freq
self.sdr.gain = 'auto' #self.gain
self.pa = pyaudio.PyAudio()
self.stream = self.pa.open( format = pyaudio.paFloat32,
channels = 2,
rate = 44100,
output = True)
adj = 0
hamming = 10*signal.hamming(self.N_samples*.10 + adj)
lpf = np.append( np.zeros(self.N_samples*.45),hamming)
self.lpf = np.roll(np.fft.fftshift(np.append(lpf,np.zeros(self.N_samples*.45))),int(-.25*self.N_samples))
示例8: transmit_and_capture
def transmit_and_capture(data, outfile, length, title='Captured Data', verbose=False, fs_audio=48000, fs_sdr=240000, fc0=443.650e6, plot=False):
"""Transmit and receive a signal.
length seconds
"""
sdr = RtlSdr() # Create an RtlSdr object
p = pyaudio.PyAudio() # Create a PyAudio object
Nsamples=256000*length
fc = fc0*(1.0-85e-6)
# Get device numbers
din, dout, dusb = audio_dev_numbers(p, in_name='USB', out_name='default', debug=verbose)
# Create SDR capture thread as daemon
capture = threading.Thread(target=sdr_record, args=(sdr, outfile, Nsamples, fc, fs_sdr))
capture.daemon = True
# Create play thread as daemon
play = threading.Thread(target=play_audio, args=(data, p, fs_audio, dusb))
play.daemon = True
# Start both threads
capture.start()
play.start()
time.sleep(length+2)
try:
if plot:
print 'Loading data...'
y = np.load(outfile)
print 'Generating plot...'
tt,ff,xmf = myspectrogram_hann_ovlp(y, 256, fs_sdr, fc)
plt.title(title)
plt.show()
else:
print 'Captured data saved to ' + outfile
except IOError:
type, value, traceback = sys.exc_info()
print('Error loading %s: %s' % (value.filename, value.strerror))
except Exception as e:
print 'Error: '+str(e)
finally:
print 'Cleaning up...'
sdr.close()
p.terminate()
print 'Closed SDR and PyAudio'
示例9: __init__
def __init__(self):
self.sdr = RtlSdr()
# Sampling rate
self.sdr.rs = Demod.SAMP_RATE
# Pins 1 and 2
self.sdr.set_direct_sampling(1)
# I don't think this is used?
self.sdr.gain = 1
示例10: __init__
def __init__(self,freq,N_samples):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.createQtConnections()
self.sample_rate = 2.4e5 ###1e6
#self.decim_r1 = 1e6/2e5 # for wideband fm
self.decim_r2 = 2.4e5/48000 # for baseband recovery
self.center_freq = freq #+250e3
self.gain = 38
self.N_samples = N_samples
self.is_sampling = False
self.spectrogram = np.zeros((328,200))
self.chspectrogram = np.zeros((328,200))
self.plspectrogram = np.zeros((164,200))
self.sdr = RtlSdr()
#self.sdr.direct_sampling = 1
self.sdr.sample_rate = self.sample_rate
self.sdr.center_freq = self.center_freq
self.sdr.gain = self.gain
self.pa = pyaudio.PyAudio()
self.stream = self.pa.open( format = pyaudio.paFloat32,
channels = 2,
rate = 48000,
output = True)
adj = 0
hamming = np.kaiser(self.N_samples/4 + adj,1)
lpf = np.append( np.zeros(self.N_samples*3/8),hamming)
self.lpf = np.fft.fftshift(np.append(lpf,np.zeros(self.N_samples*3/8))) #,int(-.25*self.N_samples))
hamming = 10*signal.hamming(self.N_samples/16)
lpf = np.append(np.zeros(self.N_samples*15/32),hamming)
self.lpf_s1 = (np.append(lpf,np.zeros(int(self.N_samples*15/32))))
#self.lpf_s1 = np.roll(temp,int(.5*self.N_samples*67/120))
#self.lpf_s1 += np.roll(temp,int(-.5*self.N_samples*67/120))
self.lpf_s1 = np.fft.fftshift(self.lpf_s1)
#self.lpf_s1 += np.fft.fftshift(self.lpf_s1)
# fig = plt.figure()
# ax = fig.add_subplot(111)
# ax.plot(range(self.lpf_s1.size),self.lpf_s1)
# fig.show()
hamming = 10*signal.hamming(self.N_samples/32)
lpf = np.append(np.zeros(self.N_samples*31/64),hamming)
self.lpf_s2 = (np.append(lpf,np.zeros(int(self.N_samples*31/64))))
#self.lpf_s2 = np.roll(temp,int(.5*self.N_samples*92/120))
#self.lpf_s2 += np.roll(temp,int(-.5*self.N_samples*92/120))
self.lpf_s2 = np.fft.fftshift(self.lpf_s2)
示例11: device_index
def device_index(self):
i = getattr(self, '_device_index', None)
if i is None:
serial_number = self.device_config.serial_number
if serial_number is None:
i = 0
else:
i = RtlSdr.get_device_index_by_serial(serial_number)
self._device_index = i
return i
示例12: main
def main():
sdr = RtlSdr()
wf = Waterfall(sdr)
# some defaults
# Sample rate
sdr.rs = 1e6
sdr.set_direct_sampling('q')
sdr.fc = 0
sdr.gain = 10
wf.start()
# cleanup
sdr.close()
示例13: Rtl_threading
class Rtl_threading(threading.Thread):
def __init__(self, addr, fc, fs, size, times, corr):
threading.Thread.__init__(self)
self.sdr = RtlSdr(addr)
# configure device
self.sdr.sample_rate = fs; # Hz
self.sdr.center_freq = fc; # Hz
# self.freq_correction = corr; # PPM
if addr==1:
self.sdr.gain = 32.8
# 36.4 the stdev=0.04
else: #0
self.sdr.gain = 32.8
#15.7 0.725
# init param
self.addr = addr;
self.size = size
self.times = times
self.counter = 0;
#0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6
def run(self):
# start lock to avoid reading the same data
# self.tlock.acquire()
for x in range(0, self.times):
timestamp = int(time.time());
global event; #init the synchronization
if event.isSet():
event.clear()
event.wait()
else:
event.set()
#read
time_str_read = int(time.time());
output = self.sdr.read_samples(self.size);
i=0
for value in output:
if self.addr == 0:
rsamples[i] = value.real;
isamples[i] = value.imag;
else:
rsamples1[i] = value.real;
isamples1[i] = value.imag;
i+=1;
示例14: __init__
def __init__(self, addr, fc, fs, size, corr):
'''Add one more augument, corr'''
threading.Thread.__init__(self)
self.sdr = RtlSdr(addr)
# configure device
self.sdr.sample_rate = fs; # Hz
self.sdr.center_freq = fc; # Hz
# self.freq_correction = corr; # PPM
if addr==1:
self.sdr.gain = 32.8
else: #0
self.sdr.gain = 32.8
# init param
self.addr = addr;
self.size = size
self.counter = 0;
示例15: Rtl_threading
class Rtl_threading(threading.Thread):
def __init__(self, addr):
global params
threading.Thread.__init__(self)
self.sdr = RtlSdr(addr)
# configure device
self.sdr.sample_rate = params.fs
# Hz
self.sdr.center_freq = params.fc
# Hz
self.is_ref = addr == params.ref_addr
# self.freq_correction = corr; # PPM
if self.is_ref:
self.sdr.gain = params.ref_gain
else: # 0
self.sdr.gain = params.ech_gain
# init param
self.addr = addr
self.size = params.size
# loop
self.loop_sw = True
def run(self):
global event, wf_ech, wf_ref, dsp # init the synchronization
# start lock to avoid reading the same data
if event.isSet():
event.clear()
event.wait()
else:
event.set()
while self.loop_sw:
# read
print "reading new data~~~"
output = self.sdr.read_samples(self.size)
if self.is_ref: # ref
wf_ref = np.array(output, dtype=np.complex128)
else:
wf_ech = np.array(output, dtype=np.complex128)
if event.isSet():
event.clear()
event.wait()
else:
dsp.new_data()
event.set()
self.loop_sw = False