function y_ = fK( A,B,C,K,NoiseVariance,u,y,SensAtt,P_prior,X0 )

% solo i sensori scelti
y_r = y(SensAtt,:);
C_r = C(SensAtt,:);

% forward innovation -> rumori di modello e di misura scorrelati
R = NoiseVariance(SensAtt,SensAtt);
S = K*NoiseVariance(:,SensAtt);
Q = K*NoiseVariance*K' - S*inv(R)*S';
Q = (Q+Q')/2;
F = A-S*inv(R)*C_r;
SRi = S*inv(R);

% Spazio spazio spazio
x_post = zeros(length(A),size( u , 2 ));

% Condizioni iniziali
x_prior = X0;

I = eye(length(A));



%%

L = P_prior*C_r'*pinv( C_r*P_prior*C_r' + R );
P_prior = F * (I - L*C_r) *P_prior * F' + Q;
x_post(:,1) = x_prior + L * ( y_r(:,1) - C_r*x_prior );
x_prior = F*x_post(:,1) + SRi*y_r(:,1) + B*u(:,1);

% Compute estimate
for j = 2:size( u , 2 )
    L = P_prior*C_r'*pinv( C_r*P_prior*C_r' + R );
    P_prior = F * (I - L*C_r) *P_prior * F' + Q;
    x_post(:,j) = x_prior + L * ( y_r(:,j) - C_r*x_prior );
    x_prior = F*x_post(:,j) + SRi*y_r(:,j) + B*u(:,j);
end

y_ = C * x_post;
