Skip to content

Commit 32db147

Browse files
committed
fixed linear sweep style
1 parent f8793dd commit 32db147

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

python_hackrf/pyhackrf_tools/pyhackrf_sweep.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
from python_hackrf import pyhackrf
2424
try:
25-
from scipy.fft import fft
25+
from scipy.fft import fft, fftshift
2626
except ImportError:
27-
from numpy.fft import fft
27+
from numpy.fft import fft, fftshift
2828
import numpy as np
2929
import datetime
3030
import signal
@@ -40,7 +40,8 @@
4040
# hackrf sweep settings
4141
AVAILABLE_SAMPLING_RATES = (2_000_000, 4_000_000, 6_000_000, 8_000_000, 10_000_000, 12_000_000, 14_000_000, 16_000_000, 18_000_000, 20_000_000)
4242
BASEBAND_FILTER_BANDWIDTH_RATIO = 0.75
43-
OFFSET_RATIO = 0.375
43+
INTERLEAVED_OFFSET_RATIO = 0.375
44+
LINEAR_OFFSET_RATIO = 0.5
4445

4546

4647
SAMPLE_RATE = None
@@ -141,12 +142,13 @@ def sweep_callback(buffer: np.ndarray, buffer_length: int, valid_length: int) ->
141142
index += (pyhackrf.PY_BYTES_PER_BLOCK - data_length)
142143

143144
fftwOut = fft((buffer[index: index + data_length: 2].astype(np.int8, copy=False) / 128 + 1j * buffer[index + 1: index + data_length: 2].astype(np.int8, copy=False) / 128) * window)
144-
145145
magsq = np.abs(fftwOut * norm_factor) ** 2
146146
pwr = np.log10(magsq) * 10.0
147147

148-
index += data_length
148+
if SWEEP_STYLE == pyhackrf.py_sweep_style.LINEAR:
149+
pwr = fftshift(pwr)
149150

151+
index += data_length
150152
if binary_output_mode:
151153
if SWEEP_STYLE == pyhackrf.py_sweep_style.INTERLEAVED:
152154
record_length = 16 + (fftSize // 4) * 4
@@ -251,7 +253,11 @@ def pyhackrf_sweep(frequencies: list = [0, 6000], lna_gain: int = 16, vga_gain:
251253
sweep_started = False
252254

253255
BASEBAND_FILTER_BANDWIDTH = int(SAMPLE_RATE * BASEBAND_FILTER_BANDWIDTH_RATIO)
254-
OFFSET = int(SAMPLE_RATE * OFFSET_RATIO)
256+
if SWEEP_STYLE == pyhackrf.py_sweep_style.INTERLEAVED:
257+
OFFSET = int(SAMPLE_RATE * INTERLEAVED_OFFSET_RATIO)
258+
else:
259+
OFFSET = int(SAMPLE_RATE * LINEAR_OFFSET_RATIO)
260+
255261
TUNE_STEP = SAMPLE_RATE / 1e6
256262

257263
init_signals()

0 commit comments

Comments
 (0)