Gain Adjustment

From my Pi 3

Edit: This was done with 10 second intervals for a total cycle of about 5 minutes each. I figure this gets a close snapshot of the sky rather than planes coming and going with 60 second intervals.


===Totals===
Gain, Messages, Positions, Aircraft
49.6 2793 369 22
48.0 2639 354 22
44.5 2740 348 24
43.9 2743 354 25
43.4 2674 351 23
42.1 2672 349 25
40.2 2804 373 24
38.6 2817 382 26
37.2 2821 386 25
36.4 2891 376 26
33.8 2927 398 27
32.8 2981 396 26
29.7 2872 366 26
28.0 2704 348 26
25.4 2629 343 25
22.9 2609 340 25
20.7 2582 326 25
19.7 2614 345 25
16.6 2423 310 27
15.7 2373 297 24
14.4 2201 292 24
12.5 2019 279 22
8.7 1928 274 21
7.7 1943 279 20
3.7 1909 263 20
2.7 1731 243 20
1.4 1431 194 19
0.9 1344 188 19
0.0 936 127 15

I got this error:


Traceback (most recent call last):
  File "./gain2.py", line 23, in <module>
    os.system("sudo /etc/init.d/dump1090-mutability restart")
NameError: name 'os' is not defined


Adding ā€˜osā€™ to the list of imported modules fixed it.

Pls explain for a noob, how do i run this script, and find the logfile? :slight_smile:

Yes, sorry, I had that of course, but missed it out in the version I copied/pasted. :unamused: Iā€™ve added it to the code above.

This is after running the test script on my system (FlightAware antenna in the roof space with about 20ft of RG6 to a FA Filter and ProStick in a Pi2) for 24 hours. (It clobbered my stats for the day as expected, but kept feeding data)

This was 70 iterations of the test, running 62 seconds each per gain setting.


===Totals===
Gain, Messages, Positions, Aircraft
20.7 498628 34177 1148
22.9 625771 42228 1291
25.4 678968 44266 1358
28.0 792787 52516 1451
29.7 836895 56191 1481
32.8 887074 59649 1499
33.8 911740 60627 1540
36.4 929263 62254 1542
37.2 937247 62541 1548
38.6 943844 62937 1569
40.2 958554 64469 1555
42.1 963873 64462 1545
43.4 981767 65265 1559
43.9 981427 65904 1561
44.5 985292 66594 1581
48.0 989690 66515 1573
49.6 997097 67386 1571

Messages and Positions peak at the highest gain. Aircraft peak at 44.5 dB. However, realistically, there is very little change in anything once above 33 dB.

I ran the script for 10 cycles of 1 minute earlier and was going to post graphs, but the results are very similar to yours. The number of messages and aircraft are both highest at maximum gain, though the difference between maximum gain and about 37dB is pretty small but below that get considerably worse. The only thing this doesnā€™t measure is the maximum range received during the period. The gain may affect that a bit, but because aircraft at maximum range tend to disappear quite suddenly it might not be easy to get a good indication with minute long changes.

obj made a gain scanning version of dump1090 which I think changed levels quite fast, thought Iā€™ve not tried it out.

Iā€™m using an LNA4ALL at the antenna for this, and not the Flightaware dongle.

Interesting python script! I like it!

Anyways, Iā€™ve been off here about a year and keep looking back every now and again, got a pro-stick and already had a Piaware filter which I hadnā€™t used yet.

Iā€™ve hooked them both together, ran the python script and hereā€™s the results:


