SnrScheduler
The module snrhelper.py implements the adaptive SNR iterator SnrScheduler.
- class neoradium.snrhelper.SnrScheduler(snr0=0, step=1, loSnrVal=100, hiSnrVal=0, fastStep=None, maxSnrs=100)
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).
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)
fastStep (float or None) – If specified, the
fastStepis used during initial searching until we find a point inside the range specified by loSnrVal and hiSnrVal. Once a point is found in the range, thestepparameter is used. If not specified, it is set to2 * step.maxSnrs (int) – Hard cap on the number of recorded SNR points; used as a safeguard against non-monotonic behavior or failure to converge (default: 100).
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). # The defaults are oriented for decreasing-with-SNR metrics like BLER/BER: at low SNR the metric is # near 100%, at high SNR it approaches 0%. Hence loSnrVal > hiSnrVal. 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. Only SNRs within the converged bracket \([curLo, curHi]\) are returned; the bracketing-phase endpoints outside that range are silently dropped.
- Returns:
Noneif no iterations have been run yet (i.e.,setData()was never called). Otherwise a listlof lengthn+2, wherenis the number of parameters in theotherValuesargument ofsetData():l[0]: 1-Dfloat32NumPy array of SNR values, sorted ascending.l[1]: 1-Dfloat32NumPy array of the primary metric (e.g. BLER) values corresponding tol[0].l[i+2](0 <= i < n): a Python list of values for the i’thotherValuesparameter, ordered to matchl[0]. Elements may be scalars or NumPy arrays of variable shape (NumPy can’t always stack them, so a list is returned).
- Return type:
list or None