03-08-2010 02:46 PM
i want to implement a kalman filter to my project but i'm not sure how to do it..
i have the code in c but i wasn't able to use it..
can anybody help..?
Thanks..
this is the code:
typedef struct {
double q; //process noise covariance
double r; //measurement noise covariance
double x; //value
double p; //estimation error covariance
double k; //kalman gain
} kalman_state;
initialization routine:
kalman_state kalman_init(double q, double r, double p, double intial_value)
{
kalman_state result;
result.q = q;
result.r = r;
result.p = p;
result.x = intial_value;
return result;
}
the main recursive routine:
void kalman_update(kalman_state* state, double measurement)
{
//prediction update
//omit x = x
state->p = state->p + state->q;
//measurement update
state->k = state->p / (state->p + state->r);
state->x = state->x + state->k * (measurement - state->x);
state->p = (1 - state->k) * state->p;
}
03-08-2010 03:53 PM
03-08-2010 04:54 PM
03-08-2010 08:35 PM
yes thats correct!
i tried to use the Code Interface Node but no luck..
although i found a solution by using the code with dll i have two issues..
the first is how to use the Code Interface Node (if i need it again.. )
the second is that if i use two vi's with the kalman filter(called from dll) the values are mixing together..
e.g the input from the first vi is affecting the output of the second vi, although they have no connection between them..
does the two vi's using the same memory?
how to make them behave as expected,i.e independent between them?
Nihil wrote:
hello karpa, i dint fully understand, so the question is how to implement C code in labview?
03-09-2010 01:03 AM - edited 03-09-2010 01:05 AM
karpa wrote:yes thats correct!
i tried to use the Code Interface Node but no luck..
although i found a solution by using the code with dll i have two issues..
the first is how to use the Code Interface Node (if i need it again.. )
the second is that if i use two vi's with the kalman filter(called from dll) the values are mixing together..
e.g the input from the first vi is affecting the output of the second vi, although they have no connection between them..
does the two vi's using the same memory?
how to make them behave as expected,i.e independent between them?
Nihil wrote:
hello karpa, i dint fully understand, so the question is how to implement C code in labview?
You are using a different state for each function?? The C code has no globals or statics inside so there is no influence between the two and LabVIEW definitely does not share data between VIs unless you use some specific means to share that data. So you must be doing something.
As to using code Interface Nodes: don't! They are legacy technology not anymore supported on all platforms that LabVIEW supports (namely 64 bit versions for now). The cross platform way of doing external code business nowadays is shared libraries/DLLs using the Call Library Node.
The code in question looks very simple to implement and there is really no reason to use an exernal code for it. To get a fairly good idea of what you might be wanting to do for this, take a look at vi.lib\Utility\MD5Checksum.llb\MD5Checksum string.vi. It's not the same but it should give some idea how to handle that. You can also combine all the state information into one cluster instead of wiring its elements around independantly.
03-12-2010 04:09 PM
the problem with dll is that it doesn't make the code very portable (only for windows..)
i'll try make it with labview functions though..
this is the code i use to test kalman_filter.vi
i don't know why they affect each other..
Waveform Chart and Waveform Chart 2 produce the same chart!! why.?!
rename kalman.dll.txt to kalman.dll..
03-12-2010 05:26 PM - edited 03-12-2010 05:28 PM
Sorry don't have LabVIEW 2009 installed to look at your code.
And to portability: The Call Library Node works on shared libraries too, or Macintosh frameworks. Simply whatever is the prefered way of implementing shared libraries on a particular platform.
If you want to really go about external code portability you should probably read these articles: http://expressionflow.com/author/rolfk/
03-12-2010 05:30 PM
03-12-2010 07:31 PM
03-13-2010 07:01 AM - edited 03-13-2010 07:06 AM
i still don't get it..
look at this images..
i think it have something to do with the dll calling..
the kalman is a recursive routine, the init is only happen once in the first running (using the feedback function) or update manually with the "update coefficients" control