Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Kalman Filters


  • Please log in to reply
7 replies to this topic

#1 entens

entens

    Member

  • Members
  • PipPip
  • 10 posts

Posted 24 November 2010 - 07:12 AM

I mostly use C# for desktop style applications, but lately I'm in need of an embedded controller. The inputs I'm working with tend to contain a fair amount of noise, so I'll need to develop some sort of smoothing algorithm. Normally I would just use a Kalman filter, but I'm doubting the performance I'll be able to harness from an embedded environment for realtime operation. Has anybody implemented a Kalman filter on the Netduino that runs with good performance? Is there anything you had to optimize to squeeze performance out of the filter (i.e. fixed point arithmetic)? What have you found works the best?

#2 Shaw

Shaw

    Member

  • Members
  • PipPip
  • 14 posts

Posted 24 November 2010 - 09:11 AM

I was just looking at porting some Kalman filters from C over to C# to run on the Netduino - however some of the System.Math functions are not available in .NETMF so it's going to take a bit of work. It might be worth implementing them in native code?

#3 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 01 April 2011 - 01:56 AM

Has anybody implemented a Kalman filter on the Netduino that runs with good performance?

Planning to ... but just started !

Mike.
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#4 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 01 April 2011 - 03:47 AM

If you mean a sort of signal processing, then forget the C#. I have tried but it is absolutely unpredictable as timing, and terribly slow. Anyway, it seems that working with floats instead of ints, is performing almost the same. That is the only good info. I am trying to move some step in C/C++ to implement some library for real-time processing. I guess it will take a long time. Cheers
Biggest fault of Netduino? It runs by electricity.

#5 Fred

Fred

    Advanced Member

  • Members
  • PipPipPip
  • 302 posts
  • LocationUK

Posted 01 April 2011 - 08:07 AM

I was just looking at porting some Kalman filters from C over to C# to run on the Netduino - however some of the System.Math functions are not available in .NETMF so it's going to take a bit of work. It might be worth implementing them in native code?

There's a good supplementary maths library here.

#6 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 01 April 2011 - 08:34 AM

There's a good supplementary maths library here.

The effort is really appreciable, but it is not enough.
Doing math in a managed way it results a very poor performance. I am fighting against a FFT and it takes almost 100ms to get the result (*VERY* simplified and with tons of hardness).

Another point over that particular library is to the square-root function I need to compute the modulus of a complex number. That algorithm is *really* slow.
Take a peek my article, if you interested in...
http://highfieldtale...he-square-root/

I'd expect to make simple calculations within microsecs, not millisecs.

Cheers
Biggest fault of Netduino? It runs by electricity.

#7 dbay

dbay

    New Member

  • Members
  • Pip
  • 2 posts
  • LocationDenmark

Posted 02 April 2011 - 09:30 PM

I am normaly working on automation project where I sometimes are using an algorithm from "Principles and Practices of Automatic Process Control" by Smith & Corripio. Perhaps some of you can use this quite simple aproach. I have only tried i out here in my workshop and i don't know if it will work in real life. But for me it seems to work fine. here is the Class: using System; using Microsoft.SPOT; /******************************************************************************** * Digital filter for noisy analogue signals. This equation is a standard * exponential filter taken from "Principles and Practices of Automatic Process * Control" by Smith & Corripio * * Equation: FltrPv = alpha * OldFltrPv + (1 - alpha) * RawPv * * where: * alpha = (tau / (tau + st)) * tau = time in sec for output to reach 63% of RawPv (Damping_time) * st = scantime, also update rate of equation * RawPv = variable to be filtered * FltrPv = filter variable * OldFltrPv = FltrPv (st - 1) ********************************************************************************/ namespace Netduino_PT100 { class Filter { const Int64 ticks_per_msec = System.TimeSpan.TicksPerMillisecond; float tau; float oldFltrPv; DateTime oldScantime = DateTime.Now; public Filter(float Tau = 10.0F) { tau = Tau; } public float Tick(float RawPv) { float st = (DateTime.Now.Subtract(oldScantime).Ticks / ticks_per_msec) * 0.001F; oldScantime = DateTime.Now; float alpha = (tau / (tau + st)); oldFltrPv = alpha * oldFltrPv + (1 - alpha) * RawPv; return oldFltrPv; } public void Set_tau(float Tau) { tau = Tau; } } } and here is the main program: using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace Netduino_PT100 { public class Program { public static void Main() { AnalogInput ain_1 = new AnalogInput(Pins.GPIO_PIN_A0); ain_1.SetRange(-40, 1040); Filter ain_1_filter = new Filter(); while (true) { Thread.Sleep(200); Debug.Print("Temperatur Filter:" + ain_1_filter.Tick(ain_1.Read() * 0.1F).ToString("N2")); Debug.Print("Temperatur Raw :" + (ain_1.Read() * 0.1F).ToString("N2")); } } } } /dennis

#8 terrorgen

terrorgen

    Member

  • Members
  • PipPip
  • 12 posts

Posted 03 April 2011 - 02:33 PM

better not use NETMF for signal processing or anything that involves heavy math iteration. It's just too slow.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.