pi@RaspberryPi3:~ $ python adsbtest.py
test 1 of 10
gain= 49.6 messages= 378 positions= 15 planes= 2
gain= 48.0 messages= 466 positions= 26 planes= 3
gain= 44.5 messages= 545 positions= 30 planes= 4
gain= 42.1 messages= 618 positions= 31 planes= 5
gain= 40.2 messages= 699 positions= 39 planes= 4
gain= 38.6 messages= 643 positions= 33 planes= 6
gain= 36.4 messages= 800 positions= 27 planes= 5
test 2 of 10
gain= 49.6 messages= 808 positions= 33 planes= 5
gain= 48.0 messages= 757 positions= 37 planes= 6
gain= 44.5 messages= 720 positions= 37 planes= 7
gain= 42.1 messages= 688 positions= 38 planes= 8
gain= 40.2 messages= 694 positions= 37 planes= 8
gain= 38.6 messages= 707 positions= 32 planes= 9
gain= 36.4 messages= 865 positions= 49 planes= 9
test 3 of 10
gain= 49.6 messages= 734 positions= 46 planes= 11
gain= 48.0 messages= 802 positions= 45 planes= 9
gain= 44.5 messages= 828 positions= 47 planes= 8
gain= 42.1 messages= 661 positions= 40 planes= 8
gain= 40.2 messages= 809 positions= 49 planes= 9
gain= 38.6 messages= 657 positions= 45 planes= 7
gain= 36.4 messages= 593 positions= 42 planes= 7
test 4 of 10
gain= 49.6 messages= 478 positions= 26 planes= 7
gain= 48.0 messages= 530 positions= 32 planes= 8
gain= 44.5 messages= 409 positions= 33 planes= 9
gain= 42.1 messages= 454 positions= 37 planes= 7
gain= 40.2 messages= 311 positions= 26 planes= 8
gain= 38.6 messages= 437 positions= 33 planes= 9
gain= 36.4 messages= 189 positions= 14 planes= 8
test 5 of 10
gain= 49.6 messages= 271 positions= 17 planes= 9
gain= 48.0 messages= 201 positions= 11 planes= 8
gain= 44.5 messages= 385 positions= 16 planes= 7
gain= 42.1 messages= 326 positions= 13 planes= 10
gain= 40.2 messages= 280 positions= 7 planes= 7
gain= 38.6 messages= 204 positions= 12 planes= 7
gain= 36.4 messages= 238 positions= 14 planes= 5
test 6 of 10
gain= 49.6 messages= 437 positions= 18 planes= 6
gain= 48.0 messages= 486 positions= 21 planes= 7
gain= 44.5 messages= 493 positions= 22 planes= 8
gain= 42.1 messages= 580 positions= 33 planes= 7
gain= 40.2 messages= 499 positions= 37 planes= 8
gain= 38.6 messages= 695 positions= 44 planes= 7
gain= 36.4 messages= 752 positions= 49 planes= 7
test 7 of 10
gain= 49.6 messages= 505 positions= 32 planes= 8
gain= 48.0 messages= 622 positions= 51 planes= 8
gain= 44.5 messages= 610 positions= 45 planes= 7
gain= 42.1 messages= 682 positions= 60 planes= 8
gain= 40.2 messages= 787 positions= 55 planes= 7
gain= 38.6 messages= 725 positions= 53 planes= 7
gain= 36.4 messages= 614 positions= 45 planes= 7
test 8 of 10
gain= 49.6 messages= 563 positions= 36 planes= 7
gain= 48.0 messages= 716 positions= 61 planes= 5
gain= 44.5 messages= 725 positions= 56 planes= 6
gain= 42.1 messages= 725 positions= 62 planes= 7
gain= 40.2 messages= 610 positions= 46 planes= 6
gain= 38.6 messages= 665 positions= 43 planes= 6
gain= 36.4 messages= 529 positions= 28 planes= 5
test 9 of 10
gain= 49.6 messages= 685 positions= 53 planes= 4
gain= 48.0 messages= 540 positions= 39 planes= 4
gain= 44.5 messages= 647 positions= 53 planes= 6
gain= 42.1 messages= 553 positions= 44 planes= 5
gain= 40.2 messages= 594 positions= 42 planes= 5
gain= 38.6 messages= 611 positions= 46 planes= 5
gain= 36.4 messages= 614 positions= 50 planes= 5
test 10 of 10
gain= 49.6 messages= 614 positions= 47 planes= 6
gain= 48.0 messages= 520 positions= 33 planes= 7
gain= 44.5 messages= 509 positions= 32 planes= 7
gain= 42.1 messages= 448 positions= 29 planes= 6
gain= 40.2 messages= 403 positions= 22 planes= 7
gain= 38.6 messages= 606 positions= 49 planes= 6
gain= 36.4 messages= 366 positions= 35 planes= 7

===Totals===
Gain, Messages, Positions, Aircraft
49.6 5473 323 14
48.0 5640 356 14
44.5 5871 371 16
42.1 5735 387 16
40.2 5686 360 15
38.6 5950 390 14
36.4 5560 353 14

Any recommendations and Iā€™ve forgotten how to change the gain if someone could point me in the right direction aha!

Seems like many people are seeing the same pattern with the Prostick and that script: gains above 35 or so all produce fairly similar results.

When I ran it I just stopped dump1090 service and let the script call the dump1090 executable directly.

If you wanted to keep piaware and mlat-client happier during a long testing process, one idea is to start the normal dump1090 service in net-only mode. Then have the gaintest script run a second instance of dump1090 (with all different ports) passing data to the original. This way piaware canā€™t see dump1090 is constantly being restarted. I havenā€™t tried it though.

Thanks for the script BartJr. It confirmed roughly where I thought my best gain setting was but its good to see some real data confirming it.

This is using a microstripline antenna directly connected to a PGA103 based LNA (both DIY) in a reasonably RF quiet area so no filter.
Presumably the PGA103ā€™s gain here is higher than LNA in the Flightaware pros but maybe some of the difference is due to coax / filter attenuation, It would be interesting to see results from a pro connected directly to the antenna.



This is great. Thanks BartJr & lignumaqua for the script, makes life easy. It came a bit late after I have found best settings by painstaking trial & error method. However I will run this script to see how my manual results match with the automated script results.

My Settings Found by Trial & Error

Pro Stick, No Filter, best settig 30 to 35 dB.

