Dual Kalman Filter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Qiang1991
    New Member
    • Mar 2016
    • 2

    #1

    Dual Kalman Filter

    I want to estimate a variable x, and the observable variable y can be obtained from sensors. These two variables has an approximately linear relationship,i. e., y=k*x + b, but k and b are difficult to get, so I use two kalman filters, one for state (x) estimation, another for parameter (k,b) estimation, which actually combines the dual kalman filter. The general scheme and code in Python is as attached, and state estimation kalman filter functions, parameter estimation kalman filter functions are also attached.
    Code:
    ##Python code
    #initialize state estimator
    kf = KalmanFilter(dim_x=1,dim_z=1)
    kf.x = numpy.array([x0])              # initial state
    kf.F = numpy.array([1.])              # state transition matrix
    kf.Q = 1000                           # state noise variance,
    kf.R = 1                              # measurement noise variance
    
    #initialize parameter estimator
    dkf = KalmanFilter(dim_x=2,dim_z=1)
    dkf.x = numpy.array([[-0.01,-0.1]]).T # initial state 
    dkf.F = numpy.array([[1,0],
                        [0,1]])           # state transition matrix
    dkf.Q = numpy.array([[1,0],
                        [0,1]])
    dkf.R = 100                           # measurement noise variance
    
    measurements = []
    resultsDKF = []                                         #dual kalman filter state estimation result
    ERRDKF = []                                               #estimation error
    
    for i in xrange(N):   # N samples
        #### parameter estimator
        dkf.H = numpy.array([[kf.x,1]])   # measurement function
        y = Y[i]
        dkf.update(y,dkf.R,dkf.H)        
        dkf.predict()
    
        #### state estimator
        kf.H = numpy.array([dkf.x[0]])
        z = Y[i]-dkf.x[1] # Y[i]-b
        kf.update(z,kf.R,kf.H)    
        kf.predict()
    
        #### save data
        measurements.append(Y[i])
        resultsDKF.append (kf.x)
        ERRDKF.append(measurements[-1]-resultsDKF[-1])
    It seems that the predicted state varies with the true value, but there still is a big gap between predicted and true value, and if I set the initial state of x (that is x0 in the code) near the true initial value, the results are much better,as attached.

    I think the dual kalman filter doesn't really track true values of x, what's the problem? Anybody who offers advice will be much appreciated.
    Attached Files
  • Qiang1991
    New Member
    • Mar 2016
    • 2

    #2
    Is there anybody can help me figure out this problem? I personally think there is something wrong with details.

    Comment

    Working...