%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function [Ni,Ratio,Nstatus]=estimate_fixed_ambiguities(Nf,P)
%
% Attempts to calculate integer ambiguities given
% floating ambiguities and their covarance matrix.
%
% [Ni,Ratio,Nstatus]=get_fixed_ambiguities(Nf,P) requires inputs of floating point
% ambiguities (Nf) and their covariances (P).  The function outputs Nstatus
% as a 0 or 1 to indicate whether or not valide integer ambiguities were most 
% likely obtained.  The function also returns the Ratio between best and
% second best set of integers to be used in a ratio test threshold.  The
% basis of the the quatly of integers is calculated based on the difference 
% in Nf and Ni (e_N) times the uncertainty in the integer uncertainty 
% (e_N'*inv(Q_hat)*e_N)

% An Nstatus=0 indicates a fail.  If the failure is due to the covariance matrix (P) symmetry
% being below a treashold then the returned ambiguities (Ni) are the same as
% the floating ambiguities (Ni=Nf).  If the failuer is due to the ratio
% test, then best estimate of Ni is returned, but a user should be cautious
% in accpeting the Ni as valid.

% If the ambiguities were obtained, with a Ratio between 1.5 and 5.0, 
% Nstatus is set to 1 and Ni reflects a good estimate of the integers.

% This function is a compilation of the Lamda Functions from Delft
% University of Technology (DUT) and includes:
%    lamda2
%    decorrel
%    chistart
%    ldldecom
%    lsearch
%
% The code was compiled for Auburn Universities MECH 5970/6970
% Fundampentals of GPS course.

% The function compares the best and second best set of integers in a
% "ratio test" to provide confidence if the integers are valid.
%
% The code can be requested from the following site:
% https://www.tudelft.nl/en/ceg/about-faculty/departments/geoscience-remote-sensing/research/lambda/lambda
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
