GPS (NMEA) Decoder
For some special applications, there is a very basic 'GPS decoder' (actually
an NMEA parser) implemented in Spectrum Lab since V2.76. The main purpose
of this decoder is to store the geograpic position (latitude, longitude and
meters above sea level) along with the current GPS time in data files. This
article describes how to configure and use the decoder inside Spectrum Lab.
Contents
-
GPS Receiver Control Panel
-
The 'position' tab
-
The 'configuration' tab
-
The 'diagnostics' tab
-
Exporting GPS data
-
GPS logfile format
-
Adding other data to the GPS logfile ("Info
Strings")
To configure and test the decoder, select Options ... GPS
Receiver from SL's main menu. This opens a small control panel forthe
receiver, with at least three tabsheets:
-
Position
-
The upper line shows the current position, for example
54°11'18.0"N 007°52'18.4"E
(Latitude, Longitude, with degrees, minutes, seconds, and tenths of
a second).
Note: You can copy & paste this position into some well-known online
mapping software..
If the position is invalid (because either the GPS receiver marked it as
invalid, or no valid NMEA data have been received yet), the field will turn
red.
The second line shows the GPS date and time (~UTC) for which the displayed
position is valid.
The third line shows 'quality' information (number of satellites currently
received, HDOP = horizontal dilution of precision), height in meters above
mean sea level (" m ASL"), and the current velocity estimated by the GPS
receiver (in kilometers/hour; no stoneage imperial units).
-
Configuration
-
On this tabsheet, select the COM port to which the receiver is
connected, and the serial port speed (bits per second, 'Baudrate').
Usual values are 4800 or 9600 bit/sec, but some receivers (especially those
which emit 4 or even 10 positions per second) use larger serial baudrates
(*). The serial data format for the GPS data
(NMEA-0183) is 4800 Baud, 8 data bits, no parity bit, one or more stop
bits, and no handshake. Except COM port number and baudrate, the parameters
are hard-coded in the program, there's no need to adjust them.
For some very special applications, it may be possible to connect the GPS
receiver via the soundcard. Set the 'COM port' to
'Soundcard' (!). This is only possible if the soundcard runs in
'stereo', and the card has a true 'line-in' (not just a microphone input).
Add a 100 : 1 resistive voltage divider, and a 100 nF coupling
capacitor between the receiver's serial output and the soundcard's line
input, to reduce the peak-to-peak voltage to a few hundred mV. The advantage
of feeding the NMEA signal through the soundcard is the better timing accuracy,
because the NMEA signal (and, possibly, a superimposed 1-pps-signal) travels
through the same 'signal path' inside the PC, and the software, like the
analysed signal.
Click 'Apply' when finished to make changes to the serial port
settings effective (this closes the serial port, an re-opens it with
the new settings).
The settings below will be 'applied' immediately, without clicking the
'Apply'-button, and thus without stopping and re-starting the acquisition.
'DispFrm': Position Display Format. At the moment, only a few formats
like dd°mm'ss.s" (degrees, minutes, seconds) are supported.
'emit pos every NN seconds' : This is the interval at which the
GPS position (including altitude, date, and time) is emitted into the audio
logfile, or audio stream. Note that this is only possible with certain file-
or data stream times. Even if the GPS receiver sends an updated position
via NMEA (say once every second), you may only want to emit a new data block
every 10 seconds - depending on the vehicle's maximum speed, and the required
position accuracy.
'show pos in spectrogram'
: When checked, the GPS position is shown in the main spectrogram, along
with the time-'ticks'. The GPS position, using the format specified above,
will be appended to the time marker format specified under 'Display Settings'
/ 'Waterfall Time Grid'.
'use GPS time, not local' : If this option is selected, most places
where otherwise the PC's local time aka 'PC clock' is used, the
program will use the last (valid) GPS time instead. If the NMEA stream stops,
the time value will continue to increase in a more or less 'free running'
mode (less accurate than the GPS time).
-
Diagnostics
-
Shows the most recent received NMEA sentences with types ($GP-)RMC, GGA,
and GLL. Your GPS receiver should be able to send at least one of these (it
may send all of them). Any 'unknown' sequence -at least from SL's NMEA parser's
point of view- is dumped to the line labelled 'unknown', along with the counter
of such messages.
For example, when tested with one of the common cheap 'GPS mice' (u-blox),
this field occasionally showed
$GPTXT,01,01,02,ANTSTATUS=SHORT*6D
when the receiver's antenna didn't have sufficient sky view.
-
Notes:
-
GPS receivers with bitrates above 9600 bit/sec
can only be connected to a 'real' serial port. Connecting such receivers
through the soundcard is impossible, especially when the soundcard's sampling
rate is limited to 48 kHz or even less. On the author's notebook (Z61m) with
only a 'mic' input for the onboard audio device, not even 9600 bit/second
seemed to work with the soundcard. Use a real serial interface, or a
USB-to-serial converter if the soundcard method doesn't work.
-
The GPS control panel doesn't need to be open to receive and log position
data. It's just an auxiliary window to check the proper operation of the
receiver, and an aid to configure it.
-
Even though there is a demodulator / decoder for DGPS
beacons built inside SL, it cannot be used to improve the accuracy GPS
decoder's position. For that purpose, the DGPS data stream would need to
be fed into the GPS receiver chip, using an extra serial interface.
back to contents
GPS data can be saved to a disk file, usually along with the 'raw data' (which
are usually saved in wave audio files). To avoid breaking the WAVE file structure
(by splitting up the 'data' chunks), the GPS data are written into a separate
file, using the same path and filename, but a different file extension. This
simplifies post-processing, and makes it easy to extract the GPS data for
a 'mapping application'. Future audio files may allow embedding the GPS data
directly in the audio file, but the principle explained below will remain
the same.
GPS positions are traditionally logged in 'GPS Track File', but unfortunately
there is no simple and space-efficient standard file format for this (GPX
is widespread now, but due to its XML-based nature, it wastes a lot of disk
space if you need to save throusands of track points). So the file format
to log GPS data within Spectrum Lab now uses its own, simple structure, which
allows an EASY link between any audio sample position (in the wave file)
and the geographic position (in the GPS logfile). If necessary, SL's own
GPS logfile format can easily be converted into GPX (or, maybe, KML), but
not vice versa because GPX doesn't store the 'audio sample index into the
wave file'.
The logfile is a simple ASCII text file, one line per GPS position, no structure,
no XML, no whistles and bells. Data columns are separated by spaces. The
data columns are:
-
Audio sample index in the audio logfile (with the same name of the logfile,
but different extension).
This value starts counting at zero(!) for the first sample in the audio
file.
-
GPS timestamp in UNIX format (number of seconds elapsed since January 1st,
1970).
It marks the time for which the GPS position (below) is valid. For most GPS
receivers, the timestamp will only step by one (second), but there are receivers
which send four or even ten position reports per second, thus the two fractional
digits.
-
GPS latitude in degrees (positive = north, negative = south, - 90 ..
+ 90 °, 0 ° = Equator) .
If the GPS position is not value, this value will be -99.99999 (degrees).
-
GPS longitude in degrees (positive = east, negative = west, - 180 ..
+ 180 °, 0 ° = Greenwich meridian).
If the GPS position is not value, this value will be -999.99999 (degrees).
-
GPS altitude in meters above mean sea level, as returned by the GPS
receiver.
If the GPS position is not value, this value will be -9999.9 (meters).
-
GPS velocity in km/h ( kilometers per hour, not knots ! ).
If the GPS position is not value, or the GPS receiver doesn't provide it,
this value will be -999.9 (km/hour).
-
'Info String' from the user application. Can be set anytime with the
'wave.wr_info' pseudo variable (see next
chapter).
Spectrum Lab makes no assumption about the contents of this string.
Only at the begin of the file, there may be a few comment lines, beginning
with a semicolon. The second comment line describes the file structure. Comments
in between to 'data lines' are not allowed. Below is a sample of such a GPS
logfile, with some user-defined contents set through
wave.wr_info (explained in the next chapter)
:
; Spectrum Lab GPS- and info logfile for "gps_log_test.wav"
;sample_nr unix_date_sec latitude_d longitude_d h_m_asl sp_kmh ...
0000000000 1278604831.00 +52.130111 +008.440111 +0098.4 +000.0 pk37=-94.8
0000004096 1278604832.00 +52.130222 +008.440222 +0098.5 +000.1 pk37=-87.5
0000014336 1278604833.00 +52.130333 +008.440333 +0098.6 +000.1
pk37=-94.7
Along with the GPS data as specified in the previous chapter, other data
can be added into the logfile (audio log, or GPS log with the same name as
the audio log but different extension).
To write such 'extra data' to the recorded file(s), put those data
into the pseudo-variable wave.wr_info, for example in the
periodic events or conditional events:
wave.wr_info="pk37="+str("##0.0",peak_a(36000,38000))
: REM update write-info with the peak amplitude between 36 and 38 kHz
Note: wave.wr_info can only be set to a string value ! Numeric values must
be formatted into a string as in the example above. There is no way to tell
exactly (in advance) when the string will be flushed / merged into the output
stream. It also depends on the GPS receiver's output interval, which is typically
once per second.
To retrieve these info strings during audio file analysis (or 'playback'),
use the function wave.rd_info . This function works like a string
variable, it contains the most recent info string read from the file
during file analysis.
Details about other interpreter commands to control 'wave' file in- and output
are here .
back to contents
See also: Spectrum Lab's main index