function tmpvar=condx_cov(tmpvar,bias,min_std)
% Conditioning for covariance estimate
% same as condx_chol for ichol=0 ??? Not sure
%
% input tmpvar is raw covariance estimate
dim=size(tmpvar,1);
if(length(min_std) ~= dim),
    error('min_std wrong size');
end;
    switch(bias),
        case 0, % CONSTRAINT method
            if(0),
                [V,S,utmp]=svd(tmpvar);
                S = diag(S);
                S=sqrt(abs(S));
            else,
                [V,S]=eig(tmpvar);
                S = diag(S);
                S=sqrt(abs(S));
            end;

            % best to ignore eigenvectors with zero eigenvalue

            % constrains on the variances
            % first determine eigen decomp of C=R' * R = V * S^2 * V'
            S = max(S,sqrt(diag( V' * diag(min_std.^2) * V )));
            tmpvar = V * diag(S).^2 * V';
        case 1, % BIAS
            for i=1:dim;
                tmpvar(i,i)= tmpvar(i,i)+min_std(i).^2;
            end;
    end;
return