本文整理匯總了Python中rtlsdr.RtlSdr.sample_rate方法的典型用法代碼示例。如果您正苦於以下問題:Python RtlSdr.sample_rate方法的具體用法?Python RtlSdr.sample_rate怎麽用?Python RtlSdr.sample_rate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rtlsdr.RtlSdr
的用法示例。
在下文中一共展示了RtlSdr.sample_rate方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [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);
示例2: get_sdr
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [as 別名]
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
示例3: get_data
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [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
示例4: storing_stream_with_windows
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [as 別名]
def storing_stream_with_windows(l, device_number, folder, subfolders, center_frequency, samplerate, gain, nsamples, freq_correction,
user_hash):
l.acquire()
print(device_number, center_frequency, samplerate, gain, nsamples, freq_correction)
# configure device
sdr = RtlSdr(device_index=device_number)
sdr.center_freq = center_frequency
sdr.sample_rate = samplerate
if freq_correction:
sdr.freq_correction = freq_correction # PPM
sdr.gain = gain
print('hello world')
timestamp = time.mktime(time.gmtime())
samples = sdr.read_bytes(nsamples*2)
sdr.close()
l.release()
print("save")
basename = "{hash}_{freq}_{time:0.0f}".format(hash=user_hash, freq=center_frequency, time=timestamp)
filename = path.join(folder, subfolders[0], "tmp_" + basename)
# np.savez_compressed(filename, samples) # storing by numpy and copressing it
'''np.save(filename, samples)
os.rename(filename + ".npy",
path.join(folder, subfolders[0], basename + ".npy"))'''
f = open(filename, 'wb')
f.write(samples)
f.close()
os.rename(filename,
path.join(folder, subfolders[0], basename + ".dat"))
del samples
filename = path.join(folder, subfolders[1], basename + ".npy")
sdrmeta(filename, device_number, folder, subfolders, center_frequency,
samplerate, gain, nsamples, freq_correction, user_hash)
return filename
示例5: RtlSdr
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [as 別名]
from encoding import *
from radio_params import *
from radio_transmit import *
record_len = 75
## configure SDR
sdr = RtlSdr()
freq_offset = 93.2e3
sample_rate = 240e3
center_freq = 443.592e6 - freq_offset
#center_freq = 145.442e6 #- freq_offset
sdr.sample_rate = sample_rate
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
示例6: elif
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [as 別名]
elif (arg == "-s"):
config.sample_num = int(sys.argv[i+1])
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)),
示例7: RtlSdr
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [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))
示例8: exit
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [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)
示例9: return
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [as 別名]
den = np.array([1, -2*gain*np.cos(freq), (2*gain-1)]);
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");
示例10: output
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [as 別名]
#echos rtlsdr read_samples output (without lines starting with hyphen) to console and to ~/finaldata.txt
import os
from rtlsdr import RtlSdr
os.chdir(os.path.expanduser("~/"))
sdr = RtlSdr()
sdr.sample_rate = 2.048e6 #Hz
sdr.center_freq = 70e6 # Hz
sdr.freq_correction = 60 # PPM
sdr.gain = 'auto'
sdroutput = str(sdr.read_samples(512))
savefile = open('finaldata.txt', 'w')
sdr1 = sdroutput.translate(None, '[]').split()
sdr2 = sdr1
finaldata = ''
for line in sdr2:
if not "-" in line:
finaldata+=line+"\n"
print finaldata
savefile.write(finaldata)
savefile.close()
示例11: acquireSamplesAsync
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [as 別名]
def acquireSamplesAsync(fs, fc, t_total, chunk_size=1024, num_SDRs=3, gain=36):
"""
Asynchronously acquire samples and save them.
"""
assert type(t_total) == int, "Time must be an integer."
N_samples = 1024000*t_total #1024000 256000 3.2e6
SDRs = []
# Initialize the SDRs
for i in xrange(num_SDRs):
sdr_i = RtlSdr(device_index=i)
sdr_i.sample_rate = fs
sdr_i.center_freq = fc
sdr_i.gain = gain
SDRs.append(sdr_i)
# Setup the output queues
output_queues = [Queue() for _ in xrange(num_SDRs)]
rec_thrds = []
# Create the thread objects for acquisition
for i, sdr_i in enumerate(SDRs):
y = output_queues[i]
sdr_rec = threading.Thread(target=recordSamples, \
args=(sdr_i, i, N_samples, y, N_samples))
rec_thrds.append(sdr_rec)
# Start the threads
for rec_thread in rec_thrds:
rec_thread.start()
# Wait until threads are done
while any([thrd.is_alive() for thrd in rec_thrds]):
time.sleep(1)
"""
for i, size in enumerate(last_size):
curr_size = output_queues[i].qsize()
if not done_arr[i] and size == curr_size:
#rec_thrds[i].terminate()
done_arr[i] = True
else:
last_size[i] = curr_size
"""
# For DEBUG
samples = []
for i, q in enumerate(output_queues):
print "Printing Queue %d" % i
print "\t- Queue size: %d" % q.qsize()
samples.append([])
while not q.empty():
print q.qsize()
samples[i] += list(q.get())
print "Done"
np.save('demo.npy',samples)
for i in range(num_SDRs-1):
assert len(samples[i]) == len(samples[i+1])
return samples
示例12: int
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [as 別名]
offset = options.samp_rate/2
hopCount = options.required_bw/options.samp_rate
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
示例13: main
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [as 別名]
def main():
print("you are using", platform.system(), platform.release(), os.name)
# creating the central shared dgsn-node-data for all programs on the nodes
#######################################
pathname = os.path.abspath(os.path.dirname(sys.argv[0]))
pathname_all = ""
for i in range(len(pathname.split(path_separator))-2): # creating the folders two folder levels above
pathname_all = pathname_all + pathname.split(path_separator)[i] + path_separator
pathname_save = pathname_all + "dgsn-node-data"
pathname_config = pathname_all + "dgsn-hub-ops"
# creating the dump folder for files and the needed data folders
#######################################
if not os.path.exists(pathname_save):
os.makedirs(pathname_save)
folder = pathname_save + path_separator + "rec"
subfolders = ["iq", "sdr", "gapped", "coded", "monitor"]
if not os.path.exists(folder):
os.makedirs(folder)
if os.path.exists(folder):
for i in range(len(subfolders)):
if not os.path.exists(folder + path_separator + subfolders[i]):
os.makedirs(folder + path_separator + subfolders[i])
if not os.path.exists(pathname_config):
os.makedirs(pathname_config)
pathname_config = pathname_config + path_separator + "io-radio"
if not os.path.exists(pathname_config):
os.makedirs(pathname_config)
# setting the rtlsdr before the gain finding
#####################################
# getting one file to each node very simple via github, or via a local file copy
data = loading_config_file(pathname_config)
# getting the specific settings for the node itself. perhaps it cannot be as fast as others
with open(pathname + path_separator +'node-config.json') as data_file:
data_node = json.load(data_file)
device_number = data["device_number"]
center_frequency = data["center_frequency"]
samplerate = data["samplerate"]
# this will be necessary in case a full fledged pc is a node or in case a micro pc is used with less RAM
secondsofrecording = min(data["secondsofrecording"], data_node["secondsofrecording_maximum"])
print("record seconds commanded", data["secondsofrecording"], "record seconds maximum",
data_node["secondsofrecording_maximum"], "and it is", secondsofrecording)
nsamples = secondsofrecording * samplerate
freq_correction = data["freq_correction"]
user_hash = get_groundstationid()
dt = datetime.datetime(data["recording_start"]["year"], data["recording_start"]["month"], data["recording_start"]["day"],
data["recording_start"]["hour"], data["recording_start"]["minute"], data["recording_start"]["second"])
recording_start = time.mktime(dt.timetuple())
dt = datetime.datetime(data["recording_end"]["year"], data["recording_end"]["month"], data["recording_end"]["day"],
data["recording_end"]["hour"], data["recording_end"]["minute"], data["recording_end"]["second"])
recording_stop = time.mktime(dt.timetuple())
# getting the data for calibration
calibration_start = data["calibration_start"]
gain_start = data["gain_start"]
gain_end = data["gain_end"]
gain_step = data["gain_step"]
signal_threshold = data["signal_threshold"]
print("gg", gain_start, gain_end)
##################################
print("starting the fun...")
if platform.system() == "Windows":
print("detecting a windows")
##############
device_count = librtlsdr.rtlsdr_get_device_count()
print("number of rtl-sdr devices:", device_count)
if device_count > 0:
lock = Lock()
jobs = []
gain = 0
calibration_finished = 0 # 1 means calibration is done
while time.mktime(time.gmtime()) <= recording_start or calibration_finished == 0:
# waiting for the time to be right :)
time.sleep(10)
print("still to wait", recording_start - time.mktime(time.gmtime()), "to record and",
recording_start - time.mktime(time.gmtime())- calibration_start, "to calibration")
if time.mktime(time.gmtime()) > recording_start - calibration_start and calibration_finished == 0:
sdr = RtlSdr(device_index=device_number)
sdr.center_freq = center_frequency
sdr.sample_rate = samplerate
# sdr.freq_correction = 1 # PPM
#.........這裏部分代碼省略.........
示例14: play
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import sample_rate [as 別名]
pa = pyaudio.PyAudio()
stream = pa.open( format = pyaudio.paFloat32,
channels = 1,
rate = 48000,
output = True)
def play(samples):
stream.write( samples.astype(np.float32).tostring() )
sdr = RtlSdr()
sdr.center_freq = 99.7e6
sdr.sample_rate = 2.4e5
sdr.gain = 22.9
sample_buffer = Queue.Queue(maxsize=10)
def sampler_callback(samples,context):
sample_buffer.put(samples)
class MakeDaemon(threading.Thread):
def __init__(self, function, args=None):
threading.Thread.__init__(self)
self.runnable = function
self.args = args
self.daemon = True