A Kalman filter can do interesting things (like filtering poll results)

I recently learned about the Kalman filter and finally got to play around with it a little bit. Since I had a hard time figuring out how to get it to work, here’s a practical (but yet general) introduction with examples:

A Kalman filter works by matching a simulation model and measured data. For each data point, an estimation of the simulation model’s internal state is computed based on the estimate of the previous state. This works with noisy data and limited measurement signals (e.g. a model with 10 state variables but only 2 measurement signals, although there are obvious limitations here (the more and the better the sensor data, the better the results should be – there’s also some limit on observability).

So we have this interesting tool which does all these different things:

  • filtering noisy data, while taking knowledge (or assumptions) on the underlying dynamics into account
  • merge data from several different sensors into one signal (typical application: combine GPS and acceleration sensor data into one accurate position signal)
  • offer a prediction of a system’s future state
  • estimate internal parameters of a system (say a spring stiffness based on measured oscillations)

Another interesting use is that we might try two different simulation models on the same measurement and check which one does a better job at synchronizing to the measurement (I’ll do this in a very simple example below).

Continue reading

Advertisements

Impulse-based dynamics: A simple and fast way to simulate contacts and constraints

So far, I’ve mostly been working on rotational mechanics – multibody models where each mass only has one rotational degree of freedom and two state variables (angle and angular velocity). Every now and then, I use some commercially available tools to simulate more complex 2d and 3d models – often being surprised by how slow simulation is. At the same time, I’ve been wondering a lot:

  • how I’d actually model these problems by hand – especially when additional boundary conditions and/or contacts are involved.
  • why some video games seem to be able to include complex dynamics with detailed contact and collisions involved, simulating in real time (while commercial multibody simulation often takes hours to calculate a few seconds of dynamic behavior).

An important answer to these questions is the topic of impulse-based dynamics. I stumbled upon it in some amazing literature from Prof. Jan Bender (see http://www.interactive-graphics.de/) and so far I’ve been experimenting a bit with the method myself. This post today features a small and practical introduction to modelling boundary conditions in impulse-based mechanics.

Continue reading

Programming advice for an engineer: Get an Arduino

Until the beginning of this year, I’ve only been coding in Matlab, GNU Octave and a few other comparable high-level 4th generation programming languages. I’ve long wanted to learn a more basic programming language which allows smaller and faster programs (more on this in another post). Basically, I wanted an answer to the question:

I’m an engineer and want to learn about programming. What can I do to get started?

It turns out one of the best answers is this: Get an Arduino.

Continue reading

Getting started

This is an experiment that has been bugging me for quite a while.

Every now and then I run into some applied mechanics problem and try to figure out how to solve it. Usually after a few minutes of trying, I also decide to google it and often I find no solution to my question (but usually a lot of helpful hints and good advice).

These are usually quite basic questions I’m considering, like:

  • how can I implement coulomb friction in a 1d mechanics model with consideration of stick and slip states?
  • my multibody model is getting quite complex with lots of reused code. The code would probably look a lot cleaner and simpler if masses and couplings are implemented as objects. How can this be done?

Both example questions are actually quite simple problems which are probably solved many times. Searching for a good solution is fun for me and I usually learn a lot along the way. So this is the idea of this blog: to write about simple problems with multibody dynamics and suggest possible solutions to them – and then see what happens.

Continue reading