I would like to present you a really simple application written in C/C++ that is able to compute the C/A code for GPS Satellites. To be exact,you can specify which PRN (1-37) you want to calculate. But now how the C/A code generator works. It is also very simple. There are two 10-bit shifting registers called G1 and G2, each with its own feedback function. The fumction consists of a simple XOR segment (+) which is fed by some fragments of the register (In case of G1 its  fragment 3 and 10). For those, who are not familiar with XOR: [1+1 = 0| 0+1 = 1 | 1+0=1| 0+0 = 0]. In general, we sum all the input (eg 1+1+1+1 …) and then make modulo 2 which results in either 0 or 1. This result is fed to the first fragment of the corresponding register while all the other fragments move its information to the next fragment of the generator. This results in the release of the infromation hold in the last fragment (10). 

PRN (2)


The G2 generator is doing almost the same,althought it has a different fixed feedback function (2+3+6+8+9). The only difference is that the final result from this register is not taken from the last register, but rather taken from a different XOR segment. Now this is interesting as the inputs to the XOR in case of G2 are dependent on the PRN we want to calculate. The above schema calculates the PRN 13 code (taps 6 and 7). Each PRN has different taps according to this table: 

As you may have noticed the XOR function defines 0+0 = 0 …. Therefore in order for each generator to works, we have to fill the whole register with ones at the beginning. The implementation is straightforward and I will not pass the code here, but its of course available for download (as a Visual Studio 2012 project). Please note that both files contains .exe file and some browsers may warn you not to download those files, however you can trust me as I do not know how to write any virusses :D … yet  ;)


You can use MATLAB to load the stored PRN sequence: load(‘PRN13.txt’);

Edit 27.12.2016: Changed Sequences from [0,1] to [-1,1].


GPS L2 CM and CL Codes

These codes were introducted later in a GPS III modernization block. The CM stands for “civil – moderate” length and the CL stands for “civil-long” length, although both codes are much longer than the standard GPS L1 C/A code. The reason is that a longer LSFR ( Linear Shift Register ) was used,containing a total of 27 registers. Thus the Maximum length sequence is roughly 227-1. Both codes are multiplexed before broadcasting and in fact only a limited amount of samples from these registers is taken. For the CM,10230 samples are taken and for CL, 767250 samples are taken. Then the registers are reseted. Each satellite has a unique initial state of these registers. The image below represents a shorthand notation of the LSFR register where each number represents amount of registers between the taps.


The initial and the end register states in the octal base (Each number represents 3 digits in binary) for all the 37 SVs can be found here in the list:

EDIT : 2017.08.11 yyyy/mm/dd

For those interested deeply in the subject,I recommend reading additional topic from sources below. The Codes were tested and should be working. The generation Script is included at the bottom. Please note that Matlab is required to run the script. Octave fans are free to try it and leave comments whether it works or not. I have tweaked the code during data saving and added some parallelism so its should run a little bit faster :)

Please email me or post comment if you find any additional bugs. Thank you :)