我正在尝试构建一个脚本来从我的 RTLSDR 进行一些信号处理。但是,我得到的比特不是我所期望的。
但是在绘制所有值之后,我的脚本看到(-1 到 +1)它看起来像这样:
通常我也会得到没有任何意义的情节。至少最后一个与 URH 序言有一些相似之处,但也有很多情节没有。
我错过了什么......“通用无线电黑客”也使用 pyrtlsdr,所以我知道它可以工作。- 复杂的,真实的,想象的 - 不能说我完全理解它。有什么问题吗?- 噪音,增益.. 不是 100% 确定在那里做什么。URH 似乎将增益设置为 25,但是当我这样做时,我什么也没得到,所以我把它留在了“自动”——我应该得到(几乎)所有的样本。一开始我确实丢失了一些,但是在我将后处理逻辑移动到单独的进程中之后,它似乎很好。
我的脚本:
from rtlsdr import RtlSdr
from datetime import datetime
import asyncio
import matplotlib.pyplot as plt
from multiprocessing import Process, Queue
async def get_samples(sdr, q1):
counter = 0
timestamp1 = datetime.now()
# Get this many samples every time
async for samples in sdr.stream():
q1.put(samples)
counter += 1
timestamp2 = datetime.now()
if (timestamp2 - timestamp1).total_seconds() > 1:
# To see if we missed any samples. Should be close to srate samples p/s
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'GETSAMPLES -', int((counter * 131072) / (timestamp2 - timestamp1).total_seconds()), 'samples p/s')
counter = 0
timestamp1 = datetime.now()
def check_samples(q1, q2, noise, samplesperbit):
while True:
values = []
withinnoisecounter = 0
signal = False
if q1.qsize() > 10:
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'CHECKSAMPLES - Warning: Queue depth is', q1.qsize())
samples = q1.get()
for sample in samples:
if not signal:
# Start when signal breaks out of noise range
if sample.real > noise or sample.real < -noise:
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'CHECKSAMPLES - signal detected')
signal = True
values.append(sample.real)
else:
values.append(sample.real)
if not (sample.real > noise or sample.real < -noise):
withinnoisecounter += 1
elif withinnoisecounter > 0:
withinnoisecounter = 0
if withinnoisecounter > samplesperbit * 3:
# Break when signal is within noise range 3 * samplesperbit
break
if signal:
q2.put(values)
def decode_fsk(q2, srate):
# ToDo, now it just plots
while True:
values = q2.get()
plt.figure(figsize=(20, 5))
# Preamble should be in here
plt.plot(values[:2000])
plt.show()
def main():
noise = 0.9
# 38400 * 30 to get exactly 30 samples per bit.
srate = 1152000
samplesperbit = 1000000 / 38400 / (1000000 / srate)
sdr = RtlSdr()
# Just like in URH
sdr.freq_correction = 1
sdr.sample_rate = srate
sdr.center_freq = 868.200e6
sdr.gain = 'auto'
# Run check_samples in another thread to make sure we don't miss any samples
q1 = Queue()
q2 = Queue()
p1 = Process(target=check_samples, args=(q1, q2, noise, samplesperbit))
p1.start()
# Run decode_fsk in another thread to make sure we don't miss any samples
p2 = Process(target=decode_fsk, args=(q2, srate))
p2.start()
# This is the main loop
loop = asyncio.get_event_loop()
loop.run_until_complete(get_samples(sdr, q1))
if __name__ == "__main__":
main()
谢谢!