Pro Stick + Fliter, best setting ā€œmaxā€.

Note: Gain setting will vary with each individual system. It depends on antenna location, antenna gain, and loss in coax cable. Below are details of my system.

Antenna: Cantenna, gain 2 dBi
Location: indoors, but at 60 ft above ground near large glass window.
Coax cable: 12 ft / 4 m RG6 coax.
Amplifier: No amplifier.

1 Like

Have been following this thread for a bit, thanks for the script ideas :wink:

Is there a simple (or direct) way to access the rtl_sdr API without having to write something up behind the entire source tree to access: ā€œint rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain)ā€ ?

Iā€™d like to be able to alter the gain without the cludge of rewriting the dump1090-mutability parm tree and restarting with every iteration. Any pointers to follow, or would the best course of action include writing up another tool and compiling in with dump1090-mutability?

Regards,

This is how Iā€™ve been making quick gain adjustments.


sudo nano /etc/default/dump1090-mutability

Find this section


# RTLSDR gain in dB.
# If set to "max" (the default) the maximum supported gain is used.
# If set to "agc", the tuner AGC is used to set the gain.
GAIN="49.6"

and make your change. Save the file with CTRL-X, Y(es), Enter.
Then restart dump1090 withā€¦


sudo service dump1090-mutability restart

Good luck,

Yessir, thatā€™s basically what the script that was pasted above is doing as well. I was however looking to control via rtl_sdr (driver level) on the fly without requiring a dump1090 restart. For instance, SDR# can adjust using a slider - I realize completely different platformā€¦

(1) Give following command to create a blank file ā€œoptimize-gain.pyā€
Note: it is not necessary to name the file optimize-gain.py. You can use any name of your choice, but it must have .py at the end

sudo nano optimize-gain.py

(2) Copy-paste the script code in the blank file created above, save the file (ctrl+o), and exit (ctrl+x)
(3) Make the file executable:

sudo chmod +x optimize-gain.py

(3) Run the script:

sudo ./optimize-gain.py

(4) Find the log file:
I dont think any log file is generated.
The results are displayed in the SSH terminal progressively as these are conducted.
The totals of the test are displayed in the terminal at the end of test.
You can copy everything from terminal and paste into a text file & save the text file.

2 Likes

~$ sudo ./optimize-gain.py

===Totals===
Gain, Messages, Positions, Aircraft
49.6 23647 585 183
48.0 24298 594 175
44.5 24238 558 182
43.9 26731 613 189
43.4 26240 572 184
42.1 24494 663 183
40.2 25305 537 179
38.6 24298 602 177
37.2 25508 631 180
36.4 26784 615 170
33.8 27507 718 174
32.8 31027 767 181
29.7 28477 552 185
28.0 29911 656 188
25.4 31822 1187 188
22.9 31240 1035 186
20.7 33081 955 192

Lowest Gain (20.7) is the best ! :astonished: :open_mouth:

The above test was done on a secondary unit+antenna, located in a room, at not-so-good-a-signal location. The results of best setting = mininum (20.7) by script test can be understood easily if the message rate graph is seen.

The last 2 hours on right of graph is the period when python sript was running to find the optimization of gain.

Thank you abcd!


===Totals===
Gain, Messages, Positions, Aircraft
49.6 5653 1042 26
48.0 5717 1055 24
44.5 5669 1042 25
43.9 5717 1058 26
43.4 5481 980 26
42.1 5348 1006 26
40.2 5046 954 26
38.6 5160 947 25
37.2 5397 989 25
36.4 5309 958 27
33.8 5360 976 25
32.8 5579 1022 23
29.7 5800 1054 24
28.0 5493 999 25
25.4 5540 1013 23
22.9 5492 995 25
20.7 5428 994 23


You can use any one. Liqmanguaā€™s scripts are BartJrā€™s script with some customization. I used the last script by liquamangua (click here)

Now that I have a spare cpu and RF chain again (PI 3, FlightAware dongle and filter), Iā€™m running gain sweeps, feeding that chain from a splitter on an operating ADS-B feeder.

Also looking at PPM correction ā€“ how important is that, and is this something that could be done (optionally) on dump1090-mutability startup?

Iā€™ve also altered process priorities on the key processed involved:


13:36 pi@wombat ~ $ whatshot
  833 dump1090  15  -5   32168  13912   2116 S  24.2  1.5   1951:38 dump1090-mutabi
  848 root      15  -5   23480   8596   4816 S   0.0  0.9 105:08.93 piaware
  883 root      15  -5    2952   1704   1532 S   0.0  0.2  28:25.94 faup1090
15246 root      15  -5   13232  10024   5732 S   0.0  1.1  90:34.39 fa-mlat-client
13:47 pi@wombat ~ $ 


Obj does this starting up dump1090-mobility. Iā€™ve extended it to the rest of the processing chain, so that when I do something that would otherwise suck up a lot of system resources, such as an update, or a compressed TAR backup, the ADS-B chain still has priority.

bob k6rtm