Main Content

gpsPCode

Generate P-code for GPS satellites

Since R2021b

Description

The gpsPCode System object™ generates a precision code (P-code) for a Global Positioning System (GPS) satellite, as defined in IS-GPS-200L Section 3.3.2.2 [1].

To generate a P-code for a GPS satellite:

  1. Create the gpsPCode 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?

Creation

Description

example

pgenerator = gpsPCode creates a default P-code generator System object.

example

pgenerator = gpsPCode(Name,Value) sets Properties using one or more name-value pairs. For example, 'PRNID',10 specifies a pseudo-random noise (PRN) ID of 10.

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.

GPS satellite PRN index, specified as one of these options.

  • Integer in the range [1, 210] — Use this option to input a PRN index for a single satellite.

  • Vector of integer elements in the range [1, 210] — Use this option to input PRN indices for multiple satellites.

For details on PRN ID values, see IS-GPS-200L Tables 3-Ia, 3-Ib, and 6-I [1].

Data Types: double | uint8

Output code length, specified as a positive integer. This length specifies the number of rows in the output P-code.

The default value of 10230 corresponds to 1 millisecond of P-code, as the P-code chips are at 10.23 MHz.

Tunable: Yes

Data Types: double | uint64

Format of the initial state, specified as "seconds", "datetime", or "chips".

Data Types: char | string

Initial time within one week, specified as one of these options.

  • Integer in the range [0, 604,800] — Use this option when you set the InitialStateFormat property to "seconds". In this case, initial time specifies the seconds that have elapsed from the beginning of the week.

  • datetime object — Use this option when you set the InitialStateFormat property to "datetime". In this case, initial time specifies the time elapsed from the beginning of the week to the time specified by datetime object.

Note

The P-code is one week long.

The default value of 0 assumes that you set the InitialStateFormat property to "seconds".

Dependencies

To enable this property, set the InitialStateFormat property to "seconds" or "datetime".

Data Types: double

Initial number of elapsed P-code chips, from the beginning of the week, specified as an integer in the range [0, 604,800x10.23e6].

The maximum input value, 604,800x10.23e6, is the total number of chips elapsed in one week (7×24×60×60×10.23e6).

Note

10.23e6 is the number of chips elapsed in one second.

Dependencies

To enable this property, set the InitialStateFormat property to "chips".

Data Types: double | uint64

Usage

Description

code = pgenerator()

Output Arguments

expand all

Generated binary-valued P-code, specified as one of these options.

  • Vector — The System object returns this option when you specify the PRNID property as a scalar.

  • Matrix — The System object returns this option when you specify the PRNID property as a vector. Each column of this matrix represents the generated P-code corresponding to the element in the PRNID vector.

The number of rows is equal to the value of the OutputCodeLength property. The number of columns is equal to the length of the PRNID property. Each element of the vector or matrix is of data type int8.

Data Types: int8

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)

expand all

infoCharacteristic information about object
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
cloneCreate duplicate System object
isLockedDetermine if System object is in use
resetReset internal states of System object

Examples

collapse all

Create a precision code generator (P-code) System object™, and then set its properties.

pgen = gpsPCode;
pgen.PRNID = [10 50];         % 2 satellites
pgen.OutputCodeLength = 1024;
pgen.InitialTime = 1800;      % Seconds (default)
disp(pgen)
  gpsPCode with properties:

                 PRNID: [10 50]
      OutputCodeLength: 1024
    InitialStateFormat: "seconds"
           InitialTime: 1800

Generate the P-code.

code = pgen();

Create the P-code System object™ and set its properties.

pgen = gpsPCode;
pgen.PRNID = 45;
pgen.OutputCodeLength = 102400;

Set the initial state format as chips. Generate the P-code for the last 5,000 chips in one week.

pgen.InitialStateFormat = "chips";
% 604,800 is the total seconds in one week
% 10.23e6 is the number of P-code chips that elapsed in one second
pgen.InitialNumChipsElapsed = 604800*10.23e6 - 5000;
code = pgen();

Create a P-code System object™ and specify the PRN index and the output code length.

Set the format of the initial state as a datetime object. Generate the P-code for the current time.

pgen = gpsPCode;
pgen.PRNID = 25;
pgen.OutputCodeLength = 20460;
pgen.InitialStateFormat = "datetime";
pgen.InitialTime = datetime("now");
code = pgen();

Display the properties of the P-code generator.

disp(pgen)
  gpsPCode with properties:

                 PRNID: 25
      OutputCodeLength: 20460
    InitialStateFormat: "datetime"
           InitialTime: 13-Feb-2024 02:05:00

Get information from a gpsPCode System object™ by using the info object function. Observe how the precision of initial time impacts the generation of the P-code.

Create a P-code generator System object™, and then specify its properties.

format long
pgen = gpsPCode
pgen = 
  gpsPCode with properties:

                 PRNID: 1
      OutputCodeLength: 10230
    InitialStateFormat: "seconds"
           InitialTime: 0

pgen.InitialStateFormat = "chips";
pgen.InitialNumChipsElapsed = 8388600;

Get the characteristic information about the P-code generator.

pgen.info
ans = struct with fields:
    TotalNumChipsElapsed: 8388600
     TotalSecondsElapsed: 0.820000000000000

Advance the time by a quarter of a P-code chip time (that is, 0.25/10.23e6).

pgen1 = gpsPCode;
pgen1.InitialTime = pgen.info.TotalSecondsElapsed + 0.25/10.23e6
pgen1 = 
  gpsPCode with properties:

                 PRNID: 1
      OutputCodeLength: 10230
    InitialStateFormat: "seconds"
           InitialTime: 0.820000024437928

pgen1.info
ans = struct with fields:
    TotalNumChipsElapsed: 8388600
     TotalSecondsElapsed: 0.820000000000000

The info function output shows no increment in the TotalNumChipsElapsed in this case, because TotalNumChipsElapsed is calculated internally using the function round.

Advance the time by half of a P-code chip time now (that is, 0.5/10.23e6).

pgen2 = gpsPCode;
pgen2.InitialTime = pgen.info.TotalSecondsElapsed + 0.5/10.23e6
pgen2 = 
  gpsPCode with properties:

                 PRNID: 1
      OutputCodeLength: 10230
    InitialStateFormat: "seconds"
           InitialTime: 0.820000048875855

pgen2.info
ans = struct with fields:
    TotalNumChipsElapsed: 8388601
     TotalSecondsElapsed: 0.820000097751711

The info function output now shows the TotalNumChipsElapsed is incremented by one, due to the internal usage of round() function.

Compare the output of each System object call.

code = pgen();
code1 = pgen1();
code2 = pgen2();
isequal(code, code1) % code and code1 are equal
ans = logical
   1

isequal(code1,code2) % code1 and code2 are unequal
ans = logical
   0

References

[1] IS-GPS-200L. "NAVSTAR GPS Space Segment/Navigation User Segment Interfaces." GPS Enterprise Space & Missile Systems Center (SMC) - LAAFB, May 14, 2020.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2021b