-
Notifications
You must be signed in to change notification settings - Fork 2
/
CA_Code.m
96 lines (83 loc) · 2.17 KB
/
CA_Code.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function [ ca_code_binary, ca_code_math, G2, G1 ] = CA_Code( PRN )
% Navigation Exercise 2 University of Stuttgart
%Worked By Karam MAWAS MTN(2946939)
% This function generates the G1 & G2 of the Satellites from 1-37 the PRN
% should be integer number.
% The G1 polynomyal:1+x^3+x^10
% The G2 polynomyal:G2= 1+x^2+x^3+x^6+x^8+x^9+x^10
% To generate a C/A code for Satellite number 17 just type CA_Code(17)
array_G1 = -ones(10,1);
array_new_G1 = array_G1;
G1=-ones(1023,1);
% Generating the code G1
% G1 = 1+x^3+x^10
for i=1:1022
t = array_G1(3,1)*array_G1(10,1);
array_new_G1(2:10,1)=array_G1(1:9,1);
array_new_G1(1,1)=t;
array_G1 = array_new_G1;
G1(i+1)=array_G1(10,1);
end
% Generating the code G2
% G2= 1+x^2+x^3+x^6+x^8+x^9+x^10
% the sequence code of the satellites in the same order of the satellite'S
% num.
G2_sequence=[2 6;
3 7;
4 8;
5 9;
1 9;
2 10;
1 8;
2 9;
3 10;
2 3;
3 4;
5 6;
6 7;
7 8;
8 9;
9 10;
1 4;
2 5;
3 6
4 7;
5 8;
6 9;
1 3;
4 6;
5 7;
6 8;
7 9;
8 10;
1 6;
2 7;
3 8;
4 9;
5 10;
4 10;
1 7;
2 8;
4 10];
P = G2_sequence(PRN,:);
array_G2 = -ones(10,1);
array_new_G2 = array_G1;
G2=-ones(1023,1);
for i=1:1022
u = array_G2(2,1)*array_G2(3,1)*array_G2(6,1)*array_G2(8,1)*array_G2(9,1)*array_G2(10,1);
array_new_G2(2:10,1)=array_G2(1:9,1);
array_new_G2(1,1)=u;
array_G2 = array_new_G2;
G2(i+1)=array_G2(P(1,1),1)*array_G2(P(1,2),1);
end
ca_code_math = G1.*G2;
% convert ca_code_math to Binary expression
ca_code_binary = ca_code_math;
for i=1:length(ca_code_binary);
if ca_code_binary(i) == -1
ca_code_binary(i)= 1;
else
ca_code_binary(i)= 0;
end
end
end