# Programming Kalman Filter with Nengo

Hello everybody,

has anybody of you already programmed a Kalman filter with Nengo?

With best regards
New_Ubuntu_User

Hi there! This publication discusses the implementation of a Kalman filter with Nengo. I don’t think that the code is available anywhere, but translating the equations in the paper to a Nengo network should be similar to what is done in the dynamics examples. Take a look at those examples and let us know if you have any questions about them.

I asked the same question in this post. @tbekolay should I close this post as a duplicate?

Please no!
The more people are asking about a Kalman Filter programmed in Nengo the higher are the chances that this programme will get published one day.

Thank you!
I will contact the authors of this paper.

Hi Trevor,
thank you for the links.
I have read the paper and according to it, I have got a question.
I do understand how the Kalman Filter works and I could implement it on Python.
What I do not understand is why I need neurons or populations for implementing a Kalman Filter in Nengo.
In my Python code, I would not need to simulate any neurons.
So why do I need them when working with Nengo?
Sorry, if this question sounds stupid.

Best,
New_Nengo_User

The point of Nengo is to build spiking neural networks that approximate dynamic functions. In this case, the dynamic function you would be approximating would be the Kalman Filter. Simulating functions in neurons can have a number of advantages. Are you asking what these advantages are or are you trying to understand how to do this with Nengo?

Hi, if you can implement a Kalman filter without Nengo and have no need for simulating neurons, then there’s no need for you to use Nengo.

If you want to integrate that Kalman filter implementation with a Nengo network, you can use a normal `Node` (potentially with a `Process` for advanced use cases) to expose your Kalman filter implementation to Nengo.

If you want to compare your Klaman filter implementation with and without neurons, you can set it up with an ensemble and use the `nengo.Direct` neuron type to simulate the Kalman filter without neurons.

But yeah, we’re not forcing you to use Nengo if you don’t need Nengo. Use whatever tools make the most sense for your use case!

Thank you for your answer!
There are for sure a lot of good reasons why to use Nengo. Otherwise it wouldn’t be so popular.
What I would like to do, is to understand how to program a Kalman filter with Nengo.

@brent has some preliminary code for programming a Kalman Filter in Nengo. However:

1. The code is horrible, because he wrote it before he knew how to Nengo
2. It only works with neurons in Direct Mode

Consequently, to understand this code and program your own Kalman Filter, you’ll have to understand:

1. The difference between neuron types in Nengo
2. How recurrent connections create dynamics in the NEF
3. How to capture the dynamics of a Kalman Filter using the NEF, which is covered in section 9.4 of the book “Neural Engineering”

Thank you for your answer. I think I will start coding the Kalman filter at first in python and then convert the code into Nengo. Hopefully, that will work out.

I have programmed a Kalman filter for different examples at university. So far, the physical law behind these systems were obvious or given.

But here, I do not know how the state transition model \$F_k\$ nor the control-input model \$B_k\$ looks like, when the vector \$x_k\$ consists of a predicted EMG value, the position of the arm in a 2D Cartesian coordinate system as well as the corresponding velocities.

\$x_k = F_k x_{k-1} + B_k u_k + w_k\$

Can someone please tell me how the matrices \$F_k\$ and \$B_k\$ are filled up in my case?
I have also tried to google for an equivalent example or explanation, but unfortunately, I could not find a sufficient one…

1 Like

I’m not sure what you mean by “EMG” here, nor the scenario you’re trying to apply this Kalman Filter to. Would you mind clarifying?