From c060f82c251b39cb7ddb534199a447b008ca5299 Mon Sep 17 00:00:00 2001 From: Michael Ossmann Date: Fri, 10 Feb 2017 22:18:46 -0700 Subject: [PATCH] fixed bug that can happen when frequency ranges are interleaved around the stop frequency --- qspectrumanalyzer/backend.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/qspectrumanalyzer/backend.py b/qspectrumanalyzer/backend.py index 62f76a1..1fa6556 100644 --- a/qspectrumanalyzer/backend.py +++ b/qspectrumanalyzer/backend.py @@ -285,12 +285,20 @@ class HackRFSweepThread(RtlPowerBaseThread): if bin_size > 5000: bin_size = 5000 + # We only support whole numbers of steps with bandwidth equal to the + # sample rate. + step_bandwidth = sample_rate / 1000000 + total_bandwidth = stop_freq - start_freq + step_count = 1 + (total_bandwidth - 1) // step_bandwidth + total_bandwidth = step_count * step_bandwidth + stop_freq = start_freq + total_bandwidth + self.params = { "start_freq": start_freq, # MHz "stop_freq": stop_freq, # MHz "hops": 0, "device_index": 0, - "sample_rate": 20e6, # Msps + "sample_rate": 20e6, # sps "bin_size": bin_size, # kHz "interval": 0, # seconds "gain": 0, @@ -328,15 +336,19 @@ class HackRFSweepThread(RtlPowerBaseThread): data = np.fromstring(buf[16:], dtype='= (self.params["stop_freq"]): + # We've reached the end of a pass, so sort and display it. sorted_data = sorted(zip(self.databuffer["x"], self.databuffer["y"])) self.databuffer["x"], self.databuffer["y"] = [list(x) for x in zip(*sorted_data)] self.data_storage.update(self.databuffer) - self.databuffer = {"timestamp": [], "x": [], "y": []} def run(self): """hackrf_sweep thread main loop"""