Parse data from standard NMEA sentences sent from GNSS receivers
The nmeaParser
System object™ parses data from some of the standard NMEA (National Marine Electronics
Association) sentences, which are sent from a GNSS (Global Navigation Satellite System)
receiver. The NMEA sentences that need parsing must be compliant with the NMEA
0183® Standard, Version 4.1.
To parse data from NMEA sentences:
Create the nmeaParser
object and set its properties.
Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects?.
The nmeaParser
System object outputs an array of structures corresponding to the values extracted from the
specified NMEA sentences.
returns a
pnmea
= nmeaParsernmeaParser
System object, pnmea
, with default properties, that extracts data
from these NMEA messages: RMC, GGA, and GSA. The order of structure arrays in the
extracted output data is also: RMC, GGA, and GSA.
returns a pnmea
= nmeaParser('MessageIDs', msgID)nmeaParser
System object, pnmea
, that extracts data from the NMEA messages
specified using the Message IDs. Specify msgID
as
'RMC'
, 'GGA'
, 'GSA'
,
'VTG'
, 'GLL'
, 'GST'
,
'ZDA'
, and 'HDT'
, or a combination of these IDs
(for example: ['VTG','GLL','HDT']
). The order in which you specify the
Message IDs determines the order of the structure arrays in the extracted output data. The
default value is ["RMC","GGA","GSA"]
.
Unless otherwise indicated, properties are nontunable, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
release
function unlocks them.
If a property is tunable, you can change its value at any time.
For more information on changing property values, see System Design in MATLAB Using System Objects.
MessageIDs
— Message IDs of NMEA sentences to extract data["RMC","GGA","GSA"]
(default) | RMC
| GGA
| GSA
| VTG
| GLL
| GST
| ZDA
| HDT
Message IDs of NMEA sentences, which are compliant with the NMEA 0183® Standard, from which you want to extract data. You can specify multiple message IDs as an array of strings to extract data from NMEA sentences.
Data Types: char
| string
[
parses data and returns an array of structures, where each structure corresponds to a
single Message ID. The sequence that you specify for the output arguments must be the same
sequence that you specified for the Message IDs when creating the
rmcData
,ggaData
,gsaData
,vtgData
,gllData
,gstData
,zdaData
,hdtData
] = pnmea(rawData
)nmeaParser
System object.
rawData
— NMEA data as obtained from a GNSS receiverNMEA data, which is compliant with NMEA 0183 Standard, as obtained from a GNSS receiver.
Data Types: string
| char
rmcData
— Data extracted from RMC sentenceData extracted from an RMC sentence. The output structure contains the information parsed from an RMC sentence along with the parsing status. If multiple RMC sentences are found in the input data, then an array of structures is returned. For more details, see RMC Sentences.
ggaData
— Data extracted from GGA sentenceData extracted from a GGA sentence. The output structure contains the information parsed from a GGA sentence along with the parsing status. If multiple GGA sentences are found in the input data, then an array of structures is returned. For more details, see GGA Sentences.
gsaData
— Data extracted from GSA sentenceData extracted from a GSA sentence. The output structure contains the information parsed from a GSA sentence along with the parsing status. If multiple GSA sentences are found in the input data, then an array of structures is returned. For more details, see GSA Sentences.
vtgData
— Data extracted from VTG sentenceData extracted from a VTG sentence. The output structure contains the information parsed from a VTG sentence along with the parsing status. If multiple VTG sentences are found in the input data, then an array of structures is returned. For more details, see VTG Sentences.
gllData
— Data extracted from GLL sentenceData extracted from a GLL sentence. The output structure contains the information parsed from a GLL sentence along with the parsing status. If multiple GLL sentences are found in the input data, then an array of structures is returned. For more details, see GLL Sentences.
gstData
— Data extracted from GST sentenceData extracted from a GST sentence. The output structure contains the information parsed from a GST sentence along with the parsing status. If multiple GST sentences are found in the input data, then an array of structures is returned. For more details, see GST Sentences.
zdaData
— Data extracted from ZDA sentenceData extracted from a ZDA sentence. The output structure contains the information parsed from a ZDA sentence along with the parsing status. If multiple ZDA sentences are found in the input data, then an array of structures is returned. For more details, see ZDA Sentences.
hdtData
— Data extracted from HDT sentenceData extracted from an HDT sentence. The output structure contains the information parsed from an HDT sentence along with the parsing status. If multiple HDT sentences are found in the input data, then an array of structures is returned. For more details, see HDT Sentences.
To use an object function, specify the
System object as the first input argument. For
example, to release system resources of a System object named obj
, use
this syntax:
release(obj)
Extract data from NMEA sentences that are obtained from a GNSS receiver.
Extract Data from RMC Sentence
Create an nmeaParser System Object by specifying the Message ID as "RMC".
pnmea = nmeaParser("MessageID","RMC");
Provide the RMC sentence obtained from the GNSS receiver as the input and extract data.
unparsedRMCLine='$GNRMC,143909.00,A,5107.0020216,N,11402.3294835,W,0.036,348.3,210307,0.0,E,A*31';
rmcData = pnmea(unparsedRMCLine)
rmcData = struct with fields:
TalkerID: "GN"
MessageID: "RMC"
FixStatus: 'A'
Latitude: 51.1167
Longitude: -114.0388
GroundSpeed: 0.0185
TrueCourseAngle: 348.3000
UTCDateTime: 21-Mar-2007 14:39:09
MagneticVariation: 0
ModeIndicator: 'A'
NavigationStatus: "NA"
Status: 0
Extract Data from Multiple Sentences
Provide GGA, GSA, and RMC sentences as the input.
unparsedGGALine = ['$GPGGA,111357.771,5231.364,N,01324.240,E,1,12,1.0,0.0,M,0.0,M,,*69']; unparsedGSALine = ['$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30']; unparsedRMCLine = ['$GPRMC,111357.771,A,5231.364,N,01324.240,E,10903,221.5,020620,000.0,W*44'];
Create a string array to include the three sentences
rawNMEAData = [unparsedGGALine ,newline, unparsedGSALine ,newline, unparsedRMCLine]
rawNMEAData = '$GPGGA,111357.771,5231.364,N,01324.240,E,1,12,1.0,0.0,M,0.0,M,,*69 $GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30 $GPRMC,111357.771,A,5231.364,N,01324.240,E,10903,221.5,020620,000.0,W*44'
However, consider that you need to extract data only from GGA and GSA sentences. So create the nmeaParser System Object 'pnmea', and specify the 'GGA' and 'GSA' Message IDs as a string array.
pnmea=nmeaParser("MessageIDs",["GGA","GSA"]);
Specify the output arguments for all the three sentences to extract the data as structures.
[ggaData,gsaData] = pnmea(rawNMEAData)
ggaData = struct with fields:
TalkerID: "GP"
MessageID: "GGA"
UTCTime: 11:13:57.771
Latitude: 52.5227
Longitude: 13.4040
QualityIndicator: 1
NumSatellitesInUse: 12
HDOP: 1
Altitude: 0
GeoidSeparation: 0
AgeOfDifferentialData: NaN
DifferentialReferenceStationID: NaN
Status: 0
gsaData = struct with fields:
TalkerID: "GP"
MessageID: "GSA"
Mode: "A"
FixType: 3
SatellitesIDNumber: [1 2 3 4 5 6 7 8 9 10 11 12]
PDOP: 1
VDOP: 1
HDOP: 1
SystemID: NaN
Status: 0
The above output shows that only GGA and GSA sentences are extracted based on the Message IDs specified as input.
Provide another GGA sentence as an additional input, and extract data. In this case, you need not modify the System object as the Message ID has not changed.
unparsedGGALine1='$GNGGA,001043.00,4404.14036,N,12118.85961,W,1,12,0.98,1113.0,M,-21.3,M,,*47'
unparsedGGALine1 = '$GNGGA,001043.00,4404.14036,N,12118.85961,W,1,12,0.98,1113.0,M,-21.3,M,,*47'
rawNMEAData = [unparsedGGALine ,newline, unparsedGSALine ,newline, unparsedGGALine1]
rawNMEAData = '$GPGGA,111357.771,5231.364,N,01324.240,E,1,12,1.0,0.0,M,0.0,M,,*69 $GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30 $GNGGA,001043.00,4404.14036,N,12118.85961,W,1,12,0.98,1113.0,M,-21.3,M,,*47'
[ggaData,gsaData] = pnmea(rawNMEAData)
ggaData=1×2 struct array with fields:
TalkerID
MessageID
UTCTime
Latitude
Longitude
QualityIndicator
NumSatellitesInUse
HDOP
Altitude
GeoidSeparation
AgeOfDifferentialData
DifferentialReferenceStationID
Status
gsaData = struct with fields:
TalkerID: "GP"
MessageID: "GSA"
Mode: "A"
FixType: 3
SatellitesIDNumber: [1 2 3 4 5 6 7 8 9 10 11 12]
PDOP: 1
VDOP: 1
HDOP: 1
SystemID: NaN
Status: 0
A status of 0 indicates that the data was parsed successfully.
Read Data from NMEA Log
Read data from a sample NMEA log, so that the data can be parsed using the nmeaParser System Object.
The sample log file is nmeaLog.nmea
, which is included in this example.
f = fopen('nmeaLog.nmea'); unParsedNMEAdata = fread(f); pnmea = nmeaParser("MessageIDs",["RMC","GGA"]); [rmcStruct, ggaStruct] = pnmea(unParsedNMEAdata)
rmcStruct=1×9 struct array with fields:
TalkerID
MessageID
FixStatus
Latitude
Longitude
GroundSpeed
TrueCourseAngle
UTCDateTime
MagneticVariation
ModeIndicator
NavigationStatus
Status
ggaStruct=1×9 struct array with fields:
TalkerID
MessageID
UTCTime
Latitude
Longitude
QualityIndicator
NumSatellitesInUse
HDOP
Altitude
GeoidSeparation
AgeOfDifferentialData
DifferentialReferenceStationID
Status
The status flag displayed along with the extracted values in each output structure can be used to determine the parsing status:
Status: 0
— Sentence is valid (checksum validation is
successful and the extracted data is as per the requested Message ID)
Status: 1
— Checksum of the sentence to be parsed is
invalid
Status: 2
— The requested sentence is not found in the input
data
Note
If a value is not available in the input sentence, the corresponding output value is displayed as “NA” for string values and "NaN" for numeric values.
Name of field displayed in the output structure after parsing is complete | Description |
---|---|
TalkerID | Identify the type of device that transmits data. For example, for a GPS
receiver, the TalkerID is Data type:
|
MessageID | Type of NMEA message – Data type:
|
FixStatus | Possible values:
Data type:
|
Latitude | Latitude in degrees. North is considered positive. Data
type: |
Longitude | Longitude in degrees. East is considered positive. Data
type: |
GroundSpeed | Speed over ground in meters per second (m/s) Data type:
|
TrueCourseAngle | Course over ground in degrees. Data type:
|
UTCDateTime | UTC date and time Data type:
|
MagneticVariation | Magnetic variation value. Direction W is considered as negative Data type: |
ModeIndicator | Possible values:
Data type:
|
NavigationStatus | Possible values:
Data type:
|
Name of field displayed in the output structure after parsing is complete | Description |
---|---|
TalkerID | Identify the type of device that transmits data. For example, for a GPS
receiver, the TalkerID is Data type:
|
MessageID | Type of NMEA message – Data type:
|
UTCTime | UTC Time ( Data type:
|
Latitude | Latitude in degrees. North is considered positive. Data
type: |
Longitude | Longitude in degrees. East is considered positive. Data
type: |
QualityIndicator | Possible values:
Data type: |
NumSatellitesInUse | Number of satellites used. This could be different from number of satellites in view. Data type:
|
HDOP | Horizontal dilution of precision Data type:
|
Altitude | Altitude above mean sea level in meters Data type:
|
GeoidSeparation | Difference between ellipsoid and mean sea level in meters Data type: |
AgeOfDifferentialData | Age of differential corrections Data type:
|
DifferentialReferenceStationID | ID of station providing differential corrections Data type:
|
Name of field displayed in the output structure after parsing is complete | Description |
---|---|
TalkerID | Identify the type of device that transmits data. For example, for a GPS
receiver, the TalkerID is Data type:
|
MessageID | Type of NMEA message – Data type:
|
Mode | Possible values:
Data type:
|
FixType | Possible values:
Data type: |
SatellitesIDNumber | Satellite numbers (array of 12 bytes). Empty fields will be displayed
as Data type:
|
PDOP | Position dilution of precision Data type:
|
VDOP | Vertical dilution of precision Data type:
|
HDOP | Horizontal Dilution of Precision Data type:
|
SystemID | NMEA defined GNSS System ID Data type:
|
Name of field displayed in the output structure after parsing is complete | Description |
---|---|
TalkerID | Identify the type of device that transmits data. For example, for a GPS
receiver, the TalkerID is Data type:
|
MessageID | Type of NMEA message – Data type:
|
UTCTime | UTC Time Data type:
|
UTCDay | UTC Day Data type:
|
UTCMonth | UTC Month Data type:
|
UTCYear | UTC Year Data type:
|
LocalZoneHours | Local zone hours ranging from Data type:
|
LocalZoneMinutes | Local zone minutes ranging from Data type:
|
Name of field displayed in the output structure after parsing is complete | Description |
---|---|
TalkerID | Identify the type of device that transmits data. For example, for a GPS
receiver, the TalkerID is Data type:
|
MessageID | Type of NMEA message – Data type:
|
Latitude | Latitude in degrees. North is considered positive. Data
type: |
Longitude | Longitude in degrees. East is considered positive. Data
type: |
UTCTime | UTC Time Data type:
|
DataValidity | Data validity status:
Data type:
|
PositioningMode | Possible values:
Data type:
|
Name of field displayed in the output structure after parsing is complete | Description |
---|---|
TalkerID | Identify the type of device that transmits data. For example, for a GPS
receiver, the TalkerID is Data type:
|
MessageID | Type of NMEA message – Data type:
|
TrueCourseAngle | Course over ground (true) in degrees Data type:
|
MagneticCourseAngle | Course over ground (magnetic) in degrees Data type:
|
GroundSpeed | Speed over ground in meters per second (m/s) Data type:
|
ModeIndicator | Possible values:
Data type:
|
Name of field displayed in the output structure after parsing is complete | Description |
---|---|
TalkerID | Identify the type of device that transmits data. For example, for a GPS
receiver, the TalkerID is Data type:
|
MessageID | Type of NMEA message – Data type:
|
UTCTime | UTC Time Data type:
|
RMSStdDeviationOfRanges | RMS value of the standard deviation of the ranges in meters. Data type: |
StdDeviationSemiMajorAxis | Standard deviation of semi-major axis in meters Data type:
|
StdDeviationSemiMinorAxis | Standard deviation of semi-minor axis in meters Data type:
|
OrientationSemiMajorAxis | Orientation of semi-major axis, in degrees Data type:
|
StdDeviationLatitudeError | Standard deviation of latitude error, in meters Data type:
|
StdDeviationLongitudeError | Standard deviation of longitude error in meters Data type:
|
StdDeviationAltitudeError | Standard deviation of altitude error in meters Data type:
|
Name of field displayed in the output structure after parsing is complete | Description |
---|---|
TalkerID | Identify the type of device that transmits data. For example, for a GPS
receiver, the TalkerID is Data type:
|
MessageID | Type of NMEA message – Data type:
|
TrueHeadingAngle | Heading in degrees with respect to true north Data type:
|
You have a modified version of this example. Do you want to open this example with your edits?