本文整理匯總了Python中rtlsdr.RtlSdr.gain方法的典型用法代碼示例。如果您正苦於以下問題:Python RtlSdr.gain方法的具體用法?Python RtlSdr.gain怎麽用?Python RtlSdr.gain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rtlsdr.RtlSdr
的用法示例。
在下文中一共展示了RtlSdr.gain方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [as 別名]
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()
示例2: main
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [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()
示例3: run
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [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);
示例4: get_sdr
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [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
示例5: main
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [as 別名]
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()
示例6: get_data
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [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
示例7: main
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [as 別名]
def main():
gin=sys.argv[1]
ppm=sys.argv[2]
chn=sys.argv[3]
if ppm=='0': ppm='1'
if chn=='a': frc=161.975e6
if chn=='b': frc=162.025e6
sdr = RtlSdr()
wf = Waterfall(sdr)
# some defaults
sdr.rs = 1e6
sdr.fc = frc
sdr.gain = float(gin)
sdr.freq_correction = int(float(ppm))
wf.start()
# cleanup
sdr.close()
示例8: main
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [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)
示例9: storing_stream_with_windows
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [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
示例10: RtlSdr
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [as 別名]
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from rtlsdr import RtlSdr
sdr = RtlSdr()
# Sampling rate
sdr.rs = 256000. #1024e3
# Pins 4 and 5
sdr.set_direct_sampling(2)
# Center frequency
sdr.fc = 0
# I don't think this is used?
sdr.gain = 1
fig = plt.figure()
ax = fig.add_subplot(211, autoscale_on=False, xlim=(-1, 513), ylim=(-1.1,1.1))
ax.grid()
rline, = ax.plot([], [], 'r-', lw=2)
iline, = ax.plot([], [], 'g-', lw=2)
ax = fig.add_subplot(212, autoscale_on=False, xlim=(-1, 513), ylim=(-1.3,1.3))
ax.grid()
mline, = ax.plot([], [], 'b-', lw=2)
def animate(i):
samples = sdr.read_samples(1024)
try:
zc = np.where(np.diff(np.sign(samples))>0)[0][0]
except:
示例11: main
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [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
#.........這裏部分代碼省略.........
示例12: int
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [as 別名]
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: acquireSamplesAsync
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [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
示例14: RtlSdr
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [as 別名]
i_curve = data_plot.plot(pen='r', name = "In-Phase Signal")
q_curve = data_plot.plot(pen='y', name = "Quadrature Signal")
win.nextRow()
# initialize plot
fft_plot = win.addPlot(title="Power Vs. Frequency")
fft_plot.showGrid(True, True, alpha = 1)
fft_plot.addLegend()
# initialize a curve for the plot
curve = fft_plot.plot(pen='g', name = "Power Spectrum")
max_curve = fft_plot.plot(pen='r', name = "Max Hold")
sdr = RtlSdr()
# some defaults
sdr.rs = 2e6
sdr.fc = 106.9e6
sdr.gain = 30
max_data = []
def update():
global dut, curve, max_data
samples = sdr.read_samples(SAMPLE_SIZE)
samples = samples * np.hanning(len(samples))
pow = 20 * np.log10(np.abs(np.fft.fftshift(np.fft.fft(samples))))
i_curve.setData(samples.real)
q_curve.setData(samples.imag)
if len(max_data) == 0:
max_data = pow
else:
max_data = np.maximum(max_data, pow)
curve.setData(pow)
max_curve.setData(max_data)
data_plot.enableAutoRange('xy', False)
示例15: elif
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import gain [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 "];"