function settings = trackingSettingsSecondary( settings, fileInfo )

%==============================================================================%
%                                                                              %
%   settings = trackingSettings( settings, fileInfo )                          %
%                                                                              %
%   Calculate secondary settings                                               %
%   David S. De Lorenzo                                                        %
%   17 November 2005                                                           %
%                                                                              %
%==============================================================================%
%                       GPS Software Receiver in Matlab                        %
%     Copyright (c) 2003-2017 David S. De Lorenzo / 2018-2023 Trimble Inc.     %
%==============================================================================%

%=== Relative time/phase of each sample point w.r.t. the epoch of sampling =====
settings.timePts  = (0:settings.samplesPer1ms-1) / settings.samplingFreq;
settings.phasePts = 2 * pi * settings.timePts;

%=== Calculate the maximum tracking duration ===================================
maxMsToProcess = calcTrackingLengthMs(settings, fileInfo.bytes);
settings.trk.msToProcess = min([settings.trk.msToProcess, maxMsToProcess]);

%=== Make sure that receiver mode transition settings are strictly monotonic ===
if ((settings.trk.transitionTimeMs < settings.trk.pullInTimeMs) ...
 || (settings.trk.pullInTimeMs < settings.trk.fllTimeMs) ...
 || (settings.trk.fllTimeMs < 0))
    error('***  Invalid mode transition times!!  ***');
end

%==============================================================================%
%   Calculate coefficients for the 2nd-order tracking loop filters.            %
%     The filter formula:                                                      %
%       y(n) = Kp * x(n) + Ki * [x(n) + x(n-1) + ... + x(1) + x(0)]            %
%==============================================================================%

%=== Make sure that the FLL pull-in mode integration time is 1 ms ==============
if (settings.PLL.F_integrationTime ~= 1)
    warning('  FLL pull-in mode integration time must be 1ms!!');
    fprintf('    --> The navigation data bit transition is not yet known.\n');
    fprintf('        Changing PLL.F_integrationTime back to 1ms!!\n\n');
    settings.PLL.F_integrationTime = 1;
end

%=== Make sure that the PLL pull-in mode integration time is 1 ms ==============
if (settings.PLL.P_integrationTime ~= 1)
    warning('  PLL pull-in mode integration time must be 1ms!!');
    fprintf('    --> The navigation data bit transition is not yet known.\n');
    fprintf('        Changing PLL.P_integrationTime back to 1ms!!\n\n');
    settings.PLL.P_integrationTime = 1;
end

%=== Make sure integration times are no longer than one data symbol ============
settings.PLL.X_integrationTime = min([settings.msPerDataBit, ...
                                      settings.PLL.X_integrationTime]);
settings.PLL.T_integrationTime = min([settings.msPerDataBit, ...
                                      settings.PLL.T_integrationTime]);
settings.DLL.P_integrationTime = min([settings.msPerDataBit, ...
                                      settings.DLL.P_integrationTime]);
settings.DLL.X_integrationTime = min([settings.msPerDataBit, ...
                                      settings.DLL.X_integrationTime]);
settings.DLL.T_integrationTime = min([settings.msPerDataBit, ...
                                      settings.DLL.T_integrationTime]);

%=== Calculate loop filter coefficients for the FLL mode =======================
%    Non-coherent tracking, with 1ms FLL integration time hard-coded!!!
[settings.PLL.F_Kp,settings.PLL.F_Ki] = ...
                  calcLoopFilterCoefs(settings.PLL.F_noiseBandwidth, ...
                                      settings.PLL.F_integrationTime * 0.001);

%=== Calculate loop filter coefficients for the pull-in mode ===================
%    Non-coherent tracking, with 1ms PLL integration time hard-coded!!!
[settings.PLL.P_Kp,settings.PLL.P_Ki] = ...
                  calcLoopFilterCoefs(settings.PLL.P_noiseBandwidth, ...
                                      settings.PLL.P_integrationTime * 0.001);
[settings.DLL.P_Kp,settings.DLL.P_Ki] = ...
                  calcLoopFilterCoefs(settings.DLL.P_noiseBandwidth, ...
                                      settings.DLL.P_integrationTime * 0.001);

%=== Calculate loop filter coefficients for the transition mode ================
%    Coherent tracking
[settings.PLL.X_Kp,settings.PLL.X_Ki] = ...
                  calcLoopFilterCoefs(settings.PLL.X_noiseBandwidth, ...
                                      settings.PLL.X_integrationTime * 0.001);
[settings.DLL.X_Kp,settings.DLL.X_Ki] = ...
                  calcLoopFilterCoefs(settings.DLL.X_noiseBandwidth, ...
                                      settings.DLL.X_integrationTime * 0.001);

%=== Calculate loop filter coefficients for the fine-tracking mode =============
%    Coherent tracking
[settings.PLL.T_Kp,settings.PLL.T_Ki] = ...
                  calcLoopFilterCoefs(settings.PLL.T_noiseBandwidth, ...
                                      settings.PLL.T_integrationTime * 0.001);
[settings.DLL.T_Kp,settings.DLL.T_Ki] = ...
                  calcLoopFilterCoefs(settings.DLL.T_noiseBandwidth, ...
                                      settings.DLL.T_integrationTime * 0.001);

%=== Tap points for detailed code correlation function visualization ===========
if (settings.trk.plotCorrelationPeak == true)
    settings.trk.correlationPeakCodeVec = ...
        [-4:0.1:-1, -0.95:0.05:0.95, 1:0.1:4]'; % [chips]
end

return
%===============================================================================