-
Notifications
You must be signed in to change notification settings - Fork 6
/
postProcessing.m
197 lines (161 loc) · 7.57 KB
/
postProcessing.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
% Script postProcessing.m processes the raw signal from the specified data
% file (in settings) operating on blocks of 37 seconds of data.
%
% First it runs acquisition code identifying the satellites in the file,
% then the code and carrier for each of the satellites are tracked, storing
% the 1msec accumulations. After processing all satellites in the 37 sec
% data block, then postNavigation is called. It calculates pseudoranges
% and attempts a position solutions. At the end plots are made for that
% block of data.
%--------------------------------------------------------------------------
% SoftGNSS v3.0
%
% Copyright (C) Darius Plausinaitis
% Written by Darius Plausinaitis, Dennis M. Akos
% Some ideas by Dennis M. Akos
%--------------------------------------------------------------------------
%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.
%--------------------------------------------------------------------------
% THE SCRIPT "RECIPE"
%
% The purpose of this script is to combine all parts of the software
% receiver.
%
% 1.1) Open the data file for the processing and seek to desired point.
%
% 2.1) Acquire satellites
%
% 3.1) Initialize channels (preRun.m).
% 3.2) Pass the channel structure and the file identifier to the tracking
% function. It will read and process the data. The tracking results are
% stored in the trackResults structure. The results can be accessed this
% way (the results are stored each millisecond):
% trackResults(channelNumber).XXX(fromMillisecond : toMillisecond), where
% XXX is a field name of the result (e.g. I_P, codePhase etc.)
%
% 4) Pass tracking results to the navigation solution function. It will
% decode navigation messages, find satellite positions, measure
% pseudoranges and find receiver position.
%
% 5) Plot the results.
%% Initialization =========================================================
addpath include
addpath common
disp ('Starting processing...');
settings = initSettings();
[fid, message] = fopen(settings.fileName, 'rb');
% Disabled by Sergio Vicenzo - 14 Feb 2024
% probeData(settings);
%Initialize the multiplier to adjust for the data type
if (settings.fileType==1)
dataAdaptCoeff=1;
else
dataAdaptCoeff=2;
end
%If success, then process the data
if (fid > 0)
% Move the starting point of processing. Can be used to start the
% signal processing at any point in the data record (e.g. good for long
% records or for signal processing in blocks).
fseek(fid, dataAdaptCoeff*settings.skipNumberOfBytes, 'bof');
%% Acquisition ============================================================
% Do acquisition if it is not disabled in settings or if the variable
% acqResults does not exist.
if ((settings.skipAcquisition == 0) || ~exist('acqResults', 'var'))
% Find number of samples per spreading code
samplesPerCode = round(settings.samplingFreq / ...
(settings.codeFreqBasis / settings.codeLength));
% Read data for acquisition. 11ms of signal are needed for the fine
% frequency estimation
data = fread(fid, dataAdaptCoeff*11*samplesPerCode, settings.dataType)';
if (dataAdaptCoeff==2)
data1=data(1:2:end);
data2=data(2:2:end);
data=data1 + 1i .* data2;
end
%--- Do the acquisition -------------------------------------------
disp (' Acquiring satellites...');
acqResults = acquisition(data, settings);
plotAcquisition(acqResults);
end
%% Initialize channels and prepare for the run ============================
% Start further processing only if a GNSS signal was acquired (the
% field FREQUENCY will be set to 0 for all not acquired signals)
if (any(acqResults.carrFreq))
channel = preRun(acqResults, settings);
showChannelStatus(channel, settings);
else
% No satellites to track, exit
disp('No GNSS signals detected, signal processing finished.');
trackResults = [];
return;
end
%% Make folder for every IF file ==========================================
% Added by Sergio Vicenzo - 14 Feb 2024
outfile_root=findstr(settings.fileName,'\');
outfile_root=settings.fileName(outfile_root(end)+1:end-4);
mkdir(outfile_root);
settings.outfile_root=outfile_root;
%% Track the signal =======================================================
if ~exist([settings.outfile_root, '\trackResults_gps_', settings.outfile_root,'.mat'])
startTime = now;
disp ([' Tracking started at ', datestr(startTime)]);
% Process all channels for given data block
[trackResults, channel] = tracking(fid, channel, settings);
disp([' Tracking is over (elapsed time ', ...
datestr(now - startTime, 13), ')'])
% Auto save the acquisition & tracking results to a file to allow
% running the positioning solution afterwards.
disp(' Saving Acq & Tracking results to file "trackingResults.mat"')
% === Saves tracking result to folder =================================
% Added by Sergio Vicenzo - 14 Feb 2024
save([settings.outfile_root, '\trackResults_gps_', ...
settings.outfile_root], 'trackResults', 'settings', 'acqResults',...
'channel');
else
% === In case of new settings, save new settings to tracking file =====
% Added by Sergio Vicenzo - 13 Feb 2024
new_settings = settings;
% === Loads prev tracking result ======================================
% Added by Sergio Vicenzo - 14 Feb 2024
load([settings.outfile_root, '\trackResults_gps_',...
settings.outfile_root,'.mat']);
settings=new_settings;
if ~exist('trackResults','var')
trackResults = trackResults_gps;
end
save([settings.outfile_root, '\trackResults_gps_', ...
settings.outfile_root], 'trackResults', 'settings', 'acqResults',...
'channel');
end
%% Calculate navigation solutions =========================================
disp(' Calculating navigation solutions...');
% "fid" added as input for postNavigation for loading IF data for DPE
% module
% Added by Sergio Vicenzo - 12 Feb 2024
[navSolutions, eph] = postNavigation(trackResults, settings, fid);
disp(' Processing is complete for this data block');
%% Plot all results =======================================================
disp (' Ploting results...');
if settings.plotTracking
plotTracking(1:settings.numberOfChannels, trackResults, settings);
end
plotNavigation(navSolutions, settings);
disp('Post processing of the signal is over.');
else
% Error while opening the data file.
error('Unable to read file %s: %s.', settings.fileName, message);
end % if (fid > 0)