GPS CA/L2-CM Code Generator

by | Apr 16, 2014 | QUICK

GPS’s CA (Coarse-Acquisition) code – also known generally as “Gold Codes” is a pseudorandom sequence used for the GPS system, which uses CDMA technology to distinguish between different satellites. There are 37 unique sequences. Each sequence has 1023 bits – sometimes denoted as “chips”.  The entire sequence is repeated each 1 ms – leading to a total chip rate of 1.023Mbit/s. As in case of most PRN sequences, they are implemnted via LSFRs (Linear Shift Feedback Register). Specifically via 2 combined shift registers G1 & G2 as shown below.


  • G1: Y = 1 + X3 + X10
  • G2: Y = 1 + X2 + X3 + X6 + X8 + X9 + X10

Operation “+” stands for XOR or accumulator with a modulo-2. The polynom used to describe G1 is constant for all PRNs. The Sequence however differ in feedbacks from G2. As shown above, PRN13 uses for example feedbacks 6 & 7. The Phase masks are easily readable within the sourcecode HERE. Note that the initialization of the LSRs is required for correct operation (Initialize to ones) – And also that implemnting LSFR in C/C++ is not the way of how that is actually done in real hardware.

All PRN Sequences are available HERE ☄️ for dowload. Later in GPS III modernization block, another set of codes was introduced: L2-CL and L2-CM. They are all generated also via LSFR, but this time with a length of 27 registers and formula of: Y = 1 + X3 + X4 + X5 + X6 + X9 + X11 + X13 + X16 + X19 + X21 + X24 + X27 Each satellite uses different initialization of those registers however – and thus each of them uses only part of the entire sequence. More information about GPS specification can be found on the official pages HERE. The LSFR is shown below,numbers do present amount of registers in between the stages.

An Example along with more information on generation and verification of the L2CM code is available in Matlab HERE.