Skip to content

Commit f73aea9

Browse files
committed
updated
1 parent e6e67f6 commit f73aea9

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

python_hackrf/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@
6868
one_shot=args.__dict__.get('1'),
6969
filename=args.r,
7070
sweep_style=pyhackrf.py_sweep_style.LINEAR if args.s == 'L' else pyhackrf.py_sweep_style.INTERLEAVED,
71-
sample_rate=int(args.SR),
71+
sample_rate=int(args.SR) * 1e6,
7272
print_to_console=True,
7373
)

python_hackrf/pyhackrf_tools/pyhackrf_sweep.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,20 @@ def sweep_callback(buffer: np.ndarray, buffer_length: int, valid_length: int) ->
195195

196196
else:
197197
if SWEEP_STYLE == pyhackrf.py_sweep_style.INTERLEAVED:
198-
line = f'{time_str}, {frequency}, {frequency + frequency_step_1}, {SAMPLE_RATE / fftSize}, {fftSize}, '
198+
line = f'{time_str}, {frequency}, {frequency + frequency_step_1}, {round(SAMPLE_RATE / fftSize, 2)}, {fftSize}, '
199199
pwr_1 = pwr[pwr_1_start: pwr_1_stop]
200200
for i in range(len(pwr_1)):
201201
line += f'{pwr_1[i]:.2f}, '
202-
line += f'\n{time_str}, {frequency + frequency_step_2}, {frequency + frequency_step_3}, {(SAMPLE_RATE / fftSize)}, {fftSize}, '
202+
line += f'\n{time_str}, {frequency + frequency_step_2}, {frequency + frequency_step_3}, {round(SAMPLE_RATE / fftSize, 2)}, {fftSize}, '
203203
pwr_2 = pwr[pwr_2_start: pwr_2_stop]
204204
for i in range(len(pwr_2)):
205205
line += f'{pwr_2[i]:.2f}, '
206-
line += '\n'
206+
line = line[:-2] + '\n'
207207
else:
208-
line = f'{time_str}, {frequency}, {frequency + SAMPLE_RATE}, {SAMPLE_RATE / fftSize}, {fftSize}, '
208+
line = f'{time_str}, {frequency}, {frequency + SAMPLE_RATE}, {round(SAMPLE_RATE / fftSize, 2)}, {fftSize}, '
209209
for i in range(len(pwr)):
210210
line += f'{pwr[i]:.2f}, '
211+
line = line[:-2] + '\n'
211212

212213
if file_object is None:
213214
print(line, end='')
@@ -235,7 +236,7 @@ def pyhackrf_sweep(frequencies: list = [0, 6000], lna_gain: int = 16, vga_gain:
235236
SWEEP_STYLE = pyhackrf.sweep_stylepyhackrf.py_sweep_style.INTERLEAVED
236237

237238
if sample_rate in AVAILABLE_SAMPLING_RATES:
238-
SAMPLE_RATE = sample_rate
239+
SAMPLE_RATE = int(sample_rate)
239240
else:
240241
SAMPLE_RATE = 20_000_000
241242

@@ -311,15 +312,14 @@ def pyhackrf_sweep(frequencies: list = [0, 6000], lna_gain: int = 16, vga_gain:
311312
start_frequency = int(frequencies[0] * 1e6)
312313

313314
fftSize = int(SAMPLE_RATE / bin_width)
314-
while ((fftSize + 4) % 8):
315-
fftSize += 1
316-
317315
if fftSize < 4:
318316
raise RuntimeError(f'bin_width should be between no more than {SAMPLE_RATE // 4} Hz')
319-
320-
if fftSize > 8180:
317+
elif fftSize > 8180:
321318
raise RuntimeError(f'bin_width should be between no less than {SAMPLE_RATE // 8180 + 1} Hz')
322319

320+
while ((fftSize + 4) % 8):
321+
fftSize += 1
322+
323323
pwr_1_start = 1 + (fftSize * 5) // 8
324324
pwr_1_stop = 1 + (fftSize * 5) // 8 + fftSize // 4
325325

0 commit comments

Comments
 (0)