Exponential curve fitting on the Teensy3.6

Greetings. I am using a teensy 3.6 to collect data from a sensor. The resulting data then needs to be processed via a curve fitting routine (The overall trend of the data is an exponential curve). Although, I could export the data to my computer and then apply a curve fitting routine, it would be highly beneficial to do this on the teensy board itself. I am looking for an Arduino library that would be useful for this task. It does not seem like one exists and this is not surprising given the memory intensive nature of curve fitting algorithms. However, I am wondering if the larger amount of memory and processing power available on a teensy 3.6 may allow for a curve fitting routine to work. Libraries to do this type of curve fitting analysis do exist for C and C++ languages and I am wondering if there is a way to modify one of the libraries for use within the Arduino environment. Any and all other suggestions on how to solve this problem are most welcome. Thanks in advance for your help!


Kenneth D. Hoadley

Without seeing the libraries how do you expect any one to be able to answer your question?


Curve fitting algorithms need not be memory intensive -- just don't store the individual data points.

For an exponential fit, one approach is to fit log(y) versus x to a straight line, using about 5 floating point memory locations.

This simple program does so, but completely unnecessarily stores the data points (which are used only once).

Hello Shannon,

Thanks for the reply. I saw that one and had tried to use it with no luck. However, I think that may have had more to do with my ability to translate it into the Arduino language. Ill give it another crack. Thanks!

Hello Paul,

I found this library for C which seems to be what I am after. However, it seems rather complex and Im not sure how easily it can be converted for use in the arduino. In general, can libraries from C or C++ be utilized or is it a fairly complex task to convert?


Kenneth D. Hoadley

Arduino is C++ so code compatibility should not be an issue. The issue is that microcontrollers tend to be memory constrained so RAM intensive algorithm implementations may not fit. Also floating point operations, transcendental functions, and such are relatively slow on 8 bit microcontrollers.* Either may or may not be an issue for your particular application.

    • edit: In review I overlooked that you are using a Teensy3.6 which does have hardware floating point and is a 32 bit microcontroller. It also has quite a bit of memory by microcontroller standards.

I think that may have had more to do with my ability to translate it into the Arduino language.

Post the code for your attempt, using code tags, so that forum members can help you fix it. It would help if you post some examples of the data, too.