ATxmega32A4U curve fitting library functions?

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am looking at using a AT xmega 32A4U.  Are there math libraries available for performing curve fitting specifically least squares?  Would rather not have to write from scratch. :)

Thanks in advance!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm sure such algo's are available in generic C (there's nothing hardware related about it when you think about it) so you should be able to find some C that can be cross-compiled for AVR. The big question will then be about its resource usage - is the code small enough to fit into small amounts of flash and is the RAM usage low enough that it can operate in the even smaller amounts of RAM that AVrs typically have.

 

But I guess my point is simply that your Google should be "C source curve fitting" not "AVR C source curve fitting".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you really want to be doing this on an AVR...?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Faster than the 8080s we used to do it with.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

numerical recipes in C

Keith Vasilakes

Firmware engineer

Minnesota

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks everyone for your replies. Basically I am reading in an op amp and trying to clean up the noise.  Is least squares the best way to do this on this processor?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

are you fitting a curve or just smoothing an analog value?

If you are fitting a curve a least squares polynomial fit is the best for accuraccy

If you have the horsepower and or time to do it

 

If you are just reading an analog value, using a low pass FIR or IIR filter is the best.

there are some very low overhead IIR filters out there that work very well

Keith Vasilakes

Firmware engineer

Minnesota

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the reply Keith.  I need to do both; clean up the analog signal then do a curve fit.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is a subject I am very interested in, modelling complicated things as polynomials is so nice, I can set the coefficients as macros and have very flexible systems where its possible to radically change analog hardware but just alter a few macro's in software!!! I use it to negate calibration and I don't think it could be anymore flexible

 

numerical recipes in C

Is a fantastic book, its a book that is in my top 5 of all time just for the knowledge in there, man if I knew a fraction of the recipes

 

I don't use an AVR to do the curve fitting though that sounds interesting

 

Edit

 

If you are fitting a curve a least squares polynomial fit is the best for accuraccy

Not that I have ever done it manually but I always thought Chebyshev approximation was the best in most departments and not the most demanding either

 

 

Last Edited: Fri. Dec 12, 2014 - 07:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My biggest problem is I used to do this on windows computers using doubles all over the place and tons of data.

trying to scale it down to an 8 bit device warps my mind.

 

I have a nice simple fixed point IIR filter I can point you to if your're interested.

 

FIR is just a running average, no magic there.

Keith Vasilakes

Firmware engineer

Minnesota

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But isn't the idea to use a PC to do the crunching and then at the end of the day you have a few coefficients depending on the order you model to, a lot can be modelled with a cubic equation so four coefficients

 

FIR is just a running average, no magic there.

And an IIR is simply an discretised RC circuit (low pass filter)

 

Still a lot of magic in both of them in my eyes =-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, my project currently has a PC UI that simply displays the graph of the data from my device via a usb port.  No curve fitting.  My task is to make the device hand held.  No graph is require (the device has a 3 line ASCII display). So as stated previously, clean up the analog signal then do a curve fit.  Maybe this will help:  The first attachment shows the theoretical or ideal image of the signal. The area of interest is in red.

 

 

The second figure is my actual data showing the noise (800Hz sample rate):

 

The idea is to clean up the noise before doing any curve fitting.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please do not cross post.

 

Moderator.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson... I apologize for the cross post but ultimately I have two different problems and questions. One regarding noise filtering and the other regarding curve fitting.