function settings = trackingSettings( settings )

%==============================================================================%
%                                                                              %
%   settings = trackingSettings( settings )                                    %
%                                                                              %
%   Initialize tracking 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.     %
%==============================================================================%

%--- Initialize the structure --------------------------------------------------
settings.softwareVersionNumber  = '3.3';
if ~(exist('OCTAVE_VERSION','builtin') > 0)
    settings.hostComputerName   = strcat(evalc('!hostname'));
end
%--- Tracking settings ---------------------------------------------------------
settings.trk.prnToTrack         =    3;         %  PRN #    usually 1-32
settings.trk.msToProcess        =  2000;        %  [ms]     default is 2sec

%--- How much buffer to leave at the end of the file ---------------------------
%    to avoid potential end-of-file fread errors.
settings.trk.endOfFileBufferMs  = 10;

%--- Switches ------------------------------------------------------------------
settings.trk.plotSwitch         = 'large';      % switch    [no/small/med/large]
settings.trk.plotToJPEG         = true;         % logical   [true/false]

%===============================================================================
%  Receiver mode transition settings
%    ______MODE__________________DESCRIPTION__________________________________
%        FLL Mode:       non-coherent integration, 1ms FLL update
%      Pull-In Mode:     non-coherent integration, 1ms PLL update
%     Transition Mode:   determine navigation boundary, coherent integration
%    Fine-Tracking Mode: coherent integration, i.e., 20ms for the GPS C/A-code
%
%           FROM                     TO                      MODE
%             0           to      fllTimeMs       -->      FLL Mode
%         fllTimeMs       to     pullInTimeMs     -->     Pull-In Mode
%        pullInTimeMs     to   transitionTimeMs   -->    Transition Mode
%      transitionTimeMs   to     msToProcess      -->   Fine-Tracking Mode
%===============================================================================
settings.trk.fllTimeMs          =  500;         %  [ms]
settings.trk.pullInTimeMs       = 1500;         %  [ms]
settings.trk.transitionTimeMs   = 2000;         %  [ms]

%===============================================================================
%  Tracking loop settings
%    There are 4 modes of operation for the carrier and code tracking loops:
%       1.  FLL Mode, for frequency alignment with the largest stable pull-in
%           range, hard-coded for 1ms of accumulation.
%       2.  Pull-in mode, for early tracking: to refine the Doppler frequency
%           and code-phase estimates, to establish carrier-phase lock, and to
%           allow enough navigation data bit flips to reliably estimate the
%           navigation data bit transition boundary (which will allow
%           coherent integration for the PLL and DLL discriminators).
%       3.  Transition mode, for tightening-up the loop filter bandwidths as
%           the Doppler frequency and code-phase estimates are further refined;
%           the first operation in the transition mode is to estimate the
%           navigation data bit transition boundary.
%       4.  Fine-tracking mode, for long-term steady-state tracking of the GPS
%           signal.
%    Note that, unlike a more complicated GPS receiver, this does't check
%    for stable FLL or PLL prior to mode transitions (strong signals could
%    allow the receiver to transition sooner than the hard-coded time
%    limits), doesn't check confidence in phase alignment or navigation
%    data bit boundary estimation, doesn't actively adjust the loop
%    bandwidths based on estimated C/No, doesn't have a lock detector or
%    logic to perceive a loss-of-lock situation, doesn't have any
%    switching logic to handle momentary outages or cycle-slips, nor
%    does it have re-acquisition or channel re-assignment states.
%    Basically, it's not a full-function receiver, but a tracking
%    environment that hopefully allows for the study of GNSS signals
%    (legacy C/A and new GPS/Galileo/Compass/SBAS), tracking loops and
%    inertial aiding, and multi-antenna and adaptive array algorithms.
%===============================================================================
%--- Carrier tracking loop -----------------------------------------------------
settings.PLL.F_noiseBandwidth   = 60;           %  [Hz]
settings.PLL.P_noiseBandwidth   = 40;           %  [Hz]
settings.PLL.X_noiseBandwidth   = 15;           %  [Hz]
settings.PLL.T_noiseBandwidth   =  7;           %  [Hz]
settings.PLL.F_integrationTime  =  1;           %  [ms] HARD-CODED, DON'T CHANGE
settings.PLL.P_integrationTime  =  1;           %  [ms] HARD-CODED, DON'T CHANGE
settings.PLL.X_integrationTime  =  5;           %  [ms]  Advised to keep short!
settings.PLL.T_integrationTime  = 20;           %  [ms]
%--- Code tracking loop --------------------------------------------------------
settings.DLL.correlatorSpacingC =  0.5;         % [chips] (prompt-to-early/late)
settings.DLL.P_noiseBandwidth   =  3;           %  [Hz]
settings.DLL.X_noiseBandwidth   =  1.5;         %  [Hz]
settings.DLL.T_noiseBandwidth   =  1;           %  [Hz]
settings.DLL.P_integrationTime  = 10;           %  [ms]  non-coherent DLL
settings.DLL.X_integrationTime  = 20;           %  [ms]    coherent DLL
settings.DLL.T_integrationTime  = 20;           %  [ms]    coherent DLL

%===============================================================================
%  Detailed code correlation function visualization
%    Stores values from more early/late correlators in order to
%    allow reconstruction of detailed correlation peak shape.
%
%    --> Slows code execution significantly.
%===============================================================================
settings.trk.plotCorrelationPeak = false;       % logical   [true/false]

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