-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtracking_MMT.m
763 lines (617 loc) · 33.3 KB
/
tracking_MMT.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
function [trackResults, channel]= tracking_MMT(fid, channel, settings)
% Performs code and carrier tracking for all channels.
%
%[trackResults, channel] = tracking(fid, channel, settings)
%
% Inputs:
% fid - file identifier of the signal record.
% channel - PRN, carrier frequencies and code phases of all
% satellites to be tracked (prepared by preRum.m from
% acquisition results).
% settings - receiver settings.
% Outputs:
% trackResults - tracking results (structure array). Contains
% in-phase prompt outputs and absolute spreading
% code's starting positions, together with other
% observation data from the tracking loops. All are
% saved every millisecond.
%--------------------------------------------------------------------------
% SoftGNSS v3.0
%
% Copyright (C) Dennis M. Akos
% Written by Darius Plausinaitis and Dennis M. Akos
% Based on code by DMAkos Oct-1999
%--------------------------------------------------------------------------
%This program is free software; you can redistribute it and/or
%modify it under the terms of the GNU General Public License
%as published by the Free Software Foundation; either version 2
%of the License, or (at your option) any later version.
%
%This program is distributed in the hope that it will be useful,
%but WITHOUT ANY WARRANTY; without even the implied warranty of
%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%GNU General Public License for more details.
%
%You should have received a copy of the GNU General Public License
%along with this program; if not, write to the Free Software
%Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
%USA.
%--------------------------------------------------------------------------
%CVS record:
%$Id: tracking.m,v 1.14.2.31 2006/08/14 11:38:22 dpl Exp $
%% Initialize result structure ============================================
% Edited by Sergio Vicenzo - 06 Jan 2025
codePeriods = settings.msToProcess/settings.DPE_cohInt; % For GPS one C/A code is one ms
% Channel status
trackResults.status = '-'; % No tracked signal, or lost lock
% The absolute sample in the record of the C/A code start:
trackResults.absoluteSample = zeros(1, codePeriods);
% Freq of the PRN code:
trackResults.codeFreq = inf(1, codePeriods);
% Frequency of the tracked carrier wave:
trackResults.carrFreq = inf(1, codePeriods);
% Outputs from the correlators (In-phase):
trackResults.I_P = zeros(1, codePeriods);
trackResults.I_E = zeros(1, codePeriods);
trackResults.I_L = zeros(1, codePeriods);
% Outputs from the correlators (Quadrature-phase):
trackResults.Q_E = zeros(1, codePeriods);
trackResults.Q_P = zeros(1, codePeriods);
trackResults.Q_L = zeros(1, codePeriods);
% Loop discriminators
trackResults.dllDiscr = inf(1, codePeriods);
trackResults.dllDiscrFilt = inf(1, codePeriods);
trackResults.pllDiscr = inf(1, codePeriods);
trackResults.pllDiscrFilt = inf(1, codePeriods);
% Remain code and carrier phase
trackResults.remCodePhase = inf(1, codePeriods);
trackResults.remCarrPhase = inf(1, codePeriods);
% Multipath Mitigation Technology variables
% Added by Sergio Vicenzo - 07 Jan 2025
trackResults.MMT_codeDelay_LOS = nan(1, codePeriods);
trackResults.MMT_codeDelay_NLOS = nan(1, codePeriods);
trackResults.MMT_codeDelay_NLOS_relative = nan(1, codePeriods);
trackResults.MMT_carrPhase_LOS = nan(1, codePeriods);
trackResults.MMT_carrPhase_NLOS = nan(1, codePeriods);
trackResults.MMT_amp_LOS = nan(1, codePeriods);
trackResults.MMT_amp_NLOS = nan(1, codePeriods);
trackResults.MMT_amp_LOS3 = nan(1, codePeriods);
trackResults.MMT_amp_NLOS3 = nan(1, codePeriods);
trackResults.MMT_time = nan(1, codePeriods);
%C/No
trackResults.CNo.VSMValue = ...
zeros(1,floor(codePeriods/settings.CNo.VSMinterval));
trackResults.CNo.VSMIndex = ...
zeros(1,floor(codePeriods/settings.CNo.VSMinterval));
%--- Copy initial settings for all channels -------------------------------
trackResults = repmat(trackResults, 1, settings.numberOfChannels);
%% Initialize tracking variables ==========================================
% Start waitbar
hwb = waitbar(0,'Tracking...');
%Adjust the size of the waitbar to insert text
CNoPos=get(hwb,'Position');
set(hwb,'Position',[CNoPos(1),CNoPos(2),CNoPos(3),90],'Visible','on');
if (settings.fileType==1)
dataAdaptCoeff=1;
else
dataAdaptCoeff=2;
end
%% Start processing channels ==============================================
for channelNr = 1:settings.numberOfChannels
%% Re-Initialize tracking variables ===================================
% First run with 1 ms coherent integration to find bit transition
% Edited by Sergio Vicenzo - 06 Jan 2025
codePeriods = settings.msToProcess; % For GPS one C/A code is one ms
% Only process if PRN is non zero (acquisition was successful)
if (channel(channelNr).PRN ~= 0)
% Save additional information - each channel's tracked PRN
trackResults(channelNr).PRN = channel(channelNr).PRN;
% Move the starting point of processing. Can be used to start the
% signal processing at any point in the data record (e.g. for long
% records). In addition skip through that data file to start at the
% appropriate sample (corresponding to code phase). Assumes sample
% type is schar (or 1 byte per sample)
% Edited by Sergio Vicenzo to also handle "int16" files
% 12 Feb 2024
if strcmp(settings.dataType,'int16')
fseek(fid, ...
dataAdaptCoeff*(settings.skipNumberOfBytes + ...
(channel(channelNr).codePhase-1)*2), ...
'bof');
else
fseek(fid, ...
dataAdaptCoeff*(settings.skipNumberOfBytes + ...
channel(channelNr).codePhase-1), ...
'bof');
end
% Get a vector with the C/A code sampled 1x/chip
caCode = generateCAcode(channel(channelNr).PRN);
% Then make it possible to do early and late versions
caCode = [caCode(1023) caCode caCode(1)];
%--- Perform various initializations ------------------------------
% define initial code frequency basis of NCO
codeFreq = settings.codeFreqBasis;
% define residual code phase (in chips)
remCodePhase = 0.0;
% define carrier frequency which is used over whole tracking period
carrFreq = channel(channelNr).acquiredFreq;
carrFreqBasis = channel(channelNr).acquiredFreq;
% define residual carrier phase
remCarrPhase = 0.0;
%code tracking loop parameters
oldCodeNco = 0.0;
oldCodeError = 0.0;
%carrier/Costas loop parameters
oldCarrNco = 0.0;
oldCarrError = 0.0;
settings.dllNoiseBandwidth = 1.5;
settings.pllNoiseBandwidth = 20;
%--- DLL variables --------------------------------------------------------
% Define early-late offset (in chips)
earlyLateSpc = settings.dllCorrelatorSpacing;
% Calculate filter coefficient values
[tau1code, tau2code] = calcLoopCoef(settings.dllNoiseBandwidth, ...
settings.dllDampingRatio, ...
1.0);
% Summation interval
PDIcode = 0.001;
%--- PLL variables --------------------------------------------------------
% Calculate filter coefficient values
[tau1carr, tau2carr] = calcLoopCoef(settings.pllNoiseBandwidth, ...
settings.pllDampingRatio, ...
0.25);
% Summation interval
PDIcarr = 0.001;
%=== Process the number of specified code periods =================
for loopCnt = 1:codePeriods
%% GUI update -------------------------------------------------------------
% The GUI is updated every 50ms. This way Matlab GUI is still
% responsive enough. At the same time Matlab is not occupied
% all the time with GUI task.
% Commented by Sergio Vicenzo - 06 Jan 2025
% if (rem(loopCnt, 50) == 0)
%
% Ln=sprintf('\n');
% trackingStatus=['Tracking: Ch ', int2str(channelNr), ...
% ' of ', int2str(settings.numberOfChannels),Ln ...
% 'PRN: ', int2str(channel(channelNr).PRN),Ln ...
% 'Completed ',int2str(loopCnt), ...
% ' of ', int2str(codePeriods), ' msec',Ln...
% 'C/No: ',CNo,' (dB-Hz)'];
%
% try
% waitbar(loopCnt/codePeriods, ...
% hwb, ...
% trackingStatus);
% catch
% % The progress bar was closed. It is used as a signal
% % to stop, "cancel" processing. Exit.
% disp('Progress bar closed, exiting...');
% return
% end
% end
%% Read next block of data ------------------------------------------------
% Record sample number (based on 8bit samples)
% Edited by Sergio Vicenzo to also handle "int16" files
% 12 Feb 2024
if strcmp(settings.dataType,'int16')
trackResults(channelNr).absoluteSample(loopCnt) = ...
(ftell(fid))/dataAdaptCoeff/2;
else
trackResults(channelNr).absoluteSample(loopCnt) = ...
(ftell(fid))/dataAdaptCoeff;
end
% Find the size of a "block" or code period in whole samples
% Update the phasestep based on code freq (variable) and
% sampling frequency (fixed)
codePhaseStep = codeFreq / settings.samplingFreq;
% Find the size of a "block" or code period in whole samples
blksize = ceil((settings.codeLength-remCodePhase) / codePhaseStep);
% Read in the appropriate number of samples to process this
% interation
[rawSignal, samplesRead] = fread(fid, ...
dataAdaptCoeff*blksize, settings.dataType);
rawSignal = rawSignal';
if (dataAdaptCoeff==2)
rawSignal1=rawSignal(1:2:end);
rawSignal2=rawSignal(2:2:end);
rawSignal = rawSignal1 + 1i .* rawSignal2; % transpose vector
end
% If did not read in enough samples, then could be out of
% data - better exit
if (samplesRead ~= dataAdaptCoeff*blksize)
disp('Not able to read the specified number of samples for tracking, exiting!')
fclose(fid);
return
end
%% Set up all the code phase tracking information -------------------------
% Save remCodePhase for current correlation
trackResults(channelNr).remCodePhase(loopCnt) = remCodePhase;
% Define index into early code vector
tcode = (remCodePhase-earlyLateSpc) : ...
codePhaseStep : ...
((blksize-1)*codePhaseStep+remCodePhase-earlyLateSpc);
tcode2 = ceil(tcode) + 1;
earlyCode = caCode(tcode2);
% Define index into late code vector
tcode = (remCodePhase+earlyLateSpc) : ...
codePhaseStep : ...
((blksize-1)*codePhaseStep+remCodePhase+earlyLateSpc);
tcode2 = ceil(tcode) + 1;
lateCode = caCode(tcode2);
% Define index into prompt code vector
tcode = remCodePhase : ...
codePhaseStep : ...
((blksize-1)*codePhaseStep+remCodePhase);
tcode2 = ceil(tcode) + 1;
promptCode = caCode(tcode2);
remCodePhase = (tcode(blksize) + codePhaseStep) - settings.codeLength;
%% Generate the carrier frequency to mix the signal to baseband -----------
% Save remCarrPhase for current correlation
trackResults(channelNr).remCarrPhase(loopCnt) = remCarrPhase;
% Get the argument to sin/cos functions
time = (0:blksize) ./ settings.samplingFreq;
trigarg = ((carrFreq * 2.0 * pi) .* time) + remCarrPhase;
remCarrPhase = rem(trigarg(blksize+1), (2 * pi));
% Finally compute the signal to mix the collected data to
% bandband
carrsig = exp(1i .* trigarg(1:blksize));
%% Generate the six standard accumulated values ---------------------------
% First mix to baseband
qBasebandSignal = real(carrsig .* rawSignal);
iBasebandSignal = imag(carrsig .* rawSignal);
% Now get early, late, and prompt values for each
I_E = sum(earlyCode .* iBasebandSignal);
Q_E = sum(earlyCode .* qBasebandSignal);
I_P = sum(promptCode .* iBasebandSignal);
Q_P = sum(promptCode .* qBasebandSignal);
I_L = sum(lateCode .* iBasebandSignal);
Q_L = sum(lateCode .* qBasebandSignal);
%% Find PLL error and update carrier NCO ----------------------------------
% Implement carrier loop discriminator (phase detector)
carrError = atan(Q_P / I_P) / (2.0 * pi);
% Implement carrier loop filter and generate NCO command
carrNco = oldCarrNco + (tau2carr/tau1carr) * ...
(carrError - oldCarrError) + carrError * (PDIcarr/tau1carr);
oldCarrNco = carrNco;
oldCarrError = carrError;
% Save carrier frequency for current correlation
trackResults(channelNr).carrFreq(loopCnt) = carrFreq;
% Modify carrier freq based on NCO command
carrFreq = carrFreqBasis + carrNco;
%% Find DLL error and update code NCO -------------------------------------
codeError = (sqrt(I_E * I_E + Q_E * Q_E) - sqrt(I_L * I_L + Q_L * Q_L)) / ...
(sqrt(I_E * I_E + Q_E * Q_E) + sqrt(I_L * I_L + Q_L * Q_L));
% Implement code loop filter and generate NCO command
codeNco = oldCodeNco + (tau2code/tau1code) * ...
(codeError - oldCodeError) + codeError * (PDIcode/tau1code);
oldCodeNco = codeNco;
oldCodeError = codeError;
% Save code frequency for current correlation
trackResults(channelNr).codeFreq(loopCnt) = codeFreq;
% Modify code freq based on NCO command
codeFreq = settings.codeFreqBasis - codeNco;
%% Record various measures to show in postprocessing ----------------------
trackResults(channelNr).dllDiscr(loopCnt) = codeError;
trackResults(channelNr).dllDiscrFilt(loopCnt) = codeNco;
trackResults(channelNr).pllDiscr(loopCnt) = carrError;
trackResults(channelNr).pllDiscrFilt(loopCnt) = carrNco;
trackResults(channelNr).I_E(loopCnt) = I_E;
trackResults(channelNr).I_P(loopCnt) = I_P;
trackResults(channelNr).I_L(loopCnt) = I_L;
trackResults(channelNr).Q_E(loopCnt) = Q_E;
trackResults(channelNr).Q_P(loopCnt) = Q_P;
trackResults(channelNr).Q_L(loopCnt) = Q_L;
% Commented by Sergio Vicenzo - 07 Jan 2025
% if (rem(loopCnt,settings.CNo.VSMinterval)==0)
% vsmCnt=vsmCnt+1;
% CNoValue=CNoVSM(trackResults(channelNr).I_P(loopCnt-settings.CNo.VSMinterval+1:loopCnt),...
% trackResults(channelNr).Q_P(loopCnt-settings.CNo.VSMinterval+1:loopCnt),settings.CNo.accTime);
% trackResults(channelNr).CNo.VSMValue(vsmCnt)=CNoValue;
% trackResults(channelNr).CNo.VSMIndex(vsmCnt)=loopCnt;
% CNo=int2str(CNoValue);
% end
% Check for bit transition --------------------------------------------
% Locate bit transition after 2000 ms of tracking with PDI = 1
% ms
% 2000 ms was chosen arbitrarily based on observation that the
% tracking loop has stabilised
% Added by Sergio Vicenzo - 06 Jan 2025
%
if loopCnt > 2000 && ...
sign(I_P)~=sign(trackResults(channelNr).I_P(loopCnt-1))
newStart=loopCnt;
break;
end
end % for loopCnt
%% Restart Tracking with desired coherent integration time ================
% Added by Sergio Vicenzo - 06 Jan 2025
% Re-Initialize tracking variables ----------------------------------------
settings.dllNoiseBandwidth = 4;
settings.pllNoiseBandwidth = 5;
% Get a vector with the C/A code sampled 1x/chip
caCode = generateCAcode(channel(channelNr).PRN);
% Then make it possible to do early and late versions
caCode = [caCode(1023-2) caCode(1023-1) caCode(1023)...
repmat(caCode,1,settings.DPE_cohInt)...
caCode(1) caCode(2) caCode(3)];
ori_codeperiods=settings.msToProcess;
codePeriods=round(codePeriods/settings.DPE_cohInt);
%--- DLL variables --------------------------------------------------------
% Summation interval
PDIcode = settings.DPE_cohInt/1000;
% Calculate filter coefficient values
[tau1code, tau2code] = calcLoopCoef(settings.dllNoiseBandwidth, ...
settings.dllDampingRatio, ...
1.0);
%--- PLL variables --------------------------------------------------------
% Summation interval
PDIcarr = settings.DPE_cohInt/1000;
% Calculate filter coefficient values
[tau1carr, tau2carr] = calcLoopCoef(settings.pllNoiseBandwidth, ...
settings.pllDampingRatio, ...
0.25);
%--- Perform various initializations --------------------------------------
% define initial code frequency basis of NCO
codeFreq = trackResults(channelNr).codeFreq(newStart-1);
% define residual code phase (in chips)
remCodePhase = trackResults(channelNr).remCodePhase(newStart);
% define carrier frequency which is used over whole tracking period
carrFreq = trackResults(channelNr).carrFreq(newStart-1);
carrFreqBasis = channel(channelNr).acquiredFreq;
% define residual carrier phase
remCarrPhase = trackResults(channelNr).remCarrPhase(newStart);
%code tracking loop parameters
oldCodeNco = trackResults(channelNr).dllDiscrFilt(newStart-1);
oldCodeError = trackResults(channelNr).dllDiscr(newStart-1);
%carrier/Costas loop parameters
oldCarrNco = trackResults(channelNr).pllDiscrFilt(newStart-1);
oldCarrError = trackResults(channelNr).pllDiscr(newStart-1);
%C/No computation
vsmCnt = 0;CNo = 0;
%=== Process the number of specified code periods =================
for loopCnt = 1:codePeriods
%To record MMT computation time
% Added by Sergio Vicenzo - 5 Nov 2024
tic
%% GUI update -------------------------------------------------------------
% The GUI is updated every 50ms. This way Matlab GUI is still
% responsive enough. At the same time Matlab is not occupied
% all the time with GUI task.
if (rem(loopCnt, 50) == 0)
Ln=sprintf('\n');
trackingStatus=['Tracking: Ch ', int2str(channelNr), ...
' of ', int2str(settings.numberOfChannels),Ln ...
'PRN: ', int2str(channel(channelNr).PRN),Ln ...
'Completed ',int2str(loopCnt* settings.DPE_cohInt), ...
' of ', int2str(ori_codeperiods), ' msec',Ln...
'C/No: ',CNo,' (dB-Hz)'];
try
waitbar(loopCnt/codePeriods, ...
hwb, ...
trackingStatus);
catch
% The progress bar was closed. It is used as a signal
% to stop, "cancel" processing. Exit.
disp('Progress bar closed, exiting...');
return
end
end
% Move the starting point of processing. Can be used to start the
% signal processing at any point in the data record (e.g. for long
% records). In addition skip through that data file to start at the
% appropriate sample (corresponding to code phase). Assumes sample
% type is schar (or 1 byte per sample)
% Edited by Sergio Vicenzo to also handle "int16" files
% 06 Jan 2025
if loopCnt==1
if strcmp(settings.dataType,'int16')
fseek(fid, ...
dataAdaptCoeff*(...
(trackResults(channelNr).absoluteSample(newStart))*2), ...
'bof');
else
fseek(fid, ...
dataAdaptCoeff*(trackResults(channelNr).absoluteSample(newStart)), ...
'bof');
end
end
%% Read next block of data ------------------------------------------------
% Record sample number (based on 8bit samples)
% Edited by Sergio Vicenzo to also handle "int16" files
% 12 Feb 2024
if strcmp(settings.dataType,'int16')
trackResults(channelNr).absoluteSample(loopCnt) = ...
(ftell(fid))/dataAdaptCoeff/2;
else
trackResults(channelNr).absoluteSample(loopCnt) = ...
(ftell(fid))/dataAdaptCoeff;
end
% Find the size of a "block" or code period in whole samples
% Update the phasestep based on code freq (variable) and
% sampling frequency (fixed)
codePhaseStep = codeFreq / settings.samplingFreq;
% Find the size of a "block" or code period in whole samples
blksize = ceil(((settings.codeLength*settings.DPE_cohInt)-remCodePhase) ...
/ codePhaseStep);
% Read in the appropriate number of samples to process this
% interation
[rawSignal, samplesRead] = fread(fid, ...
dataAdaptCoeff*blksize, settings.dataType);
rawSignal = rawSignal';
if (dataAdaptCoeff==2)
rawSignal1=rawSignal(1:2:end);
rawSignal2=rawSignal(2:2:end);
rawSignal = rawSignal1 + 1i .* rawSignal2; % transpose vector
end
% If did not read in enough samples, then could be out of
% data - better exit
if (samplesRead ~= dataAdaptCoeff*blksize)
disp('Not able to read the specified number of samples for tracking, exiting!')
fclose(fid);
return
end
% Save remCodePhase for current correlation
trackResults(channelNr).remCodePhase(loopCnt) = remCodePhase;
%% Generate the carrier frequency to mix the signal to baseband -----------
% Save remCarrPhase for current correlation
trackResults(channelNr).remCarrPhase(loopCnt) = remCarrPhase;
% Get the argument to sin/cos functions
time = (0:blksize) ./ settings.samplingFreq;
trigarg = ((carrFreq * 2.0 * pi) .* time) + remCarrPhase;
remCarrPhase = rem(trigarg(blksize+1), (2 * pi));
% Finally compute the signal to mix the collected data to
% bandband
carrsig = exp(1i .* trigarg(1:blksize));
%% Generate the six standard accumulated values ---------------------------
% First mix to baseband
qBasebandSignal = real(carrsig .* rawSignal);
iBasebandSignal = imag(carrsig .* rawSignal);
MMT_const= settings.MMT_const;
[~,...
store_a,store_a3,...
store_b,store_b3,...
store_c,store_c3,...
store_d,store_d3,...
LOS_codeDelay, ...
NLOS_codeDelay,...
codeDelay_LOS_indx,...
codeDelay_NLOS_indx] = MMT_Sergio...
(remCodePhase,codePhaseStep,blksize,...
caCode,iBasebandSignal,qBasebandSignal,MMT_const);
% Obtain LOS code delay
% Added by Sergio Vicenzo - 5 Nov 2024
trackResults(channelNr).MMT_codeDelay_LOS(loopCnt)...
= LOS_codeDelay;
% Obtain reflected path code delay
% Added by Sergio Vicenzo - 5 Nov 2024
trackResults(channelNr).MMT_codeDelay_NLOS(loopCnt)...
= NLOS_codeDelay;
% Obtain relative delay of reflected path
% Added by Sergio Vicenzo - 5 Nov 2024
trackResults(channelNr).MMT_codeDelay_NLOS_relative(loopCnt)...
= NLOS_codeDelay-LOS_codeDelay;
% Obtain carrier phase of LOS path
% Added by Sergio Vicenzo - 26 Dec 2024
trackResults(channelNr).MMT_carrPhase_LOS(loopCnt)...
= (((pi/2)*...
(1-sign(store_a3(codeDelay_LOS_indx,codeDelay_NLOS_indx)))*...
sign(store_c3(codeDelay_LOS_indx,codeDelay_NLOS_indx))) ...
+ atan(store_c3(codeDelay_LOS_indx,codeDelay_NLOS_indx)...
/store_a3(codeDelay_LOS_indx,codeDelay_NLOS_indx)));
% Obtain carrier phase of reflected path
% Added by Sergio Vicenzo - 26 Dec 2024
trackResults(channelNr).MMT_carrPhase_NLOS(loopCnt)...
= (((pi/2)*...
(1-sign(store_b3(codeDelay_LOS_indx,codeDelay_NLOS_indx)))*...
sign(store_d3(codeDelay_LOS_indx,codeDelay_NLOS_indx))) ...
+ atan(store_d3(codeDelay_LOS_indx,codeDelay_NLOS_indx)...
/store_b3(codeDelay_LOS_indx,codeDelay_NLOS_indx)));
% Obtain amplitude of LOS path
% Added by Sergio Vicenzo - 26 Dec 2024
trackResults(channelNr).MMT_amp_LOS(loopCnt)...
=(sqrt((store_a(codeDelay_LOS_indx,codeDelay_NLOS_indx)).^2 + ...
(store_c(codeDelay_LOS_indx,codeDelay_NLOS_indx)).^2));
trackResults(channelNr).MMT_amp_LOS3(loopCnt)...
=(sqrt((store_a3(codeDelay_LOS_indx,codeDelay_NLOS_indx)).^2 + ...
(store_c3(codeDelay_LOS_indx,codeDelay_NLOS_indx)).^2));
% Obtain amplitude of reflected path
% Added by Sergio Vicenzo - 26 Dec 2024
trackResults(channelNr).MMT_amp_NLOS(loopCnt)...
=(sqrt((store_b(codeDelay_LOS_indx,codeDelay_NLOS_indx)).^2 + ...
(store_d(codeDelay_LOS_indx,codeDelay_NLOS_indx)).^2));
trackResults(channelNr).MMT_amp_NLOS3(loopCnt)...
=(sqrt((store_b3(codeDelay_LOS_indx,codeDelay_NLOS_indx)).^2 + ...
(store_d3(codeDelay_LOS_indx,codeDelay_NLOS_indx)).^2));
%% Set up all the code phase tracking information -------------------------
% Define index into early code vector
tcode = (remCodePhase-earlyLateSpc) : ...
codePhaseStep : ...
((blksize-1)*codePhaseStep+remCodePhase-earlyLateSpc);
tcode2 = ceil(tcode) + 3;
earlyCode = caCode(tcode2);
% Define index into late code vector
tcode = (remCodePhase+earlyLateSpc) : ...
codePhaseStep : ...
((blksize-1)*codePhaseStep+remCodePhase+earlyLateSpc);
tcode2 = ceil(tcode) + 3;
lateCode = caCode(tcode2);
% Define index into prompt code vector
tcode = remCodePhase : ...
codePhaseStep : ...
((blksize-1)*codePhaseStep+remCodePhase);
tcode2 = ceil(tcode) + 3;
promptCode = caCode(tcode2);
remCodePhase = (tcode(blksize) + codePhaseStep)...
- settings.codeLength * (settings.DPE_cohInt);
% Now get early, late, and prompt values for each
I_E = sum(earlyCode .* iBasebandSignal);
Q_E = sum(earlyCode .* qBasebandSignal);
I_P = sum(promptCode .* iBasebandSignal);
Q_P = sum(promptCode .* qBasebandSignal);
I_L = sum(lateCode .* iBasebandSignal);
Q_L = sum(lateCode .* qBasebandSignal);
%% Find PLL error and update carrier NCO ----------------------------------
% Implement carrier loop discriminator (phase detector)
carrError = atan(Q_P / I_P) / (2.0 * pi);
% Implement carrier loop filter and generate NCO command
carrNco = oldCarrNco + (tau2carr/tau1carr) * ...
(carrError - oldCarrError) + carrError * (PDIcarr/tau1carr);
oldCarrNco = carrNco;
oldCarrError = carrError;
% Save carrier frequency for current correlation
trackResults(channelNr).carrFreq(loopCnt) = carrFreq;
% Modify carrier freq based on NCO command
carrFreq = carrFreqBasis + carrNco;
%% Find DLL error and update code NCO -------------------------------------
% Disabled by Sergio Vicenzo - 5 Nov 2024
% codeError = (sqrt(I_E * I_E + Q_E * Q_E) - sqrt(I_L * I_L + Q_L * Q_L)) / ...
% (sqrt(I_E * I_E + Q_E * Q_E) + sqrt(I_L * I_L + Q_L * Q_L));
% DLL error now defined by LOS delay from MMT
% Added by Sergio Vicenzo - 5 Nov 2024
codeError = LOS_codeDelay;
% Implement code loop filter and generate NCO command
codeNco = oldCodeNco + (tau2code/tau1code) * ...
(codeError - oldCodeError) + codeError * (PDIcode/tau1code);
oldCodeNco = codeNco;
oldCodeError = codeError;
% Save code frequency for current correlation
trackResults(channelNr).codeFreq(loopCnt) = codeFreq;
% Modify code freq based on NCO command
codeFreq = settings.codeFreqBasis - codeNco;
%% Record various measures to show in postprocessing ----------------------
trackResults(channelNr).dllDiscr(loopCnt) = codeError;
trackResults(channelNr).dllDiscrFilt(loopCnt) = codeNco;
trackResults(channelNr).pllDiscr(loopCnt) = carrError;
trackResults(channelNr).pllDiscrFilt(loopCnt) = carrNco;
trackResults(channelNr).I_E(loopCnt) = I_E;
trackResults(channelNr).I_P(loopCnt) = I_P;
trackResults(channelNr).I_L(loopCnt) = I_L;
trackResults(channelNr).Q_E(loopCnt) = Q_E;
trackResults(channelNr).Q_P(loopCnt) = Q_P;
trackResults(channelNr).Q_L(loopCnt) = Q_L;
if (rem(loopCnt,settings.CNo.VSMinterval)==0)
vsmCnt=vsmCnt+1;
CNoValue=CNoVSM(trackResults(channelNr).I_P(loopCnt-settings.CNo.VSMinterval+1:loopCnt),...
trackResults(channelNr).Q_P(loopCnt-settings.CNo.VSMinterval+1:loopCnt),settings.CNo.accTime*settings.DPE_cohInt);
trackResults(channelNr).CNo.VSMValue(vsmCnt)=CNoValue;
trackResults(channelNr).CNo.VSMIndex(vsmCnt)=loopCnt;
CNo=int2str(CNoValue);
end
% Clear MMT variables after every loop
% Added by Sergio Vicenzo - 5 Nov 2024
clear codedelay_index LOS_delay codeDelay_NLOS_indx ...
codeDelay_LOS_indx precalc_correlations MaxCorrValue ...
MMT_cost_func3 LOS_codeDelay NLOS_codeDelay
% Record MMT computation time for analysis
% Added by Sergio Vicenzo - 5 Nov 2024
trackResults(channelNr).MMT_time(loopCnt) = toc;
end % for loopCnt
% If we got so far, this means that the tracking was successful
% Now we only copy status, but it can be update by a lock detector
% if implemented
trackResults(channelNr).status = channel(channelNr).status;
end % if a PRN is assigned
end % for channelNr
% Close the waitbar
close(hwb)