當前位置: 首頁>>代碼示例>>Python>>正文


Python RtlSdr.read_samples方法代碼示例

本文整理匯總了Python中rtlsdr.RtlSdr.read_samples方法的典型用法代碼示例。如果您正苦於以下問題:Python RtlSdr.read_samples方法的具體用法?Python RtlSdr.read_samples怎麽用?Python RtlSdr.read_samples使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rtlsdr.RtlSdr的用法示例。


在下文中一共展示了RtlSdr.read_samples方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Rtl_threading

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]
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)
開發者ID:TuringTW,項目名稱:SoftwareRadar,代碼行數:35,代碼來源:rt_monitor.py

示例2: main

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [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()
開發者ID:Mondego,項目名稱:pyreco,代碼行數:34,代碼來源:allPythonContent.py

示例3: Rtl_threading

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]
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();
開發者ID:TuringTW,項目名稱:SoftwareRadar,代碼行數:33,代碼來源:go_rt.py

示例4: Rtl_threading

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]
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;
開發者ID:TuringTW,項目名稱:SoftwareRadar,代碼行數:51,代碼來源:go_mat.py

示例5: __init__

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]
class FMRadio:

     # multiple of 256


    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
        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 = self.gain

        self.pa = pyaudio.PyAudio()
        self.stream = self.pa.open( format = pyaudio.paFloat32,
                                    channels = 1,
                                    rate = 44100,
                                    output = True)

        hamming = 10*signal.hamming(self.N_samples*.10 )
        lpf = np.append( np.zeros(self.N_samples*.45),hamming)
        self.lpf = np.fft.fftshift(np.append(lpf,np.zeros(self.N_samples*.45)))

    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 blocksize amount's time
        return self.sdr.read_samples(self.N_samples)


#    def demodulate_threaded(self,samples):
#        async_demodulation = self.pool.apply_async(self.demodulate, samples, callback=self.play)


    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.
        n_s = spectrum.size
        channel_spectrum = np.append(spectrum[0:n_s/self.decim_r1*.5],spectrum[n_s-n_s/self.decim_r1*.5:n_s])

        #radio_spectrum -= np.mean(radio_spectrum) #attempt to remove dc bias

#         toplot = False
#         if(toplot):
#             fig = plt.figure()
#             plt.plot(np.abs(channel_spectrum))
#             plt.show()


        lp_samples = np.fft.ifft(channel_spectrum)

        #lp_samples = self.lowpass_filter(lp_samples,4)

    # polar discriminator

        A = lp_samples[1:lp_samples.size]
        B = lp_samples[0:lp_samples.size-1]

        dphase = ( A * np.conj(B) )

#dpm = np.mean(np.abs(dphase))
        # normalize
        #       dphase /= dpm
        dphase.resize(dphase.size+1)
        dphase[dphase.size-1] = dphase[dphase.size-2]

        rebuilt = signal.medfilt(np.angle(dphase)/np.pi,15) #  np.cos(dphase)

        #phase = np.sin(rebuilt)
        #phase = self.lowpass_filter(phase,8)

        #rebuilt= self.lowpass_filter(rebuilt,8)

#         toplot = False
#.........這裏部分代碼省略.........
開發者ID:peragwin,項目名稱:fmradio-qt,代碼行數:103,代碼來源:radio_new.py

示例6: Rtl_threading

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]
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
開發者ID:TuringTW,項目名稱:SoftwareRadar,代碼行數:49,代碼來源:go.py

示例7: get_data

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]
def get_data(freq):
    sdr = RtlSdr()

    sdr.sample_rate = 2.048e6
    sdr.center_freq = int(decimal.Decimal(str(freq) + 'e6'))
    sdr.freq_correction = 60
    sdr.gain = 'auto'

    data = sdr.read_samples(512)

    if not data.any():
        app.abort(404, 'No data!')

    d = []
    for item in data:
        d.append(str(item))

    js = json.dumps(d)
    return js
開發者ID:JE6HBC,項目名稱:satnogs-software,代碼行數:21,代碼來源:simplesdr.py

