You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.6 KiB
42 lines
1.6 KiB
#!/usr/bin/env python3 |
|
"""False-alarm check: preamble detection metric on noise-only buffers. |
|
|
|
Runs the acquisition stage on pure noise (buffers as long as a typical frame) |
|
and reports the distribution of the detection metric, to compare with the |
|
receiver's threshold (rx.acquire det_thresh, 4.0). |
|
|
|
./tools/noise_metric.py --sf 7 9 12 --trials 400 |
|
""" |
|
import os, sys |
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) |
|
import parallel # before numpy: one BLAS thread per worker |
|
import argparse |
|
from functools import partial |
|
import numpy as np |
|
import rx |
|
from phy import PhyParams |
|
from frame import build_frame |
|
|
|
|
|
def _one(rng, sf, n): |
|
p = PhyParams(sf=sf, osr=2) |
|
x = rng.standard_normal(n) + 1j * rng.standard_normal(n) |
|
s = rx.acquire(rx.decimate(x, p), p, det_thresh=0.0) |
|
return s.metric if s else 0.0 |
|
|
|
|
|
if __name__ == "__main__": |
|
ap = argparse.ArgumentParser() |
|
ap.add_argument("--sf", type=int, nargs="+", default=[7, 9, 12]) |
|
ap.add_argument("--trials", type=int, default=400) |
|
ap.add_argument("--seed", type=int, default=7) |
|
ap.add_argument("--jobs", type=int, default=parallel.default_jobs()) |
|
a = ap.parse_args() |
|
for sf in a.sf: |
|
p = PhyParams(sf=sf, osr=2) |
|
iq, _ = build_frame(p, b"\0" * 24, src="W1AW") |
|
n = len(iq) + 1200 |
|
m = np.array(parallel.run_trials(partial(_one, sf=sf, n=n), a.trials, a.seed, a.jobs)) |
|
print(f"SF{sf}: {a.trials} noise buffers x {n // (2 * p.M)} windows " |
|
f"metric max {m.max():.2f} 99.5th pct {np.percentile(m, 99.5):.2f} " |
|
f"median {np.median(m):.2f} (threshold 4.0)", flush=True)
|
|
|