File Exchange

image thumbnail

ensemble kalman filter

version 1.9 (3.86 KB) by

This program uses the ensemble kalman filter to estimate a system's state.

22 Downloads

Updated

View License

The algorithm used in this code is referenced from the following:
S Gillijns et al "What Is the Ensemble Kalman Filter and How Well Does it Work?"
Proceedings of the 2006 American Control Conference, Minneapolis, Minnesota, USA, June 14-16, 2006, pp 4448-4453.

 

Comments and Ratings (12)

Shanqin Wang

’subs‘ does not work with version 2014a. var_vector should be defined as cell just like
var_vector = cell([p1,1]);
In the first loop,
var_vector{j}=sprintf('x%d',j);

Convert the result of subs to double, do like this,
x_tr=double(subs(f,var_vector,x_tr))+w.*randn(p1,1);

Add 'double' to all 'subs'.

Done.

Daniela

Got it. This works with version R2015a:
Rewriting the code for avoiding the usage of 'syms'. You have to delete the var_vector and rewrite all lines with 'subs' in it.
e.g.:
Change x_tr=subs(f,var_vector,x_tr)+w.*randn(p1,1);
To
x_tr=A*x_tr+B*u+w.*randn(p1,1);

Therefore you need the matrizes A and B and the vector u so that x_k+1=A*x_k+B*u. In the given example it's:
A=[1 0.1;0 1];
B=[0.005; 0.1];
u=[1];

The same with h. Splitting it up so that y=C*x. Here in this example with:
C=[1 0];

Thanks,
Daniela

Daniela

The code doesn't come to a solution with the example provided. After several hours it's still at iteration number 11. I have version R2015a and with the code fragment of Colette no error arises anymore. I also tried the original code with version R2011a, but I didn't get a solution either. Can someone suggest a solution?

how to ploting the graphic?

Hello,
when i running your program, there was an error like this (please help me to solve the error):
??? Maximum recursion limit of 500 reached. Use
set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space
can
crash MATLAB and/or your computer.

Error in ==> sym.sym>varname2ref

chau aplei

Colette

Colette

Hello,

Thank you for your work on this file. It has been helpful to me as I begin learning Kalman Filter.

I am having a few issues with the code and was wondering if anyone else was too. Matlab is not my primary software, so I am wondering if it might be something simple (perhaps I need additional toolboxes). When I try to run the example, I get the following errors:
 
Error using sym/subs>normalize (line 206)
Entries in OLD must be scalar.

Error in sym/subs>mupadsubs (line 136)
[X2,Y2,symX,symY] = normalize(X,Y); %#ok

Error in sym/subs (line 124)
    G = mupadsubs(F,X,Y);

Error in ensemblekfilter3 (line 63)
   x_true=subs(f,var_vector,x_true)+w.*randn(p1,1); %compute true value of state at next
   time step

It seems I have found a solution by changing the loop to be:
for j=1:p1 %create vector containing variables x1 to xn
  eval(sprintf(' syms x%d', j));
  temp = sprintf('x%d ',j);
  var_vector = [var_vector; sym(temp)];
  %var_vector=[var_vector sprintf('x%d ',j)];
  end
%var_vector=strcat('[',var_vector);
%var_vector=strcat(var_vector,']');

If anyone else has experienced similar errors or has further insight into mine, it would be appreciated.

Thanks,
Colette

Abel Galois

Thanks a lot!

dwight nwaigwe

Hi Albert, thanks for catching that serious typo. I just corrected it and uploaded the new version.

Thank you for your work, i have found a mistake in your recent version. In line 71, yforbar=mean(ybar,2), i think it should be yforbar=mean(yfor,2).

albert chiang

have a look at!

Updates

1.9

Renamed variables and reorganized code for clarity. The original version is the .m file and the modified one is the .txt file. I haven't tested the .txt file but it should work.

1.8

whoops, i meant to say i deleted "num_members" = 20 from comments since it implied you must supply a variable with that name.

1.7

Cosmetic changes: consolidated comments, removed the comment num_iterations = 20 as it wasn't necessary, and i added spaces and indents. i did these edits in notepad. i still have the original file in zipped folder to be safe

1.4

Corrected line 71 as Albert Chiang mentioned.

It should be y_forbar=mean(y_for,2);
not y_forbar=mean(y_bar,2);

1.3

in the first few lines of the comments, I changed y+1 to y_new and x+1 to x_new

1.2

made minor adjustments to file such as inserting comments

1.1

changed description

MATLAB Release
MATLAB 7.7 (R2008b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video