> Hello,
>
> We are seeking a "light" algorithm performing exponential
> function (y=A*exp(-k*x)) fitting. A typical curve is
> composed of 200 16-bits integers. As the code should be
> executed by a MCU, fixed-point is preferable but if
> floating-point is required for accuracy reasons, it
> could also be implemented if the amount of calculation is
> compatible with a reasonable processing time (few hundreds
> ms).
>
> Did someone already implement such an algorithm or could
> provide us with references? Of course, a piece of C code
> would be ideal.
>
Taking the logarithm of y(x) yields
ln(y) = ln(A) - k*x
from where you can apply e.g. a least-squares approximation:
y = a*x + b
# the mean values
x_mean = sum(x) / n
y_mean = sum(y) / n
# the variances
sx^2 = (sum(x*x)-(sum(x)^2)/n)/(n-1)
sy^2 = (sum(y*y)-(sum(y)^2)/n)/(n-1)
sxy = (sum(x*y)-n*x_mean*y_mean)/(n-1)
# the coefficients
a = sxy/sx^2
b = y_mean - a * x_mean
# the correlation coeffiecient
# +1 positive correlation (x++ => y++)
# -1 negative correlation (x++ => y--)
# 0 no correlation
rxy^2 = sxy / (sx * sy)
I hope I got the formulas right.
Don't know whether there is something faster than that.
Best regards to my old alma mater.
I still have fond memories of my days there ...
Martin
Reply by Eric Meurville●July 20, 20052005-07-20
Hello,
We are seeking a "light" algorithm performing exponential function
(y=A*exp(-k*x)) fitting. A typical curve is composed of 200 16-bits
integers. As the code should be executed by a MCU, fixed-point is
preferable but if floating-point is required for accuracy reasons, it
could also be implemented if the amount of calculation is compatible
with a reasonable processing time (few hundreds ms).
Did someone already implement such an algorithm or could provide us with
references? Of course, a piece of C code would be ideal.
Thanks and regards,
--
Eric Meurville