function navDataBits = estNavDataBits( navStartBit, msPerDataBit, I_prompt )

%==============================================================================%
%                                                                              %
%   navDataBits = estNavDataBits( navStartBit, msPerDataBit, I_prompt )        %
%                                                                              %
%   Estimate the navigation data bit values at each ms epoch                   %
%   David S. De Lorenzo                                                        %
%   15 March 2006                                                              %
%                                                                              %
%------------------------------------------------------------------------------%
%                                                                              %
%   Input:                                                                     %
%        navStartBit   - navigation data bit transition index                  %
%        msPerDataBit  - milliseconds per data bit                             %
%        I_prompt      - in-phase prompt correlator output                     %
%                                                                              %
%   Output:                                                                    %
%        navDataBits   - values of the nav. data bit at each ms [+1 or -1]     %
%                                                                              %
%   Note: The polarity of the navigation data bit stream has not been          %
%         checked against the synchronization pattern, so there could          %
%         be a polarity reversal required to match the sync pattern.           %
%                                                                              %
%==============================================================================%
%                       GPS Software Receiver in Matlab                        %
%     Copyright (c) 2003-2017 David S. De Lorenzo / 2018-2023 Trimble Inc.     %
%==============================================================================%

% Dimension the navigation data bit output vector
navDataBits = zeros(size(I_prompt));

% Estimate the navigation data bit value for the leading samples
idx = 1:(navStartBit-1);
navDataBits(idx) = (sum(I_prompt(idx)) > 0);

% Estimate the navigation data bit values for the body of the data
for chunkStart = navStartBit:msPerDataBit:(length(I_prompt)-msPerDataBit+1)
    idx = chunkStart + (1:msPerDataBit) - 1;
    navDataBits(idx) = (sum(I_prompt(idx)) > 0);
end

% Estimate the navigation data bit value for the trailing samples
idx = (chunkStart+msPerDataBit):length(I_prompt);
navDataBits(idx) = (sum(I_prompt(idx)) > 0);

% Change bit values from [1 or 0] to [+1 or -1]
%   Note:  this performs a conversion from logical to real/double.
%   This does not assure that the polarity of a +1/-1 is set
%   correctly - the polarity would be checked when comparing the
%   data bit sequence to the synchronization pattern.
navDataBits = 2*navDataBits - 1;

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