function channel = trackingInitChannelStruct( settings, acqResults )

%==============================================================================%
%                                                                              %
%   channel = trackingInitChannelStruct( settings, acqResults )                %
%                                                                              %
%   Initialize the active tracking channel structure                           %
%   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 channel structure ==========================================
channel.signalType              = acqResults.signalType;
channel.prn                     = acqResults.prn;
channel.codePhase               = acqResults.codePhase;
channel.dopplerFreq             = acqResults.dopplerFreq;
channel.carrierPhase            = acqResults.carrierPhase;
channel.carrierPhaseInt         = acqResults.carrierPhase;

%--- Number of milliseconds since tracking was initiated -----------------------
channel.msCount                 = 0;

%--- Extra code rollover counter -----------------------------------------------
channel.extraCodeRollover       = 0;

%--- Set initial corrections for the carrier and code NCOs ---------------------
channel.codeFreqCorrection      = 0;    % Correction to the code NCO
channel.carrierFreqCorrection   = 0;    % Correction to the carrier NCO

%--- Set initial conditions for carrier frequency and code frequency -----------
carrierFreq = channel.dopplerFreq + settings.intermediateFreq;
codeFreq    = settings.codeFreq + channel.dopplerFreq*settings.carrierAidingSF;
channel.carrierFreq             = carrierFreq;
channel.carrierFreqNCO          = carrierFreq;
channel.codeFreq                = codeFreq;
channel.codeFreqNCO             = settings.codeFreq;

%--- Index of the navigation data bit transition boundary ----------------------
%    --> this index is the number of the millisecond (1-20)
%        starting a navigation data bit.
%        So, navStartBit == 1 means that milliseconds 1-20
%        all belong to the same navigation data bit.
%        A navStartBit == 11 means that milliseconds 11-30
%        all belong to the same navigation data bit.
channel.navStartBit             = 1;

%--- Counter for millisecond number within the navigation data bit -------------
%    --> this counter is for the number of the millisecond (1-20)
%        within the navigation data bit; if the counter exceeds
%        the value of msPerDataBit then re-set the counter to 1.
%        If navStartBit == 1 then dataBitMsCounter goes from 1-20
%        for milliseconds 1-20 also.
%        If navStartBit == 11 then dataBitMsCounter goes from 1-20
%        for milliseconds 11-30.
channel.databitCounter          = 1;

%--- Counter for elapsed time between tracking loop updates --------------------
%    --> these counters are for the number of milliseconds
%        elapsed since calling the PLL/DLL functions; if the
%        counter exceeds the PLL/DLL integrationTime then
%        re-set the counter back to 1.
channel.pllCounter              = 1;
channel.dllCounter              = 1;

%--- In-phase and quadrature code correlators (complex) ------------------------
channel.correlators1.Early      = complex(0);
channel.correlators1.Prompt     = complex(0);
channel.correlators1.Late       = complex(0);
channel.correlators2.Early      = complex(0);
channel.correlators2.Prompt     = complex(0);
channel.correlators2.Late       = complex(0);

%--- Loop filter variables which must be saved between processing cycles -------
channel.DLL_discr               = 0;
channel.DLL_discrIntegrated     = 0;
channel.PLL_discr               = 0;
channel.PLL_discrIntegrated     = 0;

%=== PRN code chip sequence, values of +1 and -1 ===============================
codeChips = codeGenerateMASTER(settings.signalType, channel.prn);

%--- Repeat the last chip to protect against index roundoff errors -------------
channel.codeChips = [codeChips codeChips(end)];

%--- Initialize the I & Q mixing vector w/ zero carrier-phase (complex) --------
channel.IQ = exp(-1i * (channel.carrierFreq * settings.phasePts));

%--- Initialize the code-phase index vector w/ zero code-phase -----------------
channel.codePts = channel.codeFreq * settings.timePts;

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