Using Kalman Filter to estimate the time-varying parameters

5 views (last 30 days)
Hi Matlab friends,
I wondered if it is even possible to use Kalman filter to estimate the parameter which varies in time. I tried to follow the equations, but still did not achieve a good fit. I produced a sample curves like:
%--------------------------------
figure;
ti=(1:0.25:36)/12; ome=2*pi;
y=cos(ome*ti)+sin(ome*ti); % true signal
yn=cos(ome*ti)+sin(ome*ti)+randn(1,length(ti)); % signal + noise
plot(ti,yn,'g'); hold on; plot(ti,y,'b');
%-----------------------------------
and would love to do the fit to get back the sinusoidal (blue line by) using a Kalman filter. What I did is:
%-----------------------------------
x_t=[1;1]; % initial value
A=[cos(ome) 0;0 sin(ome)]; % design matrix of states
Ex=eye(2); % state error
E_t=Ex; % predicted error
Ez=(1e3)^2; % observation error
z_t=yn; % observation
C=[1 1]; % design matrix of observation
for t = 1:length(ti)
x_t = A * x_t;
E_t = A * E_t * A' + Ex;
K_t=E_t * C' /(C * E_t * C' + Ez); % Kalman gain
x_t = x_t + K_t *(z_t(t) - C*x_t); % Update state
E_t = (eye(2) - K_t * C)*E_t; % Update covariance
% Store parameter
xHat_t1(t)=x_t(1);
xHat_t2(t)=x_t(2);
end
y2=xHat_t1.*cos(ome*ti)+xHat_t2.*sin(ome*ti); % construct the fit
plot(ti,y2,'r')
%-----------------------------------
The red fit does not really give me back the original (blue). Any Kalman filter expert please help. Any suggestion would be really helpful here.
  1 Comment
John Petersen
John Petersen on 28 Jul 2014
What are you trying to estimate? Are you trying to estimate the coefficients of the two signals in y? I think your A matrix is wrong. It is constant and probably should be changing with t. Also your covariance values are very large. Probably should choose something smaller.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!