discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] curve fitting data points


From: mike revnell
Subject: Re: [Discuss-gnuradio] curve fitting data points
Date: Sat, 24 Dec 2005 15:58:30 -0700
User-agent: Mozilla Thunderbird 1.0 (X11/20041206)

I had a go at fitting a quadratic using the Scilab leastsq function.
I ended up with the following:

  y = -3.6330888 + 0.3255432 * x + 0.0781971 * x^2

for whatever units the xdata and ydata arrays were in another message
with the python code that seems to be doing much the same.

The following scilab code computes the coefficients and plots the original and fitted function on the same plot. The fit misses a bit because the last pair of
points seems to falling off quite a bit.

--------------------------------------------------------------------------
xdata = [5.357, 5.457, 5.797, 5.936, 6.161, 6.697, 6.731, 6.775, 8.442, 9.769, 9.861]; ydata = [0.376, 0.489, 0.874, 1.049, 1.327, 2.054, 2.077, 2.138, 4.744, 7.068, 7.104];
xm=xdata';
ym=ydata';
m=max(size(xdata))
wm=ones(m,1);

x0=[1;1;1];

function y = func( p, x )
 y = p(1) + p(2) * x + p(3) * x^2
endfunction

function e = errfunc( p, xm, ym, wm )
 e = wm .* ( func( p, xm ) - ym )
endfunction

[f,xopt,gropt]=leastsq(list(errfunc,xm,ym,wm),x0)

plot( xdata, ydata )
x=(5:.5:10)
plot(x,func(xopt,x))

-----------------------------------------------------------------------------------------------------------

cswiger wrote:

This is for the mathematicians out there - what is a simple
working algorithm for creating a function model to fit an
arbitrary number of data points. What I have for a first
approximation, simple linear (y=mx+b) actually works better
than nothing, but there's room for improvement.

I set one frequency input X1=3.9e6 and an arbitrary antenna control
output Y1=1800 and adjust the physical antenna for peak signal.
Then I change the frequency to X2=4e6 and adjust the antenna
output for peak signal, which happens to be Y2=1580. From there
you can get the slope m=(Y2-Y1)/(X2-X1) and the y intercept
b  = Y1 - m * X1.   After that calibration the antenna tune
output is m * freq + b, works fine.   Change the frequency and
the antenna peak tracks ok, especially near the two calibration
points, but going very far out or if the points are too far
apart noticible error creeps in.

What is a method similar to that for 3 points? or n p  x
 p
oints?
I want to collect (x1, y1), (x2, y2), (x3, y3)  then use
a simple python formula to get a workable y for any given x.

Thanks

--Chuck



_______________________________________________
Discuss-gnuradio mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio






reply via email to

[Prev in Thread] Current Thread [Next in Thread]