function [NF,EF,Pij,Pa,Pb] = MRFilterfun(NF,EF,deltaz,Pij,Rij,Hi,Hj,Pj)
KF=0;
        P1=Pij; 
        P2= Rij +Hj*Pj*Hj';
        
        x1=NF;
        x2=EF;
        Pa=P1;
        Pb=P2;
        
 if KF==1,       
       
        K=Pij*Hi'*inv(Hi*Pij*Hi'+Rij +Hj*Pj*Hj'); %Eq. 2.51,52 for R1x inclusion
        Pij=(eye(2)-K*Hi)*Pij;
        deltax=K*deltaz;
        x1=x1+deltax(1);
        x2=x2+deltax(2);
        NF=x1;
        EF=x2;
        
 else       
        

        w= wopt( Pij,Hi,Hj,Pj,Rij );    % note Pj=R1x or R2x??
        P1=(1/w)*Pij;
        P2=(1/(1-w))*Hj*Pj*Hj'+Rij;    %split CI   
        
        K=P1*Hi'*inv(Hi*P1*Hi'+ P2); %Eq. 2.51,52 for R1x inclusion 
        Pij=(eye(2)-K*Hi)*P1;
                
        deltax=K*deltaz;
        x1=x1+deltax(1);
        x2=x2+deltax(2);
        NF=x1;
        EF=x2;

 end
        
end