Guy and Seth on Simulink

December 21st, 2010

Kalman Filter – From MATLAB to Embedded C Code

Blogger, Guy RouleauBy Guy Rouleau

In a previous post, I introduced the Embedded MATLAB Function block. This block gives the possibility to write an algorithm in MATLAB code, include it in a Simulink model, and generate embedded C code using Real-Time Workshop.

When seeing this, some users, especially from the signal processing and communication domain asked: Do I really need Simulink to generate embedded C code from a MATLAB function?

To answer this question, I would like to highlight a webinar and a submission on the MATLAB Central File Exchange from my colleague Houman Zarrinkoub:

Webinar: MATLAB to C Code Generation with Embedded MATLAB

File Exchange Submission: Kalman filtering demo in MATLAB with automatic MATLAB-to-C code generation

Using Embedded MATLAB, you can generate C-code and test your algorithm on the real hardware with only a few clicks. It significantly reduces the turnaround time of design iterations.

Design process using Embedded MATLAB

For the Kalman filter in Houman's submission, the equations are implemented in MATLAB as you would see them in a book:

Kalman filter equations

Then using emlc, the algorithm is converted to C code. For example, the last line of the above code is turned into:

Kalman filter implemented in C

So now I recommend that you get yourself a drink, sit down and watch Houman's webinar!

Now it's your turn

Are you already using Embedded MATLAB to convert your MATLAB code into C-code? Leave a comment here

7 Responses to “Kalman Filter – From MATLAB to Embedded C Code”

  1. HuangHui replied on :

    i am new to matlab, i find that the recoreded webinar in your web is very useful. iwant to know how can i download them.

  2. DRIF replied on :

    Good Job !

  3. Anas replied on :

    Hi, Guys.. I’m indonesian student,, I looking for Ensemble Kalman Filter Program.. Any one help me!

  4. Mike replied on :

    1) you should improve blog so I can thumbs-up others comments instead of saying again (I have not done this before, it looks interesting. good job!). :)

    2) being able to perform the same work demonstrated in the webinar using CUDA would be interesting. The makers of “Jacket” like to show (using poor benchmarking) that CUDA is 100x faster than CPU. Typical (published) realistic improvements are 6x to 16x faster.

    3) I would love to learn more about optimizing high-level code for embedded devices.

  5. Emmanuel replied on :

    Hi, I really need help urgently, I made the image processing with matlab, and would now like to implement in some fpga or dsp by HDL or C code

    hope I can help, congratulations and I hope your answer, THANKS!

  6. mesut replied on :

    hi teacher ,how are you? I hope you are fine.I am a physics engineering student. I want to ask a question.how can I do measurement of gravity with simple pendulum in matlab programme? thank you:)))

  7. kutty replied on :

    Can u explain the steps that involved in converting the .m file to .c file?

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks
Guy Rouleau and Seth Popinchalk are Application Engineers for MathWorks. They write here about Simulink and other MathWorks tools used in Model-Based Design.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.