因此,使用覆盆子pi,我尝试使用rtl扫描仪扫描一系列频率,然后绘制该信息。但是,我得到的更新情节运行得相当慢。无论如何我可以加快这个过程吗?这是我的代码:
#!bin/usr/python
#gathers from the rtl library needed for this program
from rtlsdr import RtlSdr
import math
from pylab import *
import time
from scipy.fftpack import fft, ifft
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
sdr = RtlSdr()
freq = 5.5e6
num_samples = 1024
##freq_range_lo = 52e6
freq_range_lo = 5.3e6
freq_range_hi = 1766e6
##freq_range_hi = 5.8e6
freq_step = 1e6
sdr.sample_rate = 1e6
sdr.center_freq = freq
sdr.freq_correction =1142
sdr.gain = 49.6
samples = np.array([])
freq_array = []
fft_data = []
app = QtGui.QApplication([])
win = pg.GraphicsWindow(title="Basic plotting examples")
win.resize(1000,600)
win.setWindowTitle('pyqtgraph example: Plotting')
pg.setConfigOptions(antialias=True)
win.nextRow()
p6 = win.addPlot(title="Freq plot")
curve = p6.plot(pen='y')
#data = np.random.normal(size=(5.5,1766))
data = np.random.normal(size=(10,1000))
ptr = 0
def scan(low, hi, freq, freq_step):
global samples, fft_data
for freq in range (int(low), int(hi), int(freq_step)):
samp_val = 0
samples = fft(sdr.read_samples(256))
samples = abs(samples[0::])
for i in samples:
samp_val += samples[i]
fft_data.append(samp_val)
return fft_data
def update():
global curve, data, ptr, p6,samples, fft_data
curve.setData(scan(freq_range_lo, freq_range_hi, freq, freq_step))
if ptr == 0:
p6.enableAutoRange('xy', False)
ptr += 1
del fft_data[:]
timer = pg.QtCore.QTimer()
timer.timeout.connect(update)
timer.start(2)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
对于扫描仪,我使用此链接提供的设置https://github.com/roger-/pyrtlsdr
非常感谢任何有助于加快这一步骤的帮助。