Last active
September 20, 2021 22:19
-
-
Save varnav/b16a8a47a1d8933cf78a5cdf7d7aa24e to your computer and use it in GitHub Desktop.
Readsb: Analyze strong signal percentage and give gain recommendation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# This script will find out what strong messages percentage is and | |
# advise you to tune gain to keep it in range from 0.5% to 5%. | |
# Can be used as one-liner on some systems: | |
# python3 <(curl -s https://gist.githubusercontent.com/varnav/b16a8a47a1d8933cf78a5cdf7d7aa24e/raw/811afe852797845931b528e8e82f13b45c864ed4/gain-advisor.py) | |
# Evgeny Varnavskiy 2021 | |
# https://gist.github.com/varnav/ | |
# See also: | |
# https://github.com/wiedehopf/adsb-scripts/wiki/Optimizing-gain | |
# https://github.com/wiedehopf/adsb-scripts/wiki/Automatic-gain-optimization-for-readsb-and-dump1090-fa | |
import json | |
# Typical possible gain values | |
gains = "20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6" | |
try: | |
with open('/run/readsb/stats.json') as f: | |
data = json.load(f) | |
except IOError: | |
with open('/run/dump1090-fa/stats.json') as f: | |
data = json.load(f) | |
if (data["total"]["end"] - data["total"]["start"]) < 3600: | |
print("Statistics are collected for less that 1h and may be inaccurate") | |
strong = data["total"]["local"]["strong_signals"] | |
total = data["total"]["local"]["accepted"][0] + data["total"]["local"]["accepted"][1] | |
# It's logarithmic values - this is why it's substraction and not division | |
# snr = round(data["total"]["local"]["signal"] - data["total"]["local"]["noise"]) | |
# print("Signal to noise ratio (SNR):", snr) | |
perc = round((strong * 100 / total), 2) | |
print("Too strong messages percentage:", perc) | |
if perc > 5: | |
print("Decrease gain") | |
print("Typical possible gain values:", gains) | |
elif perc < 0.5: | |
print("Increase gain") | |
print("Typical possible gain values:", gains) | |
else: | |
print("Gain optimal") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment