# GPS CA/L2-CM Code Generator

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 + X**^{3}+ X^{10} - G2:
**Y = 1 + X**^{2}+ X^{3}+ X^{6}+ X^{8}+ X^{9}+ X^{10}

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 + X ^{3} + X^{4} + X^{5} + X^{6} + X^{9} + X^{11} + X^{13} + X^{16} + X^{19} + X^{21} + X^{24} + X^{27}** 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.