Wednesday, December 16, 2015

Acquiring GPS signals with an RTLSDR dongle using gnss-sdr

Once you've installed gnss-sdr and tested your installation with prerecorded data, the next step is to try and get a live GPS solution. The following is based off this node at gnss-sdr.org and this paper. The paper is a really good mix of theory and implementation and I strongly recommend reading it.

The first thing you need to do is calibrate the front end of your RTL-SDR device. The calibration procedure will do the following
  1. Download an ephemeris via SUPL. This provides your computer with advance knowledge of the GPS satellite locations, allowing you to get a quick fix.
  2. Search for GPS satellites
  3. Calculate the doppler shift assuming your RTL-SDR stick is perfect (trust me, it's not!)
  4. Using the predicted doppler shift and some fancy math (see the paper, section 5), calculate
    1. The actual sampling frequency
    2. The actual IF bias

Before running the calibration you need to update the front-end-cal.conf. Make a copy of the version installed (typically to /usr/local/share/gnss-sdr/conf/front-end-cal.conf). On the first couple of lines you will see a number of GPS lat/lon/alt locations commented out using a semicolon. You need to provide your best estimate at lat/lon/alt, bearing in mind altitude is in meters. The easiest way to do this is use a tool like the aptly named mapcoordinates.net. The other change I had to make was to change both SUPL servers to supl.google.com in place of supl.nokia.com - for some reason the nokia servers were not working. Once complete, you can run the front end calibration like so 

sudo front-end-cal --config_file=/path/to/my/front-end-cal.conf

Your output should look something like this
linux; GNU C++ version 4.9.1; Boost_105500; UHD_003.007.003-0-unknown
Initializing... Please wait.
Logging will be done at /tmp
Use front-end-cal --log_dir=/path/to/log to change that.
Trying to read ephemeris from SUPL server...
SUPL: Trying to read GPS ephemeris from SUPL server...
SUPL: Received Ephemeris for GPS SV 1
SUPL: Received Ephemeris for GPS SV 2
SUPL: Received Ephemeris for GPS SV 3
SUPL: Received Ephemeris for GPS SV 5
SUPL: Received Ephemeris for GPS SV 6
SUPL: Received Ephemeris for GPS SV 7
SUPL: Received Ephemeris for GPS SV 8
SUPL: Received Ephemeris for GPS SV 9
SUPL: Received Ephemeris for GPS SV 10
SUPL: Received Ephemeris for GPS SV 11
SUPL: Received Ephemeris for GPS SV 12
SUPL: Received Ephemeris for GPS SV 13
SUPL: Received Ephemeris for GPS SV 14
SUPL: Received Ephemeris for GPS SV 15
SUPL: Received Ephemeris for GPS SV 16
SUPL: Received Ephemeris for GPS SV 17
SUPL: Received Ephemeris for GPS SV 18
SUPL: Received Ephemeris for GPS SV 19
SUPL: Received Ephemeris for GPS SV 20
SUPL: Received Ephemeris for GPS SV 21
SUPL: Received Ephemeris for GPS SV 23
SUPL: Received Ephemeris for GPS SV 24
SUPL: Received Ephemeris for GPS SV 25
SUPL: Received Ephemeris for GPS SV 26
SUPL: Received Ephemeris for GPS SV 27
SUPL: Received Ephemeris for GPS SV 28
SUPL: Received Ephemeris for GPS SV 29
SUPL: Received Ephemeris for GPS SV 30
SUPL: Received Ephemeris for GPS SV 31
SUPL: Received Ephemeris for GPS SV 32
SUPL: Trying to read Acquisition assistance from SUPL server...
Actual RX Rate: 2000000.000000 [SPS]...
Actual RX Freq: 1575420000.000000 [Hz]...
PLL Frequency tune error 0.000000 [Hz]...Actual RX Gain: 40.200000 dB...
Front-end RAW samples captured
Using Volk machine: sse4_2_64_orc
Searching for GPS Satellites in L1 band...
[ . . . . 5 . 7 8 9 . . . . . . . . . 19 . . . 23 . . . 27 28 . 30 . . ]
Total signal acquisition run time 2.73478 [seconds]
Reference Time:
GPS Week: 851
GPS TOW: 276680 22134.400000
~ UTC: Tue Dec 15 20:51:21 2015
Current TOW obtained from SUPL assistance = 276680
Doppler analysis results:
SV ID Measured [Hz] Predicted [Hz]
5 3000.00 871.77
7 2875.00 524.39
8 2500.00 170.24
9 1125.00 -1220.17
19 6000.00 3734.82
23 -750.00 -3032.99
27 687.50 -1703.53
28 4375.00 2306.86
30 3750.00 1621.38
Parameters estimation for Elonics E4000 Front-End:
Sampling frequency =1999997.27 [Hz]
IF bias present in baseband=2151.87 [Hz]
Reference oscillator error =-1.37 [ppm]
Corrected Doppler vs. Predicted
SV ID Corrected [Hz] Predicted [Hz]
5 848.13 871.77
7 723.13 524.39
8 348.13 170.24
9 -1026.87 -1220.17
19 3848.13 3734.82
23 -2901.87 -3032.99
27 -1464.37 -1703.53
28 2223.13 2306.86
30 1598.13 1621.38GNSS-SDR Front-end calibration program ended.

The important outputs are highlighted above, the sampling frequency and the IF bias. The sampling frequency is nominally 2 MHz but deviation of a few Hz are normal. Baseband is defined as 0 Hz, so when the signal is shifted to baseband if the signal is not exactly centered at 0 Hz this bias is calculated as an IF bias. 

To receive GPS, then, we can copy the gnss-sdr_GPS_L1_rtlsdr_realtime.conf file (typically located in /usr/local/share/gnss-sdr/conf) to another directory and make a few edits. Handily enough there are comments in the file like this

NSS-SDR WITH RTLSDR DONGLES USER MUST SET THE CALIBRATED SAMPLE RATE HERE
; i.e. using front-end-cal as reported here:http://www.cttc.es/publication/turning-a-television-into-a-gnss-receiver/


at each place we need to make an edit. The four edits you need to make are

GNSS-SDR.internal_fs_hz=(your sampling frequency)
SignalSource.sampling_frequency=(your sampling frequency)
InputFilter.sampling_frequency=(your sampling frequency)
InputFilter.IF=(your IF bias)

Once complete, you can run the receiver 

gnss-sdr ---config_file=/path/to/your/gnss-sdr_GPS_L1_rtlsdr_realtime.conf

It will likely take a minute or two to get a fix as a certain amount of ephemeris and almanac data must be downloaded from the satellites. You also must have at least four satellites in view. Here is example output once a fix was found:


Using the KML file generated by gnss-sdr I was able to plot the locations generated in Google Earth


The red dots are individual position fixes. The blue arrow points to the skylight where my GPS antenna is mounted. The road is a two-lane road with no shoulder and the boat in the backyard is 20' long. There is a bias which may be due to the fact that the roof occludes satellites to the east (the four satellites I picked up were, at the time, overhead and eastward). I want to move the antenna up to a (plastic) roof vent in the attic to get a better view of the sky.


14 comments:

  1. I am using an RTLSDR with the 1ppm TXCO (similar to http://www.amazon.com/RTL-SDR-Blog-RTL2832U-Software-Defined/dp/B0129EBDS2/) with the bias tee mod and a generic GPS patch antenna (similar to http://www.amazon.com/HitCar-Active-Antenna-Connector-Stereos/dp/B00JE4GV8S/ ). Have you tried using gnss-sdr? the ./front-end-cal script will try to get a snapshot of the GPS constellation and will give you an idea if your configuration is working. Also try receiving terrestrial radio with a whip antenna to ensure your RTLSDR is working properly.

    ReplyDelete
  2. Fernando, did you install the Google Test framework?

    https://github.com/google/googletest

    It is one of the installation prerequsites. Maybe it installed but it is not in the include path?

    https://github.com/gnss-sdr/gnss-sdr

    Also, did you follow the 16.04 installation instructions?

    ReplyDelete
  3. Fernando, I've only ever done Ubuntu 14.04 and Kali VM. Ubuntu I had a few false starts but Kali went smoothly. good luck, -philip

    ReplyDelete
  4. When starting the config file I am getting a PLL not locked error.

    Found Rafael Micro R820T tuner
    [R82XX] PLL not locked!
    Exact sample rate is: 2000000.052982 Hz
    [R82XX] PLL not locked!

    This happens in the front end config, and the real time config. In the front end config it does seem to find some sats.

    Front-end RAW samples captured
    Searching for GPS Satellites in L1 band...
    [ 1 . . . . . . . . 10 . . . 14 . . . . . . . 22 . . . . . . . . 31 32 ]
    Total signal acquisition run time 20.9691 [seconds]


    In the real time config it never locks. The satellites seem to lock and unlock.

    Tracking start on channel 5 for satellite GPS PRN 17 (Block IIR-M)
    OOOOOOOOOOOOOOOOOOLoss of lock in channel 2!
    OOOOOOOLoss of lock in channel 7!
    OOOOOOOOOOLoss of lock in channel 1!

    Using 1PPM rtl-sdr with bias-t enabled and generic gps antenna.

    Any ideas?

    ReplyDelete
    Replies
    1. Sorry for the late reply - the OOOO's are GNU Radio indicating an overflow, that is, the dongle is producing more data than your computer can process in real time. What kind of computer are you using? Are you in a virtual machine?

      Delete
  5. Dear Philip

    when am trying to run front end calibration getting this message please help me to get out from this

    E0706 20:30:25.382395 12227 gnss_block_factory.cc:1101] SignalSource.Osmosdr_Signal_Source: Undefined implementation for block
    Segmentation fault (core dumped)

    Thanks
    Mallikarjuna G

    ReplyDelete
  6. Mallikarjuna, if Osmosdr_Signal_Source is not defined, it means you have not properly installed Osmocom. How are you installing gnss-sdr? Nowadays on Ubuntu you can get it via apt-get (quite simpler than building from scratch as I did).

    ReplyDelete
  7. Thanks for Replay Philip

    As am using Ubuntu16.04. so i installed gnss-sdr with apt-get and osmocom also reinstalled but no luck. same error

    Regards
    Mallikarjuna G

    ReplyDelete
  8. Hello,

    I am using RTL 2838U DVB-T Dongle as front end. Tallysman Low Noise Amplifier and active antenna. When i run front-end calibration file i face this error

    Sorry, no GPS satellites detected in the front-end capture, please check the antenna setup...
    GNSS-SDR Front-end calibration program ended

    I checked sourceforge mailing list the error they are mentioning is use of bias-tee or Low Noise Amplifier. But, in my case i am using LNA.

    Can, you please suggest solution to this problem.

    Regards,
    Muhammad Shujjah Yamin

    ReplyDelete
    Replies
    1. Are you providing power to the LNA? Is your antenna outside with a clear view of the sky?

      Delete
    2. Hello,

      I am using RTL 2838U DVB-T Dongle as front end. Tallysman Low Noise Amplifier and active antenna. When i run front-end calibration file i face this error

      Sorry, no GPS satellites detected in the front-end capture, please check the antenna setup...
      GNSS-SDR Front-end calibration program ended
      I m using bias tee
      can you please suggest me what to do???

      Delete
  9. Hello,

    I am using RTL 2838U DVB-T Dongle as front end. Tallysman Low Noise Amplifier and active antenna. When i run front-end calibration file i face this error

    Sorry, no GPS satellites detected in the front-end capture, please check the antenna setup...
    GNSS-SDR Front-end calibration program ended
    I m using bias tee
    can you please suggest me what to do???

    ReplyDelete
    Replies
    1. Hi I would check the amplifier with off-the-shelf receiver first to see if it works OK.

      Delete
  10. This comment has been removed by a blog administrator.

    ReplyDelete