-
Notifications
You must be signed in to change notification settings - Fork 0
/
bit_reduction_thesis.m
342 lines (282 loc) · 9.17 KB
/
bit_reduction_thesis.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
function [ab,eb,incb,RAANb,omegab,M0b,Cusb,Cucb,IDOTb,numbits] = bit_reduction(a,e,inc,RAAN,omega,M0,Cus,Cuc,IDOT)
%% BIT REDUCTION
% -------------------------------------------------------------------------
% DESCRIPTION
%
% Written By: Tyler Reid ([email protected])
% PI: Todd Walter, Per Enge
% Lab: Stanford University GPS Lab
% Date Start: Summer 2013
% Modified to match IWG draft ICD March 3, 2015
%
% -------------------------------------------------------------------------
% FUNCTION DESCRIPTION
%
% This takes the L5 SBAS MOPS ephemeris message parameters and applies
% quantization. This reduces the number of bits used in matlab to represent
% these parameters to those specified in the ICD.
%
% -------------------------------------------------------------------------
% INPUT:
%
% a = Best fit semi-major axis [m]
% e = Best fit eccentricity [-]
% inc = Best fit inclination [rad]
% RAAN = Best fit right ascension of the ascending node [rad]
% omega = Best fit argument of perigee [rad]
% M0 = Best fit mean anomaly at epoch [rad]
% Cus, Cuc = Best fit along-track harmonic correction terms [rad/s]
% IDOT = Best fit inclination correction rate [rad/s]
%
% -------------------------------------------------------------------------
% OUTPUT:
%
% ab = Quantized (truncated) a
% eb = Quantized (truncated) e
% incb = Quantized (truncated) inc
% RAANb = Quantized (truncated) RAAN
% omegab = Quantized (truncated) omega
% M0b = Quantized (truncated) M0
% Cusb, Cucb = Quantized (truncated) Cus, Cuc
% IDOTb = Quantized (truncated) IDOT
% num_bits = Total number of message bits (combined)
%
%% IMPLEMENTATION
% Parameter bit assignment.
% Based on the IWG draft MOPS ICD 16/12/2014
% This was different for ION GNSS 2013.
a_bits = 32;
e_bits = 31;
i_bits = 34;
RAAN_bits = 35; % allows 1 sign bit
omega_bits = 35; % allows 1 sign bit
M0_bits = 35; % allows 1 sign bit
Cuc_bits = 22; % allows 1 sign bit
Cus_bits = 22; % allows 1 sign bit
IDOT_bits = 22; % allows 1 sign bit
% Compute the number of message bits.
numbits = a_bits+e_bits+i_bits+RAAN_bits+omega_bits+M0_bits+IDOT_bits+Cuc_bits+Cus_bits;
% Define scale factors (SF).
% SF's are as per the IWG draft MOPS ICD 16/12/2014
% This was different for ION GNSS 2013.
scale_a = 0.01; % 32 bits (0 sign)
scale_e = 2^-31; % 33 bits (0 sign)
scale_i = pi*2^-34; % 34 bits (0 sign)
scale_RAAN = pi*2^-34; % 35 bits (1 sign)
scale_omega = pi*2^-34; % 35 bits (1 sign)
scale_M0 = pi*2^-34; % 35 bits (1 sign)
scale_Cuc = ((pi/2)*1e-4)*(2^-21); % 22 bits (1 sign)
scale_Cus = ((pi/2)*1e-4)*(2^-21); % 22 bits (1 sign)
scale_IDOT = ((7*pi/6)*1e-6)*(2^-21); % 22 bits (1 sign)
% -------------------------------------------------------------------------
% Semi major axis
% -------------------------------------------------------------------------
% Apply scale factor.
temp = a/scale_a;
% Convert to binary string.
tempbin = dec2bin(round(temp));
% Determine if the string is within bit limit.
if length(tempbin)>a_bits
error('Semi major axis bit overflow')
return;
else
ab = bin2dec(tempbin)*scale_a;
a_bits = length(tempbin);
end
% -------------------------------------------------------------------------
% Eccentricity
% -------------------------------------------------------------------------
% Apply scale factor.
temp = e/scale_e;
% Convert to binary string.
tempbin = dec2bin(round(temp));
% Determine if the string is within bit limit.
if length(tempbin)>e_bits
error('Eccentricity bit overflow')
return;
else
eb = bin2dec(tempbin)*scale_e;
e_bits = length(tempbin);
end
% -------------------------------------------------------------------------
% Inclination
% -------------------------------------------------------------------------
% Make sure inclination is in acceptable limits.
if inc < 0 || inc > pi
fprintf('Inclination must be a number between 0 and pi [rad]\n');
return;
end
% Apply scale factor.
temp = inc/scale_i;
% Convert to binary string.
tempbin = dec2bin(round(temp));
% Determine if the string is within the bit limit.
if length(tempbin)>i_bits
error('Inclination bit overflow')
return;
else
incb = bin2dec(tempbin)*scale_i;
i_bits = length(tempbin);
end
% -------------------------------------------------------------------------
% RAAN
% -------------------------------------------------------------------------
% Make sure RAAN is within +/- pi bounds.
if RAAN > pi || RAAN < -pi
% Put in the correct range.
RAAN = mod(RAAN,2*pi);
if RAAN > pi
RAAN = RAAN-2*pi;
end
end
% Deal with negative numbers.
if RAAN < 0
RAAN = -RAAN;
negate = 1;
else
negate = 0;
end
% Apply scale factor.
temp = RAAN/scale_RAAN;
% Convert to binary string.
tempbin = dec2bin(floor(temp));
% Determine if the string is within the bit limit.
if length(tempbin)>RAAN_bits-1 % Allows for theoretical sign bit
error('RAAN bit overflow')
return;
else
RAANb = bin2dec(tempbin)*scale_RAAN*(-1)^negate;
RAAN_bits = length(tempbin);
end
% -------------------------------------------------------------------------
% omega
% -------------------------------------------------------------------------
% Make sure omega is within +/- pi bounds
if omega >= pi || omega <= -pi
% Put in the correct range.
omega = mod(omega, 2*pi);
if omega >= pi
omega = omega-2*pi;
end
end
% Deal with negative numbers.
if omega <= 0
omega = -omega;
negate = 1;
else
negate = 0;
end
% Apply scale factor.
temp = omega/scale_omega;
if omega == pi
temp = temp - 1;
end
% Convert to binary string.
tempbin = dec2bin(round(temp));
% Determine if the string is within bit limit.
if length(tempbin)>omega_bits-1 % allows for theoretical sign bit
error('omega bit overflow')
return;
else
omegab = bin2dec(tempbin)*scale_omega*(-1)^negate;
omega_bits = length(tempbin);
end
% -------------------------------------------------------------------------
% M0
% -------------------------------------------------------------------------
% Make sure omega is within +/- pi bounds.
if M0 > pi || M0 < -pi
% Put in the correct range.
M0 = mod(M0,2*pi);
if M0 > pi
M0 = M0-2*pi;
end
end
% Deal with negative numbers.
if M0 < 0
M0 = -M0;
negate = 1;
else
negate = 0;
end
% Apply scale factor.
temp = M0/scale_M0;
% Convert to binary string.
tempbin = dec2bin(round(temp));
% Determine if the string is within bit limit.
if length(tempbin)>M0_bits-1 % allows for theoretical sign bit
error('M0 bit overflow')
return;
else
M0b = bin2dec(tempbin)*scale_M0*(-1)^negate;
M0_bits = length(tempbin);
end
% -------------------------------------------------------------------------
% IDOT
% -------------------------------------------------------------------------
% Deal with negative numbers.
if IDOT < 0
IDOT = -IDOT;
negate = 1;
else
negate = 0;
end
% Apply scale factor.
temp = IDOT/scale_IDOT;
% Convert to binary string.
tempbin = dec2bin(round(temp));
% Determine if the string is within bit limit.
if length(tempbin)>IDOT_bits-1 % allows for theoretical sign bit
error('IDOT bit overflow')
return;
else
IDOTb = bin2dec(tempbin)*scale_IDOT*(-1)^negate;
IDOT_bits = length(tempbin);
end
% -------------------------------------------------------------------------
% Cus
% -------------------------------------------------------------------------
% Deal with negative numbers.
if Cus < 0
Cus = -Cus;
negate = 1;
else
negate = 0;
end
% Apply scale factor.
temp = Cus/scale_Cus;
% Convert to binary string.
tempbin = dec2bin(round(temp));
% Determine if the string is withing bit limit.
if length(tempbin)>Cus_bits-1 % allows for theoretical sign bit
error('Cus bit overflow')
return;
else
Cusb = bin2dec(tempbin)*scale_Cus*(-1)^negate;
Cus_bits = length(tempbin);
end
% -------------------------------------------------------------------------
% Cuc
% -------------------------------------------------------------------------
% Deal with negative numbers.
if Cuc < 0
Cuc = -Cuc;
negate = 1;
else
negate = 0;
end
% Apply scale factor.
temp = Cuc/scale_Cuc;
% Convert to binary string.
tempbin = dec2bin(round(temp));
% Determine if the string is withing bit limit.
if length(tempbin)>Cuc_bits-1 % allows for theoretical sign bit
error('Cuc bit overflow')
return;
else
Cucb = bin2dec(tempbin)*scale_Cuc*(-1)^negate;
Cuc_bits = length(tempbin);
end
% Count the total number of bits of the message.
numbits = a_bits + e_bits + i_bits + RAAN_bits + 1 + omega_bits +...
1 + M0_bits + 1 + IDOT_bits + 1 + Cuc_bits + 1 + Cus_bits;