Gain Adjustment

I’m having trouble obtaining & deploying the optimize-gain-piaware3.py script.I am running PiAware 3.6.3 on an SD card, with a FA Pro stick.

When I type in

wget https://raw.githubusercontent.com/wittrup/piawarebash/master/pyh/optimize-gain-piaware3.py

I get “Cannot write to ‘optimize-gain-piaware3.py’ (Permission denied).”

I’m a real newb when it comes to all this - can someone help point me in the right direction so I can try to determining the optimum gain for my setup?

you are in a folder where you don’t have write permission.

use

cd

to get back to the home directory you should have write permissions there.
then run the wget command again and follow the instructions.

i don’t particularly like the gain script.
i would use the tabular display of your local map
Screenshot%20from%202018-11-09%2022-38-21

Sort the planes by RSSI by clicking on the column head (twice or until it’s sorted with values closer to 0 at the top)
The closer to 0 a value is the stronger the signal.

Make sure not too many have a value > -3

If you have no planes > -6 or so just go ahead and increase the gain.

Now if you have sometimes low traffic coming close by (general aviation for example)
their signal might become too strong.

So if on the map you use the button “show all track” and some low level tracks are interrupted near the receiver that’s a good hint that your gain was too high to receive them.
(assuming they didn’t duck behind a hill or something)

@mblacklin

looking at your stats and assuming you have been running with gain -10 until now.

pretty sure -10 is the best setting for you already.

Which antenna are you using and is it indoors?

I’m using the 26” FA antenna, mounted outside, about 12’ off the ground.

you are close to an airport. that’s always complicated.
also it could be that weaker signals from further away are being drowned in cell phone noise.

anyways what’s your current gain and why don’t you make a screenshot of the table i mentioned?

what also is a consideration are there hills around you that are higher than your position?
or buildings?
i mean in all directions most people will have hills in some directions :wink:

Here’s a snippet of what I’ve got. Values run all the way to -30. Gain is currently set to 20. I had it at 40, without much change.

you need do restart dump1090-fa or the gain doesn’t actually change

systemctl restart dump1090-fa

Yes, I restart dump1090-fa each time.

changing between 20 and 40 you should see a change.
try 1 then.

how are you changing gain?

you need to use

sudo piaware-config rtlsdr-gain 10

you need a sudo for the dump1090-fa restart as well (or it will show you an error)

this command will show you the current gain dump1090-fa was started with:

journalctl -u dump1090-fa -e --no-pager

That works only for the case that he has flashed the SD card image from FA.
If he installed Piaware and dump1090-fa as add-on (via commands), then the gain needs to be changed directly:

sudo nano /etc/default/dump1090-fa

Followed by
sudo systemctl restart dump1090-fa

And the check:
sudo systemctl status dump1090-fa -l

I am currently trying to run the test script for demonstration purposes

