@@ -35,10 +35,12 @@ def test_monitor_maps_freqs_to_segments(stub_device):
3535def test_monitor_tracks_power_change (stub_device ):
3636 h = stub_device (sweep = dict (stdout_lines = _TWO_PASS ))
3737 out = h .monitor_frequencies ([433e6 ], span_hz = 2e6 )
38- # 433 MHz segment rises from mean(-55,-50,-52,-58)=-53.75 to
39- # mean(-45,-40,-42,-48)=-43.75 between passes
38+ # 433 MHz sits in bin idx 2 of the 431-435 segment (1 MHz bins). The
39+ # reading is the max of bins 1..3: pass 1 max(-50,-52,-58) = -50, pass 2
40+ # max(-40,-42,-48) = -40 -- the covering bin, not the segment mean, so a
41+ # narrowband carrier is no longer diluted by its quiet neighbors.
4042 assert out [0 ][433e6 ] < out [1 ][433e6 ] # power increased
41- assert abs (out [1 ][433e6 ] - (- 43.75 )) < 0.1
43+ assert abs (out [1 ][433e6 ] - (- 40.0 )) < 0.1
4244
4345
4446def test_monitor_callback_mode (stub_device ):
@@ -59,3 +61,22 @@ def cb(u):
5961
6062 h .monitor_frequencies ([100e6 ], on_update = cb )
6163 assert calls ["n" ] == 1
64+
65+
66+ # ---- regression: covering-bin power, not segment mean ----------------------
67+ # A strong narrowband carrier in one bin of a wide segment must dominate the
68+ # reading. The old segment-mean proxy diluted it toward the noise floor.
69+ _HOT_BIN = [
70+ "2026-06-15, 12:00:00.000000, 430000000, 440000000, 1000000.00, 4, "
71+ "-80, -80, -80, -20, -80, -80, -80, -80, -80, -80" ,
72+ "2026-06-15, 12:00:01.000000, 430000000, 440000000, 1000000.00, 4, "
73+ "-80, -80, -80, -20, -80, -80, -80, -80, -80, -80" ,
74+ ]
75+
76+
77+ def test_monitor_reads_covering_bin_not_segment_mean (stub_device ):
78+ h = stub_device (sweep = dict (stdout_lines = _HOT_BIN ))
79+ out = h .monitor_frequencies ([433.5e6 ], span_hz = 1e6 )
80+ # 433.5 MHz -> bin idx 3 (the -20 dB carrier). The segment mean would
81+ # have read -74; the covering bin reads the carrier itself.
82+ assert abs (out [0 ][433.5e6 ] - (- 20.0 )) < 0.1
0 commit comments