本文整理匯總了Python中rtlsdr.RtlSdr.read_samples_async方法的典型用法代碼示例。如果您正苦於以下問題:Python RtlSdr.read_samples_async方法的具體用法?Python RtlSdr.read_samples_async怎麽用?Python RtlSdr.read_samples_async使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rtlsdr.RtlSdr
的用法示例。
在下文中一共展示了RtlSdr.read_samples_async方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples_async [as 別名]
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()
示例2: run
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples_async [as 別名]
def run(self):
# Read 128ms of data at a time (must be a multiple of a power of two)
blkSize = SAMPLE_RATE_KHZ()*128;
blockLoc = np.zeros(1,dtype=np.uint64);
sdr = RtlSdr();
# configure device
sdr.sample_rate = SAMPLE_RATE_KHZ()*1e3 # Hz
sdr.center_freq = 1575420000 # Hz
sdr.gain = 29;
sdrQueue.put((sdr,blockLoc,blkSize/SAMPLE_RATE_KHZ(),1));
sdr.read_samples_async(sdrCallback, blkSize, context=sdrQueue);
示例3: main
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples_async [as 別名]
def main():
@limit_time(0.01)
@limit_calls(20)
def read_callback(buffer, rtlsdr_obj):
print('In callback')
print(' signal mean:', sum(buffer)/len(buffer))
from rtlsdr import RtlSdr
sdr = RtlSdr()
print('Configuring SDR...')
sdr.rs = 1e6
sdr.fc = 70e6
sdr.gain = 5
print(' sample rate: %0.6f MHz' % (sdr.rs/1e6))
print(' center ferquency %0.6f MHz' % (sdr.fc/1e6))
print(' gain: %d dB' % sdr.gain)
print('Testing callback...')
sdr.read_samples_async(read_callback)
示例4: FMRadio
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples_async [as 別名]
#.........這裏部分代碼省略.........
self.useMedianFilt = not s
def setDemodFiltSize(self,s):
if(s % 2 == 0):
s+=1
self.demodFiltSize = s
def setAudioFiltUse(self,s):
self.useAudioFilter = s
def setAudioFiltSize(self,s):
self.audioFilterSize = s
def terminate(self):
self.__del__()
def __del__(self):
#QtGui.QMainWindow.__del__()
#Ui_MainWindow.__del__()
#self.streamer.stop()
#self.sampler_t.stop()
print "sdr closed"
self.sdr.close()
print "pyaudio terminated"
self.pa.terminate()
sys.exit()
def getSamples(self):
#N_samples = self.N_samples # 1/24.4 seconds ~46336 #approximately a 2048/44100 amount's time
return self.sdr.read_samples(self.N_samples)
def getSamplesAsync(self):
#Asynchronous call. Meant to be put in a loop w/ a calback fn
#print 'gonna sample'
self.is_sampling = True
samples = self.sdr.read_samples_async(self.sampleCallback,self.N_samples,context=self)
def sampleCallback(self,samples,sself):
self.is_sampling = False
self.sample_buffer.put(samples)
#print 'put some samples in the jar'
# recursive loop
#sself.getSamplesAsync()
def demodulate_th(self):
while(1):
try:
samples = self.sample_buffer.get()
#samples2 = self.sample_buffer.get()
# print 'gottum'
except:
print "wtf idk no samples?"
break
out1 = self.demodulate(samples)
self.sample_buffer.task_done()
#out2 = self.demodulate(samples2)
#self.sample_buffer.task_done()
audio_out = out1 #np.append(out1,out2)
self.play(audio_out)
print 'gonna try to finish off the to-do list'
sample_buffer.join()
示例5: callback
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples_async [as 別名]
sdr.center_freq = center_freq
sdr.gain = 10
## get samples
samples = []
def callback(ss, obj):
samples.append(ss)
#obj.cancel_read_async()
print('Ready to record!')
raw_input("Press Enter to record...")
print('recording...')
N_samples = sample_rate*0.5 # approximately seconds
sdr.read_samples_async(limit_time(record_len)(callback), N_samples) # get samples
print('recorded!')
sdr_samples = np.hstack(samples)
print('demodulating...')
ss = smart_demod(sdr_samples, sample_rate, freq_offset)
#del sdr_samples'
print('finding packets...')
packets = findPackets(ss)[0]
print('error correcting packets...')
decodes = map(lambda p: util.correct(decodePacket(p)), packets)
示例6: exit
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples_async [as 別名]
bitstr += "0"
else:
bitstr += "1"
if bitCount < 6:
scancode += 1 << bitCount
bitCount += 1
bitValue = 0
if bitCount > 10:
bitCount = 0
state = 0 # fin demod
except:
exit(0)
if __name__ == "__main__":
q = Queue()
p = Process(target=AsyncWelchProcess, args=(q,))
p.start()
def on_sample(buf, queue):
queue.put(list(buf))
from rtlsdr import RtlSdr
sdr = RtlSdr()
# configure device
sdr.sample_rate = SAMPLE_RATE # sample rate
sdr.center_freq = FREQ
sdr.gain = "auto"
sdr.read_samples_async(on_sample, 2048, context=q)
示例7: return
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples_async [as 別名]
return (num,den);
fmDemod = FMDemod();
fileRead = FileReader();
audioPlay = AudioPlay();
dataQueue = Queue.Queue([1]);
audioQueue = Queue.Queue([1]);
sdr = RtlSdr();
# configure device
sdr.sample_rate = 250e3; # Hz
numSampsRead = 1024*600;
freq = raw_input('Choose a station frequency: ');
try:
freq = float(freq);
sdr.center_freq = freq;
sdr.gain = 'auto';
#fileRead.start();
fmDemod.start();
audioPlay.start();
sdr.read_samples_async(sdrCallback, numSampsRead);
except ValueError:
print("Invalid number");
示例8: FMRadio
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples_async [as 別名]
#.........這裏部分代碼省略.........
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)
# Not currently used
def getSamples(self):
return self.sdr.read_samples(self.N_samples);
def getSamplesAsync(self):
#Asynchronous call. Initiates a continuous loop with the callback fn
self.is_sampling = True
samples = self.sdr.read_samples_async(self.sampleCallback,self.N_samples,context=self)
def sampleCallback(self,samples,sself):
self.is_sampling = False
self.sample_buffer.put(samples)
#print 'put some samples in the jar'
# recursive loop
#sself.getSamplesAsync()
def demodulate_th(self):
# Initiates a loop to process all the incoming blocks of samples from the Queue
# This should be run in its own thread, or the program will become unresponsive
while(1):
try:
samples = self.sample_buffer.get()
#samples2 = self.sample_buffer.get()
except:
#print "wtf idk no samples?" # even though this can't happen... (although I'm not sure why not)
#print 'gonna try to finish off the to-do list'
#self.sample_buffer.join()
break
out1 = self.demodulate(samples)
self.sample_buffer.task_done()
#out2 = self.demodulate(samples2)
#self.sample_buffer.task_done()
audio_out = out1 #np.append(out1,out2)
self.play(audio_out)
def gen_spectrogram(self,x,m,prevSpec):
示例9: __init__
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples_async [as 別名]
class FMRadio:
sample_buffer = Queue.Queue(maxsize=100)
base_spectrum = np.ones(5780)
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.is_sampling = False
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 = 1,
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))
def __del__(self):
print "sdr closed"
self.sdr.close()
print "pyaudio terminated"
self.pa.terminate()
def getSamples(self):
#N_samples = self.N_samples # 1/24.4 seconds ~46336 #approximately a 2048/44100 amount's time
return self.sdr.read_samples(self.N_samples)
def getSamplesAsync(self):
#Asynchronous call. Meant to be put in a loop w/ a calback fn
#print 'gonna sample'
self.is_sampling = True
samples = self.sdr.read_samples_async(self.sampleCallback,self.N_samples,context=self)
def sampleCallback(self,samples,sself):
self.is_sampling = False
self.sample_buffer.put(samples)
#print 'put some samples in the jar'
# recursive loop
#sself.getSamplesAsync()
def demodulate_th(self):
while(1):
try:
samples = self.sample_buffer.get()
#samples2 = self.sample_buffer.get()
# print 'gottum'
except:
print "wtf idk no samples?"
break
out1 = self.demodulate(samples)
self.sample_buffer.task_done()
#out2 = self.demodulate(samples2)
#self.sample_buffer.task_done()
audio_out = out1 #np.append(out1,out2)
self.play(audio_out)
print 'gonna try to finish off the to-do list'
sample_buffer.join()
def demodulate(self,samples):
# DEMODULATION CODE
#samples = #self.sample_buffer.get()
# LIMITER goes here
# low pass & down sampling via fft
spectrum = np.fft.fft(samples)*self.lpf
toplot = False
if(toplot):
fig = plt.figure()
plt.plot(np.abs(spectrum))
plt.show()
# Decimate in two rounds. One to 200k, another to 44.1k
# DECIMATE HERE. Note that we're looking at 1MHz bandwidth.
#.........這裏部分代碼省略.........