from __future__ import division
import numpy as np
from numpy import *
from numpy.fft import *
from rtadsb import rt_flight_radar
The function rt_flight_radar() in rtadsb.py creates a real-time flight position plot using your preamble detection function and the data2bit() function. Decoding the packets is beyond the scope of this lab. However, if you are interested you can take a look at these links:
Our ADS-B decoder essentially follows the dump1090 software for mode S decoding. We first correct for 1-bit errors using the checksum in the packet and look for specific ADS-B message types that we are interested in. Most aircraft information (position, velocity, angle, altitude and flight number) can only be transmitted using the long squitters so we will actually ignore the short squitters. It turns out that even the long squitter is too short for precise latitude/longitude bits, so the aircraft positions are further split into 2 different packets called even and odd during transmittion. A more complicated reconstruction method is used to extract position from the two packets. You can read http://www.lll.lu/~edward/edward/adsb/DecodingADSBposition.html for more detail.
Copy and paste your detectPreamble()
and data2bit()
functions to the code cell below. Scroll down to the bottom and you should be able to rt_flight_radar()! To receive the ads-b packets from planes, it is recommended you are outside during daytime. It is also recommended to use Chrome to view the map. (Some parts of the map become blank on Safari, but you can fix it by resizing your browser).
If a plane with position information is detected, it will be shown as a blue cross on the map. If a flight number is decoded, it will be shown next with the blue blob. It might take some time to detect a plane, but be patient. When an ADS-B packet from a plane is decoded, a Found a plane
string will be printed. However, it might not be on the map because its position information is not received.
# Your detectPreamble and data2bit functions below:
fs = 2000000; # 2MHz sampling frequency
center_freq = 1090e6 # 1090 MHz center frequency
gain = 49.6 # gain
N_samples = 2048000 # number of sdr samples for each chunk of data
pos_ref = [37.875219, -122.257939] # Berkeley's latitude, longitude for initializing the map
functions = (detectPreamble, data2bit)
# Run flight radar
stop_flag = rt_flight_radar( fs, center_freq, gain, N_samples, pos_ref, functions )
# Run this to stop
stop_flag.set()