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: Chuck Swiger
Subject: Re: [Discuss-gnuradio] curve fitting data points
Date: Fri, 23 Dec 2005 13:36:45 -0500

At 07:06 AM 12/23/2005 -0500, Robert McGwier  wrote:

If we know already, a priori, that the data is from a "smooth function",


The phsical device has a smooth transfer curve ( MVAM109 capacitance / voltage ) and
resonant frequency is a linear function of capitance ( f = 1 / ( 2 * pi * L * C  ) ) but the
DATA is human generated: set freq, peak antenna cap, then click a button. So if all else
fails we can blame it on operator error ;)

that means (moving from left to right say), the extended line or the extended parabola from the last two or last three points respectively is always a very good predictor of the next point, then I would suggest some form of interpolation. 

Just thought while going to sleep last night, piecemeal linear or collecting several data
points and doing linear interpolation betwen them should work fine.
For (x1, y1)  (x2, y2) (x3, y3) where x1 < x2 < x3 I can get slope m1 and y-intercept b1
between x1-x2, and slope m2 and y-intercept b2 between x2-x3. Then if freq is between
x1-x2 use m1 and b1, if between x2-x3 use m2 and b2, etc.
The operator just has to make sure data points are close enough together.

You can get very bad behavior from least squares polynomial fitting.   If the data is very noisy, then it will not meet the smoothness assumption and some kind of least squares polynomial fitting will be better than interpolation so long as the underlying signal is well matched to the polynomial degree.  If it is a signal with very poor signal to noise ratio (for example), these fitting algorithms are very problematic. Then we need to talk about understanding the dynamics that produce the underlying signal so that we can have a predictor that we can "correct" with the noisy observations. This is like Kalman Filtering/Smoothing.   If the underlying dynamics is very nonlinear, or not well approximated locally by lines, as well as the observation of the signal, then welcome to nonlinear filtering and the theory of infinite dimensional functions spaces of the Hilbert type and stochastic driven parabolic partial differential equations.   I needed 4.5 years to get a Ph.D. to understand the latter and that was the first time I could write down a real phase locked loop with nonlinear observation (sinusoidal phase detector) and understand the mechanics. JUST SAY NO.   Doing all of these kinds of approximations, predictors, etc. in the real world, DSP type, control type, etc.  is an art form in many cases based on some science or assumed knowledge.  Chuck's question is too wide without further specifics to give it a one answer fits all.

No we don't need to talk about that.  I'll try the above piecemeal linear and also a python library scipy, which has
a least squares function and this example:


import scipy.linalg.basic

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]
matrix = []

for x in xdata:
    matrix.append([1.0, x, x*x]) # for y = a + bx + cx^2

coeffs = scipy.linalg.basic.lstsq(matrix, ydata)[0]

print "scipy.linalg.basic.lstsq curve fitting example"
print "fitting data to quadratic equation y = a + bx + cx^2"

print "yields:  x data     y
data    calc value   error"
for i in range(len(xdata)):
    ycalc = coeffs[0] + coeffs[1] * xdata[i] + coeffs[2] *
xdata[i] * xdata[i]
    error = ycalc - ydata[i]
    print
"         %
.3f    % .3f      %
.3f    % .3f" % (xdata[i], ydata[i], ycalc, error)
print



reply via email to

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