Skip to content

Commit 279f952

Browse files
committed
checkpoint. feeling out issue with DC spike and sampling
1 parent a5a03e7 commit 279f952

7 files changed

Lines changed: 731 additions & 1 deletion

File tree

‎hackrfpy/examples/collect_sample_data.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ def _validate_capture(iq, expected_n):
9393
if power_db < -70:
9494
reasons.append(f"suspiciously quiet ({power_db:.1f} dBFS -- "
9595
"dead antenna / wrong gain?)")
96+
peak = float(mag.max())
97+
if peak < 0.1:
98+
reasons.append(f"low ADC utilization (peak {peak:.3f} < 0.1, "
99+
f"~{int(peak*128)} of 127 int8 codes -- raise "
100+
"LNA/VGA; see examples/calibrate.py)")
96101
clip = float(np.mean(mag > 0.99))
97102
if clip > 0.01:
98103
reasons.append(f"clipping ({clip*100:.1f}% of samples -- "
@@ -128,7 +133,7 @@ def collect_band(h, name, args, suspects):
128133
f"({args.seconds}s, {args.sample_rate/1e6:g} Msps) ==")
129134
try:
130135
h.capture(band["center"], args.sample_rate, num_samples=n,
131-
out=iq_path, sigmf=True)
136+
out=iq_path, sigmf=True, lna=args.lna, vga=args.vga)
132137
iq = load_iq(iq_path)
133138
size_mb = os.path.getsize(iq_path) / 1e6
134139
print(f" wrote {os.path.basename(iq_path)} "
@@ -209,6 +214,11 @@ def main():
209214
help="sample rate in sps (default 2e6, small + USB-friendly)")
210215
p.add_argument("--sweep-count", type=int, default=1,
211216
help="sweeps per band dataset (default 1)")
217+
p.add_argument("--lna", type=int, default=32,
218+
help="LNA gain dB (default 32; the old library default of "
219+
"16 produced ~3-bit captures on 2026-09-17)")
220+
p.add_argument("--vga", type=int, default=28,
221+
help="VGA gain dB (default 28)")
212222
p.add_argument("--no-sweep", action="store_true",
213223
help="IQ captures only, skip sweep datasets")
214224
args = p.parse_args()

‎hackrfpy/examples/tx_test_tone.py‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#! /usr/bin/python3
2+
##--------------------------------------------------------------------\
3+
# hackrfpy 'examples/tx_test_tone.py'
4+
# The library's TX side, demonstrated the SAFE way: the deliberate
5+
# RX->TX mode switch (which prints the safety banner), a constant-wave
6+
# test tone via transmit_cw, and the dead-man duration bound so the
7+
# transmitter can never outlive the script.
8+
#
9+
# This is the only example that transmits. It is deliberately timid:
10+
# - duration is REQUIRED and capped at 10 s
11+
# - txvga defaults low; the RF amp is never enabled here
12+
# - --print-cmd previews the exact hackrf_transfer command w/o running
13+
#
14+
# TRANSMITTING IS REGULATED. Use a dummy load or a shielded setup, and
15+
# operate only within your license privileges and local law. A CW
16+
# carrier is useful for antenna checks and for giving a nearby receiver
17+
# (or your own second SDR) a known signal to find.
18+
#
19+
# Usage:
20+
# uv run python examples/tx_test_tone.py --freq 433.92M --seconds 2
21+
# uv run python examples/tx_test_tone.py --freq 915M --seconds 2 --print-cmd
22+
#
23+
#
24+
# Author(s): Lauren Linkous
25+
##--------------------------------------------------------------------\
26+
import argparse
27+
import sys
28+
29+
from hackrfpy import HackRF, parse_freq
30+
31+
MAX_SECONDS = 10.0
32+
33+
34+
def main():
35+
p = argparse.ArgumentParser(
36+
description="Bounded CW test-tone transmit (TX-gated).")
37+
p.add_argument("--freq", required=True,
38+
help="carrier frequency (parse_freq notation, e.g. 433.92M)")
39+
p.add_argument("--rate", default="2M", help="sample rate (default 2M)")
40+
p.add_argument("--seconds", type=float, required=True,
41+
help=f"transmit duration; required, max {MAX_SECONDS:g}s")
42+
p.add_argument("--txvga", type=int, default=4,
43+
help="TX VGA gain dB (default 4, deliberately low)")
44+
p.add_argument("--amplitude", type=int, default=64,
45+
help="CW DAC amplitude 0-127 (default 64)")
46+
p.add_argument("--print-cmd", action="store_true",
47+
help="preview the command without transmitting")
48+
p.add_argument("--tools-dir", default=None)
49+
args = p.parse_args()
50+
51+
if not args.print_cmd and not 0 < args.seconds <= MAX_SECONDS:
52+
print(f"--seconds must be in (0, {MAX_SECONDS:g}]", file=sys.stderr)
53+
return 2
54+
55+
h = HackRF(tools_dir=args.tools_dir, verbose=True)
56+
freq, rate = parse_freq(args.freq), parse_freq(args.rate)
57+
58+
# The deliberate confirmation: transmit() refuses in the default RX
59+
# mode, and this switch prints the one-time TX safety banner.
60+
h.set_mode("tx")
61+
h.transmit_cw(freq, rate, amplitude=args.amplitude, txvga=args.txvga,
62+
duration=args.seconds, print_cmd=args.print_cmd)
63+
h.set_mode("rx") # leave the object safe for whatever follows
64+
if not args.print_cmd:
65+
print(f"[*] transmitted {args.seconds:g}s CW at {freq/1e6:g} MHz")
66+
return 0
67+
68+
69+
if __name__ == "__main__":
70+
sys.exit(main())

0 commit comments

Comments
 (0)