Main Content

nmeaParser

Parse data from standard NMEA sentences sent from GNSS receivers

Description

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:

  1. Create the nmeaParser object and set its properties.

  2. 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.

Creation

Description

pnmea = nmeaParser returns a nmeaParser 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.

example

pnmea = nmeaParser('MessageIDs', msgID) returns a 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"].

Properties

expand all

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.

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

Usage

Description

example

[rmcData,ggaData,gsaData,vtgData,gllData,gstData,zdaData,hdtData] = pnmea(rawData) 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 nmeaParser System object.

Input Arguments

expand all

NMEA data, which is compliant with NMEA 0183 Standard, as obtained from a GNSS receiver.

Data Types: string | char

Output Arguments

expand all

Data 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.

Data 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.

Data 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.

Data 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.

Data 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.

Data 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.

Data 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.

Data 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.

Object Functions

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)

Examples

collapse all

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

More About

expand all

Introduced in R2020b