SnrScheduler
The module snrhelper.py implements the adaptive SNR iterator SnrScheduler.
- class neoradium.snrhelper.SnrScheduler(snr0=0, step=1, maxSnrs=500, loSnrVal=100, hiSnrVal=0)
Use this class as an adaptive SNR iterator to step through SNR values while measuring a metric such as Bit Error Rate (BER), Block Error Rate (BLER), or throughput. Starting from an initial SNR guess, it adaptively searches until it brackets a usable range and then traverses from the low to the high operating point.
The iterator enforces that setData(…) is called once per loop iteration to report the metric value(s) computed at the current SNR.
- Parameters:
snr0 (float) – Initial SNR in dB. Pick a mid-range guess if possible (default: 0.0).
step (float) – SNR increment in dB used when moving up/down (default: 1.0).
maxSnrs (int) – Hard cap on the number of recorded SNR points; used as a safeguard against non-monotonic behavior or failure to converge (default: 500).
loSnrVal (float) – Target metric value associated with the low SNR operating point. Example for BLER (%): 100. (default: 100)
hiSnrVal (float) – Target metric value associated with the high SNR operating point. Example for BLER (%): 0. (default: 0)
Notes
For BER/BLER, metrics generally decrease with SNR (loSnrVal > hiSnrVal).
For throughput, metrics often increase with SNR (loSnrVal < hiSnrVal).
The scheduler handles both cases.
Examples# Start at -8 dB, use increments of 0.2 dB for BLER using default values (loSnrVal=100, hiSnrVal=0) snrScheduler = SnrScheduler(snr0=-8, step=.2) # Start at 0 dB, use increments of 0.5 dB for BER in the range %10 to %45 snrScheduler = SnrScheduler(snr0=0, step=.5, loSnrVal=45, hiSnrVal=10) # Start at -4 dB, use increments of 0.5 dB for throughput in the range %0 to %100. Note that # direction of changes in this case is the opposite of BER/BLER cases. (loSnrVal < hiSnrVal) snrScheduler = SnrScheduler(snr0=-4, step=1, loSnrVal=0, hiSnrVal=100)
- reset()
Reset to the initial state; typically called before the SNR loop inside an outer-loop.
- setData(value, *otherValues)
Record the metric(s) for the current SNR and advance the internal state.
You MUST call this at the end of each loop iteration; otherwise a ValueError is raised on the next iteration.
- Parameters:
value (float) – Primary metric used to drive scheduling (e.g., BLER, BER, throughput).
otherValues (tuple of float, optional) – Additional values to store per SNR. The arity must be consistent across iterations. These are returned by
getSnrsAndData()after the loop.
ExamplesnrScheduler = SnrScheduler(snr0=7, step=.2) # Instantiate the SnrScheduler for BLER for snrDb in snrScheduler: # Start your loop # ... # Calculate "ber" and "bler" values in your loop for current snrDb # ... # Call setData with 'bler' as the main metric and 'ber' as 'otherValues'. snrScheduler.setData(bler, ber) # After the loop, call the 'getSnrsAndData' method. It returns 3 numpy arrays for SNR values, # the corresponding BLER values, and the corresponding BER values. snrs, blers, bers = snrScheduler.getSnrsAndData()
- getSnrsAndData()
Return recorded SNRs and their associated metric arrays.
- Returns:
A list of numpy arrays:
index 0: sorted SNR values inside the finalized [Lo, Hi] bracket
index 1: primary metric values aligned with the SNRs
index 2+: additional arrays for each otherValues stream
- Return type:
list[np.ndarray]