Skip to content

Commit b326ffd

Browse files
committed
added baseband filter choice option
1 parent ba4027a commit b326ffd

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

python_hackrf/pyhackrf_tools/pyhackrf_sweep.pyx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ PY_BLOCKS_PER_TRANSFER = 16
4444

4545
# hackrf sweep settings
4646
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)
47+
AVAILABLE_BASEBAND_FILTER_BANDWIDTHS = (1_750_000, 2_500_000, 3_500_000, 5_000_000, 5_500_000, 6_000_000, 7_000_000, 8_000_000, 9_000_000, 10_000_000, 12_000_000, 14_000_000, 15_000_000, 20_000_000, 24_000_000, 28_000_000)
4748
BASEBAND_FILTER_BANDWIDTH_RATIO = 0.75
4849
INTERLEAVED_OFFSET_RATIO = 0.375
4950
LINEAR_OFFSET_RATIO = 0.5
@@ -79,16 +80,16 @@ cdef int pwr_1_stop = 0
7980
cdef int pwr_2_start = 0
8081
cdef int pwr_2_stop = 0
8182
cdef float norm_factor = 0
82-
cdef int start_frequency = 0
83+
cdef unsigned long start_frequency = 0
8384

8485
sweep_started = False
8586
run_available = True
8687
check_max_num_sweeps = False
8788

8889
cdef int max_num_sweeps = 0
89-
cdef unsigned int accepted_bytes = 0
90+
cdef unsigned long long accepted_bytes = 0
9091
cdef double sweep_rate = 0
91-
cdef unsigned int sweep_count = 0
92+
cdef unsigned long long sweep_count = 0
9293

9394

9495
def sigint_callback_handler(sig, frame):
@@ -116,7 +117,7 @@ cdef sweep_callback(buffer: np.ndarray[:], buffer_length: int, valid_length: int
116117
timestamp = datetime.datetime.now()
117118
time_str = timestamp.strftime("%Y-%m-%d, %H:%M:%S.%f")
118119

119-
cdef int frequency = 0
120+
cdef unsigned long frequency = 0
120121
cdef int index = 0
121122
cdef int i, j
122123
for j in range(PY_BLOCKS_PER_TRANSFER):
@@ -228,7 +229,7 @@ cdef sweep_callback(buffer: np.ndarray[:], buffer_length: int, valid_length: int
228229

229230

230231
def pyhackrf_sweep(frequencies: list = [0, 6000], lna_gain: int = 16, vga_gain: int = 20, bin_width: int = 100_000,
231-
serial_number: str = None, amp_enable: bool = False, antenna_enable: bool = False, sample_rate: int = 20_000_000,
232+
serial_number: str = None, amp_enable: bool = False, antenna_enable: bool = False, sample_rate: int = 20_000_000, bandwidth: int = 15_000_000,
232233
num_sweeps: int = None, binary_output: bool = False, one_shot: bool = False, use_queue: bool = False, filename: str = None, sweep_style: pyhackrf.py_sweep_style = pyhackrf.py_sweep_style.INTERLEAVED,
233234
print_to_console: bool = True, device: pyhackrf.PyHackrfDevice = None):
234235

@@ -249,6 +250,11 @@ def pyhackrf_sweep(frequencies: list = [0, 6000], lna_gain: int = 16, vga_gain:
249250
SAMPLE_RATE = int(sample_rate)
250251
else:
251252
SAMPLE_RATE = 20_000_000
253+
254+
if bandwidth in AVAILABLE_BASEBAND_FILTER_BANDWIDTHS:
255+
BASEBAND_FILTER_BANDWIDTH = int(bandwidth)
256+
else:
257+
BASEBAND_FILTER_BANDWIDTH = int(SAMPLE_RATE * BASEBAND_FILTER_BANDWIDTH_RATIO)
252258

253259
frequency_step_1 = sample_rate // 4
254260
frequency_step_2 = sample_rate // 2
@@ -260,7 +266,6 @@ def pyhackrf_sweep(frequencies: list = [0, 6000], lna_gain: int = 16, vga_gain:
260266
accepted_bytes = 0
261267
sweep_started = False
262268

263-
BASEBAND_FILTER_BANDWIDTH = int(SAMPLE_RATE * BASEBAND_FILTER_BANDWIDTH_RATIO)
264269
if SWEEP_STYLE == pyhackrf.py_sweep_style.INTERLEAVED:
265270
OFFSET = int(SAMPLE_RATE * INTERLEAVED_OFFSET_RATIO)
266271
else:

0 commit comments

Comments
 (0)