But i am getting an error in line 37:

  File "gain.py", line 37
    for l in d.split('
                     ^
SyntaxError: EOL while scanning string literal

What did i do wrong? I changed values in the first few lines, but nothing where the fault is coming up.

EDIT:
This issue is fixed, the script is running now
But it only shows message values. the values for position and aircraft is 0 in all results
I am running latest dump1090-fa

EDIT2: Fixed it by using the correct script for FA here:
https://www.dropbox.com/s/4bhv5q9rdu3p5bp/Optimize-Gain-dump-fa-on-Raspbian-Jessie.docx?dl=1

Seem to be that the gain settings above 40 are pretty similar each other on the blue FA pro plus stick.

-10 is not an option, obviously too much noise and below 40 is decreasing performance.

All tested with an optimized antenna mounted indoor. Will run it again once the antenna is mounted outoor
Test is just a snapshot as seen from the results. some minutes later, a different gain setting can be the better one.

For me indoor i leave it to 49.6

test 1 of 5
gain= -10 messages= 26776 positions= 1148 planes= 89
gain= 49.6 messages= 29137 positions= 1302 planes= 88
gain= 48.0 messages= 28762 positions= 1280 planes= 86
gain= 44.5 messages= 28380 positions= 1227 planes= 84
gain= 42.1 messages= 27719 positions= 1249 planes= 79
gain= 40.2 messages= 28135 positions= 1242 planes= 85
gain= 36.4 messages= 26656 positions= 1174 planes= 86
gain= 32.8 messages= 25229 positions= 1137 planes= 78
gain= 29.7 messages= 25183 positions= 1127 planes= 75
test 2 of 5
gain= -10 messages= 25542 positions= 1080 planes= 94
gain= 49.6 messages= 28507 positions= 1235 planes= 89
gain= 48.0 messages= 28498 positions= 1233 planes= 86
gain= 44.5 messages= 28498 positions= 1262 planes= 79
gain= 42.1 messages= 28014 positions= 1234 planes= 81
gain= 40.2 messages= 27265 positions= 1195 planes= 84
gain= 36.4 messages= 24811 positions= 1021 planes= 77
gain= 32.8 messages= 25387 positions= 1071 planes= 71
gain= 29.7 messages= 24133 positions= 1054 planes= 77
test 3 of 5
gain= -10 messages= 27038 positions= 1175 planes= 88
gain= 49.6 messages= 28498 positions= 1235 planes= 90
gain= 48.0 messages= 28534 positions= 1251 planes= 90
gain= 44.5 messages= 28192 positions= 1313 planes= 93
gain= 42.1 messages= 27914 positions= 1285 planes= 97
gain= 40.2 messages= 27890 positions= 1230 planes= 98
gain= 36.4 messages= 26291 positions= 1220 planes= 88
gain= 32.8 messages= 25806 positions= 1136 planes= 83
gain= 29.7 messages= 22316 positions= 1027 planes= 82
test 4 of 5
gain= -10 messages= 25939 positions= 1128 planes= 104
gain= 49.6 messages= 28279 positions= 1259 planes= 98
gain= 48.0 messages= 28529 positions= 1276 planes= 97
gain= 44.5 messages= 28024 positions= 1242 planes= 96
gain= 42.1 messages= 28043 positions= 1284 planes= 93
gain= 40.2 messages= 28322 positions= 1299 planes= 93
gain= 36.4 messages= 27573 positions= 1291 planes= 87
gain= 32.8 messages= 26231 positions= 1271 planes= 83
gain= 29.7 messages= 25490 positions= 1194 planes= 82
test 5 of 5
gain= -10 messages= 26727 positions= 1209 planes= 94
gain= 49.6 messages= 30310 positions= 1358 planes= 96
gain= 48.0 messages= 29124 positions= 1346 planes= 91
gain= 44.5 messages= 28749 positions= 1380 planes= 90
gain= 42.1 messages= 28786 positions= 1370 planes= 94
gain= 40.2 messages= 29306 positions= 1408 planes= 91
gain= 36.4 messages= 28111 positions= 1387 planes= 83
gain= 32.8 messages= 28797 positions= 1340 planes= 83
gain= 29.7 messages= 27201 positions= 1301 planes= 85

===Totals===
Gain, Messages, Positions, Aircraft
-10 132022 5740 205
49.6 144731 6389 204
48.0 143447 6386 197
44.5 141843 6424 196
42.1 140476 6422 201
40.2 140918 6374 199
36.4 133442 6093 192
32.8 131450 5955 185
29.7 124323 5703 181
1 Like

After moving to a new appartment, my antenna (or better: The whole device including the antenna) went outside to the balcony.

I did a quick check and it looks like 44.5 will be the best option for now, the others are close as well.
Will try it and make another test at another day.

test 1 of 5
gain= 49.6 messages= 17984 positions= 879 planes= 76
gain= 48.0 messages= 18890 positions= 906 planes= 74
gain= 44.5 messages= 18221 positions= 913 planes= 75
gain= 42.1 messages= 18035 positions= 881 planes= 72
gain= 40.2 messages= 18574 positions= 873 planes= 72
gain= 36.4 messages= 17740 positions= 875 planes= 71
gain= 33.8 messages= 17799 positions= 879 planes= 71
test 2 of 5
gain= 49.6 messages= 18775 positions= 913 planes= 77
gain= 48.0 messages= 19206 positions= 956 planes= 77
gain= 44.5 messages= 19310 positions= 974 planes= 78
gain= 42.1 messages= 18810 positions= 958 planes= 73
gain= 40.2 messages= 18530 positions= 894 planes= 78
gain= 36.4 messages= 18121 positions= 927 planes= 74
gain= 33.8 messages= 18169 positions= 951 planes= 70
test 3 of 5
gain= 49.6 messages= 19290 positions= 967 planes= 77
gain= 48.0 messages= 19310 positions= 975 planes= 78
gain= 44.5 messages= 18538 positions= 955 planes= 78
gain= 42.1 messages= 18413 positions= 905 planes= 79
gain= 40.2 messages= 18653 positions= 945 planes= 78
gain= 36.4 messages= 18263 positions= 945 planes= 72
gain= 33.8 messages= 17835 positions= 896 planes= 71
test 4 of 5
gain= 49.6 messages= 18437 positions= 947 planes= 76
gain= 48.0 messages= 18301 positions= 946 planes= 74
gain= 44.5 messages= 17978 positions= 951 planes= 74
gain= 42.1 messages= 17974 positions= 955 planes= 74
gain= 40.2 messages= 17683 positions= 971 planes= 71
gain= 36.4 messages= 17257 positions= 934 planes= 71
gain= 33.8 messages= 17472 positions= 931 planes= 71
test 5 of 5
gain= 49.6 messages= 18237 positions= 948 planes= 77
gain= 48.0 messages= 17573 positions= 951 planes= 76
gain= 44.5 messages= 18610 positions= 991 planes= 75
gain= 42.1 messages= 18506 positions= 1008 planes= 74
gain= 40.2 messages= 18359 positions= 939 planes= 75
gain= 36.4 messages= 17579 positions= 940 planes= 73
gain= 33.8 messages= 17175 positions= 910 planes= 68
===Totals===
Gain, Messages, Positions, Aircraft
49.6 92723 4654 123
48.0 93280 4734 123
44.5 92657 4784 125
42.1 91738 4707 119
40.2 91799 4622 120
36.4 88960 4621 119
33.8 88450 4567 116

I have used the blue dongle with a 15’ long cable and I had to go to 40 in my area to minimize lost samples. I have airplanes flying almost directly above me ( a few miles over is a major traffic lane).
So gain IMO it’s all about location and antenna gain.

it 's is really 90° above you, there is a kind of a blind spot where signal gets lost.
I don’t have problems even if aircraft are less than 2000 ft on altitude and less than 2 miles away

I did the test again today over the day. Interestingly it gave me 44.5 which should perform the best. However the number of aircraft and the number of messages dropped after switching to it: The red line indicates where i changed it.

Also the number of messages > -3db did not change that much as i would have expected it.

This comparison is meaningless.
At least try to account for traffic, compare a week with one setting to another week with the other setting.

2 Likes

Ok, will try it, thanks

This script is recommended: GitHub - caiusseverus/adsbcompare: Tools to plot and compare data gathered with graphs1090

But without having a reference setup it’s really hard to draw conclusions.

Is it still possible to run this in 2020 to test the different gain values? I’ve tried and just get errors.

pi@piaware:~ $ #!/usr/bin/python2
pi@piaware:~ $ import time, socket, subprocess, fileinput, os
-bash: import: command not found
else:
print line,
os.system(“sudo systemctl restart dump1090-fa”)
time.sleep(2)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((‘localhost’,30003))
t = time.time()
d = ‘’
while 1:
d += s.recv(32)
if time.time() - t > measure_duration:
break
s.close()
messages = 0
positions = 0
planes = {}
pi@piaware:~ $
for l in d.split(‘\n’):
a = l.split(‘,’)
messages += 1
if len(a) > 4:
if a[1] == ‘3’:
positions += 1
planes[a[4]] = 1
print “gain=”,g, “messages=”, messages, “positions=”, positions, “planes=”, len(planes.keys())
results[g][0] += messages
results[g][1] += positions
for hex in planes.keys():
results[g][2][hex] = 1

print “\n===Totals===”
print “Gain, Messages, Positions, Aircraft”
for g in gains:
(messages,positions,planes) = results[g]
pi@piaware:~ $ measure_duration = 62 #duration of one pass, seconds
-bash: measure_duration: command not found
print g, messages, positions, len(planes.keys())
pi@piaware:~ $ ntests = 5 #number of tests
-bash: ntests: command not found
pi@piaware:~ $ 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”.split()
-bash: syntax error near unexpected token `(’
pi@piaware:~ $ #gains = “20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4”.split()
pi@piaware:~ $ #gains = “36.4 38.6 40.2 42.1 44.5 48.0 49.6”.split()
pi@piaware:~ $
pi@piaware:~ $ gains.reverse()

results = {}
-bash: syntax error near unexpected token results' pi@piaware:~ $ pi@piaware:~ $ for i in range(ntests): -bash: syntax error near unexpected token (’
pi@piaware:~ $ print “test”, i+1, “of”, ntests
Error: no such file “test,”
Error: no such file “i+1,”
Error: no such file “of,”
Error: no such file “ntests”
pi@piaware:~ $ for g in gains:
if g not in results:
-bash: syntax error near unexpected token if' pi@piaware:~ $ results[g] = [0,0,{}] #msgs, positions, aircraft -bash: results[g]: command not found pi@piaware:~ $ pi@piaware:~ $ for line in fileinput.input('/etc/default/dump1090-fa', inplace=1): -bash: syntax error near unexpected token (’
pi@piaware:~ $ if line.startswith(‘RECEIVER_OPTIONS’):
-bash: syntax error near unexpected token 'RECEIVER_OPTIONS'' pi@piaware:~ $ print 'RECEIVER_OPTIONS="--device-index 0 --ppm 0 --gain ' + g + ' --net-bo-port 30005 --net-sbs-port 30003"' Error: no such file "RECEIVER_OPTIONS="--device-index 0 --ppm 0 --gain " Error: no such file "+" Error: no such file "g" Error: no such file "+" Error: no such file " --net-bo-port 30005 --net-sbs-port 30003"" pi@piaware:~ $ else: -bash: else:: command not found pi@piaware:~ $ print line, Error: no such file "line," pi@piaware:~ $ os.system("sudo systemctl restart dump1090-fa") -bash: syntax error near unexpected token “sudo systemctl restart dump1090-fa”’
pi@piaware:~ $ time.sleep(2)
-bash: syntax error near unexpected token 2' pi@piaware:~ $ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -bash: syntax error near unexpected token (’
pi@piaware:~ $ s.connect((‘localhost’,30003))
-bash: syntax error near unexpected token (' pi@piaware:~ $ t = time.time() -bash: syntax error near unexpected token (’
pi@piaware:~ $ d = ‘’
-bash: d: command not found
pi@piaware:~ $ while 1:
d += s.recv(32)
-bash: syntax error near unexpected token (' pi@piaware:~ $ if time.time() - t > measure_duration: -bash: syntax error near unexpected token -’
pi@piaware:~ $ break
-bash: break: only meaningful in a for', while’, or until' loop pi@piaware:~ $ s.close() messages = 0 -bash: syntax error near unexpected token messages’
pi@piaware:~ $ positions = 0
-bash: positions: command not found
pi@piaware:~ $ planes = {}
-bash: planes: command not found
pi@piaware:~ $ for l in d.split(‘\n’):
-bash: syntax error near unexpected token (' pi@piaware:~ $ a = l.split(',') -bash: syntax error near unexpected token (’
pi@piaware:~ $ messages += 1
-bash: messages: command not found
pi@piaware:~ $ if len(a) > 4:
-bash: syntax error near unexpected token a' pi@piaware:~ $ if a[1] == '3': positions += 1 planes[a[4]] = 1 print "gain=",g, "messages=", messages, "positions=", positions, "planes=", len(planes.keys()) -bash: syntax error near unexpected token (’
pi@piaware:~ $ results[g][0] += messages
-bash: results[g][0]: command not found
pi@piaware:~ $ results[g][1] += positions
-bash: results[g][1]: command not found
pi@piaware:~ $ for hex in planes.keys():
-bash: syntax error near unexpected token (' pi@piaware:~ $ results[g][2][hex] = 1 -bash: results[g][2][hex]: command not found pi@piaware:~ $ pi@piaware:~ $ print "\n===Totals===" Error: no such file "\n===Totals===" pi@piaware:~ $ print "Gain, Messages, Positions, Aircraft" Error: no such file "Gain, Messages, Positions, Aircraft" pi@piaware:~ $ for g in gains: (messages,positions,planes) = results[g] -bash: syntax error near unexpected token (’
pi@piaware:~ $ print g, messages, positions, len(planes.keys())
-bash: syntax error near unexpected token `(’