packet_analysis
amber.packet_analysis
thermal_noise_watts
thermal_noise_watts(
bandwidth_hz: float, noise_figure_db: float = 6.0
) -> float
Calculate thermal noise power: N = k * T * B * NF
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bandwidth_hz
|
float
|
Bandwidth in Hz |
required |
noise_figure_db
|
float
|
Noise figure in dB, by default 6.0 |
6.0
|
Returns:
| Type | Description |
|---|---|
float
|
Thermal noise power in watts |
Source code in amber/packet_analysis.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
apply_sic
apply_sic(
powers_dbm: List[float],
noise_w: float,
required_sinr_db: float,
cancellation_factor: float = 0.9,
) -> Tuple[List[int], List[float]]
Apply Successive Interference Cancellation (SIC) algorithm.
SIC Algorithm:
- Sort packets by power (strongest first)
- Try to decode strongest packet (check SINR >= threshold)
- If successful, subtract signal (with imperfect cancellation)
- Re-calculate SINR for remaining packets
- Repeat until no more packets can be decoded
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
powers_dbm
|
List[float]
|
List of received powers at BS in dBm |
required |
noise_w
|
float
|
Thermal noise power in watts |
required |
required_sinr_db
|
float
|
Minimum SINR for successful decode |
required |
cancellation_factor
|
float
|
Cancellation factor is how much of a decoded signal can be subtracted out of the received signal before trying to decode the next packet. It's a value between 0 and 1, by default 0.9: 1.0 = perfect cancellation → the decoded signal is fully removed, leaving zero residual interference 0.9 = 90% cancellation → 10% of the decoded signal still leaks through as interference 0.0 = no cancellation → the decoded signal stays fully in the mix (equivalent to capture effect only) |
0.9
|
Returns:
| Type | Description |
|---|---|
Tuple[List[int], List[float]]
|
Indices of successfully decoded packets (in decode order) and their final SINR values |
Source code in amber/packet_analysis.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
detect_collisions
detect_collisions(
df: DataFrame,
bs_id: int,
noise_w: float,
required_sinr_db: float = 10.0,
enable_sic: bool = True,
) -> Tuple[List[CollisionEvent], Dict[int, str]]
Detect collisions with subcarrier awareness and SINR-based resolution.
Packets on different subcarriers do NOT collide. Packets on same subcarrier with time overlap -> check SINR for decode.
Uses SIC (Successive Interference Cancellation) algorithm:
- Sort packets by power (strongest first)
- Try to decode strongest (SINR >= threshold)
- If successful, subtract signal and repeat for next strongest
- Continue until no more packets can be decoded
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with packet information |
required |
bs_id
|
int
|
Base station ID |
required |
noise_w
|
float
|
Thermal noise power in watts |
required |
required_sinr_db
|
float
|
Minimum SINR for successful decode, by default 10.0 |
10.0
|
enable_sic
|
bool
|
Enable successive interference cancellation, by default True |
True
|
Returns:
| Type | Description |
|---|---|
Tuple[List[CollisionEvent], Dict[int, str]]
|
Tuple of (collision_events, packet_outcomes) packet_outcomes: {row_idx: "decoded" | "collision_loss" | "captured" | "sic_recovered"} |
Source code in amber/packet_analysis.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
analyze_packets
analyze_packets(
data_path: str,
num_bs: int,
num_nodes: int,
packet_sent: Iterable[int],
packet_received: Iterable[int],
required_sinr_db: float = 10.0,
enable_sic: bool = True,
noise_figure_db: float = 6.0,
bandwidth_hz: float = 100000000.0,
write_collision_log: Optional[
str
] = "collision_out.txt",
write_terminal_log: Optional[str] = "terminal_out.txt",
) -> PacketAnalysisResult
Packet analysis with subcarrier-aware, SINR-based collision detection.
Reads BSEngine rx log format (tab-separated): start_ms, end_ms, slot_id, node_id, payload, rssi_dbm, sector_idx, expected_node, matched, subcarrier_shift, collided, bs_id
Uses SIC (Successive Interference Cancellation) for collision resolution:
- SINR is computed dynamically based on actual colliding packets
- Capture effect is a special case of SIC (only strongest decoded)
- Multiple packets can be decoded if power differences allow
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path
|
str
|
Path to BSEngine rx log file. |
required |
num_bs
|
int
|
Number of base stations. |
required |
num_nodes
|
int
|
Number of nodes. |
required |
packet_sent
|
Iterable[int]
|
Packets sent per node. |
required |
packet_received
|
Iterable[int]
|
Packets received per node. |
required |
required_sinr_db
|
float
|
Minimum SINR for successful decode. |
10.0
|
enable_sic
|
bool
|
Enable successive interference cancellation. |
True
|
noise_figure_db
|
float
|
Receiver noise figure. |
6.0
|
bandwidth_hz
|
float
|
System bandwidth. |
100000000.0
|
write_collision_log
|
str
|
Path for collision log file. |
'collision_out.txt'
|
write_terminal_log
|
str
|
Path for terminal log file. |
'terminal_out.txt'
|
Returns:
| Type | Description |
|---|---|
PacketAnalysisResult
|
Per-BS and per-node statistics. |
Source code in amber/packet_analysis.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
load_packet_log
load_packet_log(path: str) -> Optional[pd.DataFrame]
Load packet log from BSEngine rx log file.
Expected format (tab-separated with headers): start_ms, end_ms, slot_id, node_id, payload, rssi_dbm, sector_idx, expected_node, matched, subcarrier_shift, collided
Source code in amber/packet_analysis.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |