# Gain Adjustment

**URL:** <https://discussions.flightaware.com/t/gain-adjustment/18376>\
**Category:** ADS-B Flight Tracking\
**Created:** [April 26, 2016, 5:27am UTC](https://discussions.flightaware.com/t/gain-adjustment/18376 "2016-04-26T05:27:33Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![BartJr](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/bartjr/32/33888_2.png) [@BartJr](https://discussions.flightaware.com/u/BartJr)\
**Post date:** [April 26, 2016, 4:03pm UTC](https://discussions.flightaware.com/t/gain-adjustment/18376/7 "2016-04-26T16:03:12Z")

</div>

> [@cptdevine](#):
>
> I’ve been wanting to setup a script to change the gain setting once every hour to test each setting and find the best results.

I wrote a script to sort of do this. I only ran for 15 second intervals because the amount of traffic can change a lot throughout the day. But you can try different durations.

It gives an output like:

```auto

test 1 of 10
gain= 49.6 messages= 771 positions= 41 planes= 49
gain= 48.0 messages= 742 positions= 43 planes= 51
gain= 44.5 messages= 785 positions= 37 planes= 51
gain= 40.2 messages= 677 positions= 35 planes= 51
gain= 37.2 messages= 743 positions= 32 planes= 48
gain= 32.8 messages= 711 positions= 37 planes= 46
test 2 of 10
gain= 49.6 messages= 667 positions= 32 planes= 44
...
test 10 of 10
gain= 49.6 messages= 757 positions= 43 planes= 49
gain= 48.0 messages= 814 positions= 37 planes= 51
gain= 44.5 messages= 830 positions= 37 planes= 50
gain= 40.2 messages= 766 positions= 49 planes= 43
gain= 37.2 messages= 671 positions= 31 planes= 50
gain= 32.8 messages= 651 positions= 27 planes= 43

===Totals===
Gain, Messages, Positions, Aircraft
49.6 6925 361 73
48.0 7230 331 76
44.5 7149 347 75
40.2 6883 352 71
37.2 7071 351 69
32.8 6653 332 69

```

Plotting the data into excel you can give helpful graphs

 ![](https://us1.discourse-cdn.com/flex019/uploads/flightaware/original/3X/2/2/2271abf6d9f8caf0740a4c82bb6b440c93ba6a85.png)  
Although for tuning the Prostick it didn’t help me that much, since a lot of gains gave similar results ❓  
 ![](https://us1.discourse-cdn.com/flex019/uploads/flightaware/original/3X/8/b/8b03798c68787b6594505a79cc2eb7372810a4f0.png)  
Here’s the code. It’s pretty dumb (like it just waits 2 seconds after starting dump1090 rather than checking to see if dump1090 is actually ready). You probably want to change the measure\_duration, ntests, and gains variables at the top.

Stop any existing dump1090 process before running the script. **sudo /etc/init.d/fadump1090.sh stop** or \*\*sudo service dump1090-mutability stop  
\*\*

```auto

#!/usr/bin/python2
import time, socket, subprocess

measure_duration = 15 #seconds
ntests = 10 #Number of tests
mutability = False #set to True if you use dump1090-mutability
#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()
gains = "36.4 38.6 40.2 42.1 44.5 48.0 49.6".split()
#gains = "22.9 25.4 28.0 29.7 32.8 33.8 36.4".split()
gains.reverse()
results = {}

for i in range(ntests):
  print "test", i+1, "of", ntests 
  for g in gains:
	if g not in results:
		results[g] = [0,0,{}] #msgs, positions, aircraft
	if mutability:
  	  p = subprocess.Popen(('/usr/bin/dump1090-mutability --net --gain '+g+' --oversample --fix --phase-enhance --quiet').split(),shell=False,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
	else:
  	  p = subprocess.Popen(('/usr/bin/dump1090 --net --gain '+g+' --quiet').split(),shell=False,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
	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()
	p.terminate()
	messages = 0
	positions = 0
	planes = {}
	for l in d.split('
'):
		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 "
===Totals==="
print "Gain, Messages, Positions, Aircraft"
for g in gains:
	(messages,positions,planes) = results[g]
	print g, messages, positions, len(planes.keys())

```

---

_[View the full topic](https://discussions.flightaware.com/t/gain-adjustment/18376)._