示例8: Sampler

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]
class Sampler(QtCore.QObject):
    samplerError = QtCore.pyqtSignal(object)
    dataAcquired = QtCore.pyqtSignal(object)

    def __init__(self, gain, sampRate, freqs, numSamples, parent=None):
        super(Sampler, self).__init__(parent)
        self.gain = gain
        self.sampRate = sampRate
        self.freqs = freqs
        self.numSamples = numSamples
        self.offset = 0
        self.sdr = None
        self.errorMsg = None

        self.WORKING = True
        self.BREAK = False
        self.MEASURE = False

        try:
            self.sdr = RtlSdr()
            self.sdr.set_manual_gain_enabled(1)
            self.sdr.gain = self.gain
            self.sdr.sample_rate = self.sampRate
        except IOError:
            self.WORKING = False
            print "Failed to initiate device. Please reconnect."
            self.errorMsg = "Failed to initiate device. Please reconnect."
            self.samplerError.emit(self.errorMsg)

    def sampling(self):
        print 'Starting sampler...'
        while self.WORKING:
            prev = 0
            counter = 0
            gain = self.gain
            numSamples = self.numSamples
            self.BREAK = False
            self.sdr.gain = gain
            start = time.time()
            #print self.sdr.get_gain()
            for i in range(len(self.freqs)):
                if self.BREAK:
                    break
                else:
                    centerFreq = self.freqs[i]
                    #print "frequency: " + str(center_freq/1e6) + "MHz"
                    if centerFreq != prev:
                        try:
                            self.sdr.set_center_freq(centerFreq)
                        except:
                            self.WORKING = False
                            print "Device failure while setting center frequency"
                            self.errorMsg = "Device failure while setting center frequency"
                            self.samplerError.emit(self.errorMsg)
                            break
                        prev = centerFreq
                    else:
                        pass

                    #time.sleep(0.01)
                    try:
                        x = self.sdr.read_samples(2048)
                        data = self.sdr.read_samples(numSamples)

                    except:
                        self.WORKING = False
                        print "Device failure while getting samples"
                        self.errorMsg = "Device failure while getting samples"
                        self.samplerError.emit(self.errorMsg)
                        break

                    if self.MEASURE:
                        self.offset = np.mean(data)

                    counter += 1
                    self.dataAcquired.emit([i, centerFreq, data])

        if self.errorMsg is not None:
            self.samplerError.emit(self.errorMsg)
        if self.sdr is not None:
            self.sdr.close()
開發者ID:tapczan666,項目名稱:potworniak,代碼行數:83,代碼來源:sampler.py

示例9: Rtl_threading

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]
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 = 15.7;
		else: #0
			self.sdr.gain = 32.8;

			#15.7 0.725
		# init param
		self.alive = True
		self.addr = addr;
		self.size = size
		self.times = times
		self.counter = 0;
		self.timestamp = int(time.time());

#0.0 0self.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):
		global event, samples0, samples1; #init the synchronization
		# start lock to avoid reading the same data
		if event.isSet():
			event.clear()
			event.wait()
		else:
			self.timestamp = int(time.time());
			event.set()

		for x in range(0, self.times):
			#read
			output = self.sdr.read_samples(self.size);

			if self.addr == 0:  #ref
				samples0 = np.array(output, dtype = np.complex128);
			else:
				samples1 = np.array(output, dtype = np.complex128);

			if event.isSet():
				event.clear()
				if not self.alive:
					break;
				event.wait()
			else:
				self.save2mat(x)
				self.timestamp = int(time.time());
				print '*'*3+' '+str(x)+' done: '+time.asctime( time.localtime(time.time()) );
				if not self.alive:
					break;
				event.set()
	def save2mat(self, i):
		global samples0, samples1;
		std0 = np.around(np.std(samples0), 5);
		std1 = np.around(np.std(samples1), 5);
		print 'std0:', std0, 'std1', std1;

		scipy.io.savemat('./data/'+folder_name+'/'+filename+'_'+str(i)+'.mat', mdict={'s0':samples0, 's1':samples1, 'timestamp': self.timestamp, 'fs':self.sdr.sample_rate, 'ref_addr':ref_addr});
開發者ID:TuringTW,項目名稱:SoftwareRadar,代碼行數:66,代碼來源:go_mat.py

示例10: __init__

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]
class FMRadio:

     # num samplesmust be multiple of 256


    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))

    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 blocksize amount's time
        return self.sdr.read_samples(self.N_samples)


