I used this code for perfoming kalman filtering for signal data. the measurment are random created.
this massege was appearing (Unable to perform assignment because the left and right sides have a
different number of elements.)
% %Initializations
Pk_prev = [0,0; 0,0];x_kprev_hat = [0 ; 0];xk_hat = [];% Time update equations
A= [0.5 , 0 ; 0 , 0.3];B = 0;% Measurement update equations
H = [ 1 , 0];z = rand(2,200);E_x=[1,0 ; 0,1]; %Simulating noisy measurements
E_s =[1,0 ; 0,1];E_y=1%Measurement model
z_k = H*(z + 1) + E_y;P = zeros(1,length(z));% Measurement noise
R =1;%R = 0.000001 for a very low value
% Process noise covariance
Q =[1, 0; 0, 1];for k = 1: length(z) x_k_hat_minus = A*x_kprev_hat+ E_x ; %a priori estimate
Pk_minus = A*Pk_prev * A'+ Q; %A priori estimate error covariance
Kk = Pk_minus/(Pk_minus + R);%Kalman gain
x_kprev_hat = x_k_hat_minus + Kk*(z_k(k) - x_k_hat_minus); %A priori estimate
xk_hat = cat(2,xk_hat,x_kprev_hat);%A posteriori estimate
Pk_prev = (1 - Kk)*Pk_minus;%A posterirori estimate error covariance
P(k) = Pk_prev;endplot(z_k,'bx-');hold on;plot(xk_hat,'gx-');plot(z*ones(1,200),'rx-');figure;plot(P,'r');E_y =1
Best Answer