#    def demodulate_threaded(self,samples):
#        async_demodulation = self.pool.apply_async(self.demodulate, samples, callback=self.play)


    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.
        n_s = spectrum.size

        channel_spectrum = spectrum[int(n_s*.75-.5*n_s/self.decim_r1):int(.75*n_s+.5*n_s/self.decim_r1)] #np.append(spectrum[0:int(n_s/self.decim_r1*.5)],spectrum[n_s-int(n_s/self.decim_r1*.5):n_s])

        #radio_spectrum -= np.mean(radio_spectrum) #attempt to remove dc bias
        #print channel_spectrum.size
        toplot = False
        if(toplot):
            fig = plt.figure()
            plt.plot(np.abs(np.fft.ifftshift(channel_spectrum)))
            plt.show()


        lp_samples = np.fft.ifft(np.fft.ifftshift(channel_spectrum))


        power = np.abs(self.rms(lp_samples))
        lp_samples /= power
        #lp_samples = self.lowpass_filter(lp_samples,4)

    # polar discriminator

        A = lp_samples[1:lp_samples.size]
        B = lp_samples[0:lp_samples.size-1]

        dphase = ( A * np.conj(B) )

#dpm = np.mean(np.abs(dphase))
        # normalize
        #       dphase /= dpm
        dphase.resize(dphase.size+1)
        dphase[dphase.size-1] = dphase[dphase.size-2]

        rebuilt = signal.medfilt(np.angle(dphase)/np.pi,21) #  np.cos(dphase)

        #phase = np.sin(rebuilt)
#.........這裏部分代碼省略.........
開發者ID:peragwin,項目名稱:fmradio-qt,代碼行數:103,代碼來源:radio-slim.py

示例11: int

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]
     if hopCount == 0:
	hopCount = 1

     sampleCount = options.dwell_time*options.samp_rate
	
     p = int(math.log(sampleCount,2) + 1)
	
     sampleCount = pow(2,p)
	
     print "SampleCount ", sampleCount
   
     sdr = RtlSdr()
     sdr.sample_rate = options.samp_rate
     sdr.gain = 4
     sdr.freq_correction = 60

     while True:
         for i in range(0,int(hopCount) - 1):
	     sdr.center_freq = startHz + i*options.samp_rate + offset
	     samples = sdr.read_samples(sampleCount)
	     energy = numpy.linalg.norm(samples)/sampleCount
	     print "Center Freq ", (startHz + i*options.samp_rate + offset)/1e6 , " Mhz", " Energy ", energy


     
    
     


開發者ID:usnistgov,項目名稱:rtlsdr-tv-whitespace-monitor,代碼行數:24,代碼來源:sense-whitespace.py

示例12: elif

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]
	elif (arg == "-c"):
		config.center_freq = int(sys.argv[i+1])
	elif (arg == "-r"):
		config.sample_rate = int(sys.argv[i+1])

#init RTLSDR and if no then go out
try:
	sdr = RtlSdr()
except IOError:
	print "Probably RTLSDR device not attached"
	sys.exit(0)

# configure device
sdr.sample_rate = config.sample_rate  # Hz
sdr.center_freq = config.center_freq     # Hz
sdr.freq_correction = 60   # PPM
sdr.gain = 'auto'


samples = sdr.read_samples( config.sample_num )
if config.matlab_flag == False:
	print( samples )
else:
	print "samples = [",
	for s in samples:
		if s.imag < 0.0:
			print "%s%si "%(str(s.real), str(s.imag)),
		else:
			print "%s+%s "%(str(s.real), str(s.imag)),
	print "];"
開發者ID:antiface,項目名稱:sdrdsp-protos,代碼行數:32,代碼來源:get_data.py

示例13: FMRadio

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]

#.........這裏部分代碼省略.........

    def setDemodFiltMedian(self,s):
        self.useMedianFilt = s
        self.useLPFilt = not s
    def setDemodFiltLP(self,s):
        self.useLPFilt = s
        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()
開發者ID:peragwin,項目名稱:fmradio-qt,代碼行數:69,代碼來源:radio-multithread.py

示例14: RtlSdr

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [as 別名]
from rtlsdr import RtlSdr

sdr = RtlSdr()

# configure device
sdr.sample_rate = 240e3  # Hz
sdr.center_freq = 101.7e6     # Hz
sdr.freq_correction = 0   # PPM
sdr.gain = 'auto'

print(sdr.read_samples(512))
開發者ID:TuringTW,項目名稱:SoftwareRadar,代碼行數:13,代碼來源:go.py

示例15: __init__

# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_samples [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.
#.........這裏部分代碼省略.........
開發者ID:peragwin,項目名稱:fmradio-qt,代碼行數:103,代碼來源:radio-final.py


注:本文中的rtlsdr.RtlSdr.read_samples方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。