Curve fitting question - Page 1
Forum section: electronics / projects

author: Jester
author_rank: Frequent Contributor
timestamp: March 06, 2019, 12:34:03 pm
content: I'm working on the calibration aspect of a project and would like to correct for some non linearity by applying a correction factor.The uncorrected data and graph can be seen here (correction only at zero and full-scale):I tried plugging the data into an online 3rd order Polynomial Regression tool and it helps but is far from ideal. We covered curve fitting in school decades ago, I don't recall much at this stage, except that a polynomial fit is likely a poor choice, perhaps Cubic spline or some other fit method?Also can you suggest an online tool that will accept preferably 10-15 data pairs.Thanks

author: magic
author_rank: Super Contributor
timestamp: March 06, 2019, 12:41:56 pm
content: Quote from: Jester on March 06, 2019, 12:34:03 pmOctave/Matlab have polyfit, splinefit, etc.Polynomial may suffice and has the advantage of being trivial to implement in embedded firmware, but you will need a much higher degree than 3 for all that curvy waviness.

author: Siwastaja
author_rank: Super Contributor
timestamp: March 06, 2019, 01:37:48 pm
content: A strange curve. It may be difficult to fit a function. Of course youcan, but I would consider using a lookup table instead.Curve fitting works great when your error function is some easy, quick-to-calculate function with only one or two parameters - first order linear with offset and gain being the most typical example, and a second-order parabolic function often being the most complexity you want to deal with, especially in embedded. This tends to be the case when there is one dominant physical mechanism of error, over all other causes.Lookup tables are most flexible, if you can afford the space for storage. Piecewise linear interpolation is simple to implement if you can't fit the LUT in full resolution. The best thing is, the lookup table adapts automatically even if a particular unit behaves very differently for any reason. With curves, once you have selected which function to use, you are limited to what you can do by changing its input parameters (which you typically try to minimize) - this is harder to analyze.

author: golden_labels
author_rank: Super Contributor
timestamp: March 06, 2019, 01:54:47 pm
content: You are calculating a relative error for 0, which is already an indication of a problem. 0 can have only three relative error values, none useful for calculations: 0, -∞ and +∞.Using absolute error provides datapoints that reveal a nice curve with two separate, tiny subgroups on the sides. Therefore you can use a piecewise approach. First few values, having no error, have correction of +0. Then there is the huge blue part that fits logarithmic curve with R²≈0.93. Then there is the problem with the final values (red): there is not enough of them to actually calculate any curve. The two options, the 2nd and 3rd order polynomials, give some reasonable correction, but I feel like they are going to fail as soon as you collect more data in that region. The blue part gets a better fit (R²≥0.96, not shown on the chart) if the values are moved to the logarithmic scale and higher-order polynomial (≥4) is used, but I am also expecting this to be overfitting for that particular data set.But all the above make sense for that single, particular sample. If you need a general approach for your system, those fixed values will not work. While the middle, blue part seems like it may work with logarithmic curve for any sample, the green and the red ones will probably not fit the models I have chosen for them if you collect samples from a different specimen or under different conditions.Also, if you are implementing this in a microcontroller with limited resources, consider approximating the logarithmic curve with straight sections. Calculating logarithms is expensive.

author: SiliconWizard
author_rank: Super Contributor
timestamp: March 06, 2019, 03:13:04 pm
content: I suggest considering Lagrange polynomials:https://en.wikipedia.org/wiki/Lagrange_polynomial

author: Henrik_V
author_rank: Regular Contributor
timestamp: March 06, 2019, 03:20:12 pm
content: If you don't have a model of that error (resulting in a function with parameters to fit)the (in my eyes) only valid error compesation is a lookup table with linear interpolation inbetween.

author: golden_labels
author_rank: Super Contributor
timestamp: March 06, 2019, 04:08:55 pm
content: Quote from: SiliconWizard on March 06, 2019, 03:13:04 pmJester has only a small number of points and we also can’t tell if the variation is due to random effects or actual, fixed properties of the system. There is simply not enough data to make any conclusions about why values jump up and down; just look at all those waves interpolated at the original chart: there is nothing between inflection points and local extrema. And there is only one sample. The independent variable is not even spaced evenly¹, so all the hills and valleys may be merely effects of quite arbitrary choices.In that situation it makes no sense to use any detailed function — there is no data to support it. However, using Lagrange polynomials would provide exactly that: a very detailed function built on top of data that isn’t there. It would just cause overfiting. Perhaps statistical approach is like building castles on sand, but using anything that provides a perfect fit is like building castles on air.And if going for a perfect fit, I would rather use what Henrik_V suggested: LUT with linear interpolation. Much cheaper implementation, probably equally good/bad.--- editLagrange polynomials may work to some degree, if points are chosen wisely. But we do not know the actual model, so we can’t select those points. The data provided uses arbitrary locations.____¹ On either linear or logarithmic scale.

author: Conrad Hoffman
author_rank: Super Contributor
timestamp: March 06, 2019, 06:04:50 pm
content: Wealth of stuff here you might try-http://zunzun.com/

author: aldi
author_rank: Contributor
timestamp: March 06, 2019, 06:07:51 pm
content: The "function finder" on zunzun.com may be useful.

author: den
author_rank: Contributor
timestamp: March 06, 2019, 08:06:55 pm
content: Calibration is performed by measuring the same thing with another equipment, which is pore accurate, but still has an error. The curve should include these error bars.Anyway, I would never try to fit such a curve in this way, like with a cubic spline (which, by the way, you see in the graph - Excel uses it for smooth line option), because it just doesn't make sense. Just measure same thing on a different day and you will get a different curve.

author: Kasper
author_rank: Frequent Contributor
timestamp: March 07, 2019, 07:08:34 am
content: I would get more data before curve fitting. If possible / feasible, test at different temperautres, battery levels, or whatever might affect your errors. Also do some tests with Vin increasing and some with it decreasing, if possible.It's hard to imagine an error pattern looking like that every time. If it varies on other tests, look for a pattern, if you see one, make an equation or a look up table. If there is too much difference between each test, then clean up your test set or your unit under test.I'm sure there are better solutions but I've found excel works well for curve fitting. Sometimes I use the polynomials excel recommends and other times I make an equation and graph it then tune the equation until the graph matches the curve I'm trying to fit.

author: jbb
author_rank: Super Contributor
timestamp: March 07, 2019, 08:19:30 am
content: If it’s embedded, +1 for lookup table and piecewise linear interpolation.However, that curve is weird. Might I suggest you examine your equipment to check for unexpected conditions?Some colleagues of mine once had a hell of a time with a wonky rotary encoder. It produced very very strange output. Eventually they realised that the grub screw holding the encoder disk onto the shaft wasn’t done up.

author: voltsandjolts
author_rank: Unknown
timestamp: March 07, 2019, 08:29:21 am
content: Data looks strange, if it's not repeatable then it's not even worth trying to curve fit to it.

author: rs20
author_rank: Super Contributor
timestamp: March 07, 2019, 08:34:08 am
content: A Lagrange polynomial is aHORRIBLEidea in this context because the resulting polynomial will take a circuitous path to travel through every point precisely, no matter how ridiculous the resulting values between the given points are:The ONLY time to use Lagrange polynomials is if you absolutely must have a polynomial curve that goespreciselythrough all your points, and absolutely literallycouldn't care lesswhat the rest of the values are.In general I'd say linear interpolation is the best you're going to manage, except:Quote from: voltsandjolts on March 07, 2019, 08:29:21 am+1 to this. The recorded data wildly changes direction from one sample to the next. If the wild changes are due to noise, you shouldn't try to fit to the noise. If the wild changes are a real, actual signal, then you need to make more finely spaced measurements to establish the true shape of the curve (and avoidAliasing).

author: tggzzz
author_rank: Super Contributor
timestamp: March 07, 2019, 08:40:43 am
content: Quote from: Jester on March 06, 2019, 12:34:03 pmThe "right" curve to use can only be defined after you know thetheoryof how the measurement is expected to vary. In the absence of that understanding, plotting a curve is like a Rorschach testExamples:if you are plotting mortality against time, then you ought to have a bathtub curveif you are plotting noise, then you shouldn't use a curve, but should use mean and standard deviationif you are plotting a time series where there is an expected temperature dependence, then you should use the measured temperature as the curveif you are plotting a warm-up transient, perhaps an offset exponential curve is relevant

author: Henrik_V
author_rank: Regular Contributor
timestamp: March 07, 2019, 09:10:20 am
content: Overseen the relative part... so +1 for golden_labelsfitting:https://xkcd.com/2048/For a meaningful correction much more information is needed.Are different ranges involved? (Should have individual LUTs)Repeatability?Stability/Drift?Systematic errors (loaded voltage divider?)?

author: iMo
author_rank: Super Contributor
timestamp: March 07, 2019, 11:23:26 am
content: Quote from: Jester on March 06, 2019, 12:34:03 pmWhat are the Vdisp values at Vin=65 or 76 or 44? You do not know.It could be anything.You have to live with an error and you may fit with a polynomial such the resulting error will still be acceptable.

author: mjkuwp
author_rank: Unknown
timestamp: March 07, 2019, 12:15:20 pm
content: It will help if you can post actual data in a text file rather than an image.I suspect that the odd 'shape' of the curve is not real it is noise in the instrument and you would not want to try to calibrate this out. A 2nd or 3rd order curve may be enough.Do you have multiple samples of this data? Or, could you take 10 samples at each reference point, average these and use those as the inputs to the calibration.For something like this I would use either Python with numpy and matplotlib or EXCEL or even Google Sheets ( part of Google Docs)in Google Sheets you would use Charts to make a Scatter plot and then add a trendline to a series and select the option for the Label of that trendline to show the equation.

author: Jester
author_rank: Frequent Contributor
timestamp: March 07, 2019, 09:10:06 pm
content: Quote from: Conrad Hoffman on March 06, 2019, 06:04:50 pmThanks for the link, this in an excellent tool. I ended up breaking the data into a few ranges and then applying correction factor per range. Displayed error is now < +/- 0.1% from 0-250V, and that's good enough for this project. I still need to test over temperature range and will add an additional tweak factor to compensate if needed.

author: Jester
author_rank: Frequent Contributor
timestamp: March 07, 2019, 09:15:16 pm
content: Quote from: rs20 on March 07, 2019, 08:34:08 amGood point, and I observed what you described when I tried that approach.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: March 08, 2019, 01:15:28 am
content: You'll need a quite high polynomial to fit that lumpy mess.Also, is it actually lumpy, or is it truly noisy? Is this an ADC input transfer function, by any chance? Typically many-bits code crossings exhibit spikes, for which you could use a curve to minimize peak error, but not really get the bulk of it without just using a lookup table on the whole damn thing.A procedural function could produce blips around specific breakpoints, without costing too much execution time or data space, but may cost a fair amount of code itself.Most embedded platforms don't have div or float (many don't have mul either!), which makes anything but plain polynomial functions awkward.Rational functions can fit spiky data very well indeed for a given order, but require at least p+q multiplies and one division (for rationals of the form A / B, for polynomials A and B, of order p and q respectively), assuming you don't run into problems with numerical range and stability, or other optimization options, that may suggest another factorization (sums of terms p/q + r/s + ..).Tim

author: AlcidePiR2
author_rank: Regular Contributor
timestamp: March 08, 2019, 05:17:52 am
content: As with Lagrange interpolation, large degree polynomial is a very bad idea.The problem of this plot is that most probably a large component is noise. You dont want to interpolate precisely noise. On the contrary, you want to use the least degree possible, to make the correction robust.Without knowing better the setting, it is difficult to give precise advice, but I would dump the two extreme part of the curve, and conserve only the [10:28] data points, where there is an obvious trend.The just fit a line by quadratic regression.One get cor = -0.663145 + 0.001981 * VThe two attached plots are (V, error) and (V, error-cor).Then only you wonder if you want to add additionnal corrections for the extreme parts

author: AlcidePiR2
author_rank: Regular Contributor
timestamp: March 08, 2019, 05:46:55 am
content: Looking more closely to the data, I see the problem.The plotted error is the relative error. This is bad, as for very small values it is meaningless.One should plot the absolute errors.Then it appears that for large values, there was probably a reading problem on the scale. I would then discard these values.A quadratic fit is then very adequate (see the plot) . The plot is with the absolute error.The fit is F = - 0.005786 * V + 1.199683E-5 * V^2The last curve is ERR-F vs V.I believe that the 5 last points are bad measures.

author: Berni
author_rank: Super Contributor
timestamp: March 08, 2019, 07:06:25 am
content: I say don't bother with curve fitting and just use a lookup table with interpolation.Curve fitting works great when your graph is a smooth curve all the way (for example NTK temperature sensor corrections) as such a curve can be made into a polynomial with only 2 to 4 elements. While storing a precise lookup table would require something like 100 points. Speed of lookup is about the same on both, but the polynomial uses less memory. However when your curve is so erratic it would take a awfully long polynomial to aproximate it to a point where the two basically look the same. This ruins the advantage of polynomials as now you need to store a long list of elements in memory anyway while calculating the polynomials becomes significantly slower than a lookup table (And as you found curve fitting becomes hard at this point).The trick to having a lookup table work just as well is in interpolation. For a smooth and dense graph you can use simple linear interpolation between points that's fast to compute too. If the points are too far apart then a bit of extra math can be added to do cubic interpolation. This looks at the data points around the point of interest to make a smooth spline trough them. This is computationally a little more expensive (About 6 multiplies and 10 sums) but still very fast.Here is a nice page on interpolation:http://paulbourke.net/miscellaneous/interpolation/

author: AlcidePiR2
author_rank: Regular Contributor
timestamp: March 08, 2019, 07:56:19 am
content: Quote from: Berni on March 08, 2019, 07:06:25 amBerni, I dont agree with you. You need first to distinguish what part is due to the moise. You dont want to interpolate or use look out table for noise. It is pointless.In the given example. I bet the level of noise is about 0.1 %.

author: AlcidePiR2
author_rank: Regular Contributor
timestamp: March 08, 2019, 08:00:18 am
content: @Jester : You need to do at least an additional experiment with the full curve again. Even better a few.This will tell you the noise level in your experiment.

author: Berni
author_rank: Super Contributor
timestamp: March 08, 2019, 10:27:39 am
content: Curve fitting onto noisy data will also try to reproduce the noise the best it can. It has no way of knowing what is noise and what is signal. Just that usually by limiting the number of elements in the polynomial you smooth it out somewhat by limiting its ability on fine detail reproduction.If you want the same smoothing effect with a lookup table then you just run the whole thing trough a filter that smooths out the points. Basically like bluring on a image but on 1D instead. The end result is the same, just a different process to get the smoothing effect.Not saying polynomial curve fitting is bad, just saying that its much better suited to very smooth graphs. If the graph has only a 2nd order curve to it along its whole size and you have 100 points then yes a polynomial curve fit is an excellent way to clean it up as a low order polynomial will average out the noise due to its inability to take sharp turns and will be computationally nice for lookup due to being short. But the graph that the OP is showing is not a smooth graph at all and i assume he wants his curve fit to look similar to the interpolated curve that excel draws (And excel likely did it with cubic interpolation or similar for efficiency reasons)But if we are talking about the actual data, the graph in the original post does look like it should have more points in it. Some points have significant jumps so you probably want some extra points in there. As for noise, that's the OPs job to make sure his test setup makes a graph sufficiently accurate to begin with. No amount of math will magically remove noise, not even polynomials. You can just mask the noise a bit by smoothing. The proper way to 'remove noise' is taking many passes at the measurement and then averaging the results. That is provided your DUT doesn't drift between the test runs, but if it does drift then correcting it using calibration data won't work anyway.

author: Jester
author_rank: Frequent Contributor
timestamp: March 09, 2019, 02:56:07 pm
content: This is such a great forum from the sharing of expertise perspective. Big thanks to all of you.Noise was certainly a factor, as well as the relative error. I broke the curve up into a few segments and then remeasured the outliers and found that on average they were actually closer to the trend. The function finder in ZunZun is great in that it lets you see the error for a multitude of solutions, polynominal solutions were usually not great.Fortunately I'm using a 32bit uC, so some number crunching is not much of an impediment. I'm getting great corrected results now 0-250V ac and DC, will be moving on to current measurement later today. I'm using a LEM DCCT, and I'm anticipating a fair bit of drift, hopefully I can correct based on temperature in the box.

author: mrflibble
author_rank: Super Contributor
timestamp: March 11, 2019, 07:09:29 am
content: Did some linear regression for the error term, and the results look suspiciously much like an ADC non-linearity error function. Complete with excursion within 1 LSB and some semi-random walking of the residue. That residue will contain a good bit of noise, but I would not be at all surprised if there's some zig-zag-zag-ziggy-zaggy pattern in there at multiples of 16 or 32 or something similar.Below the result when using the data-points from 10 to 200, so excluding that big jump at 210. Not so much for numerical reasons but more to make it a bit easier to try and spot any potential periodicity in the residue.And here the full range is used, so including the fairly big jump at 210. The curve fit is still fairly similar to the previous one due to the use of l1-minimization. That is far less sensitive to outliers than ye olde l2-norm least squares.

author: mrflibble
author_rank: Super Contributor
timestamp: March 11, 2019, 07:49:19 am
content: Quote from: Jester on March 09, 2019, 02:56:07 pmIf you are serious about spending more time & effort on making a predictor for the error, then you might want to consider getting more data. Those few samples are okay for doing some quick checks, but IMO not near enough for getting a result with decent statistical significance. Also, if you have a max budget of measurement points due to time constraints or whatever, you are better of generating them at random intervals. As opposed to 0,10,20,30,etc... For the same number of samples the non-uniform intervals will typically give you more information for this kind of thing. And as a bonus feature, by using random instead of fixed intervals, certain systematic errors are less likely to occur. And at no extra cost to the user.

author: golden_labels
author_rank: Super Contributor
timestamp: March 11, 2019, 12:00:48 pm
content: Nice observation, mrflibble. I would not be surprised if 200V is the effect of n-and-a-half-digit DMMs having one of their voltage ranges ending at 199.9…V. Which brings us to a question I already wanted to ask earlier: what about the measurement errors? Perhaps what was achieved in that topic is producing a calibration curve for the multimeter itself?

author: rhb
author_rank: Super Contributor
timestamp: March 11, 2019, 01:19:51 pm
content: Try the curve fitting in gnuplot. The Marquardt-Levenberger solver in it is fantastic. I used that for all my professional work as a research scientist working for major and super major oil companies. It also gives you publication quality figures.i was able to do accurate fits to y=a*exp(b*x + c*x**2 + d*x**3) and higher order polynomial exponents. It takes a bit of practice to do that, but it's easier than you'd think. The key is to only solve for one term at a time until you've got a fit for all of them. Then do fits for more than one.It will blow up if you happen to choose the wrong combination of terms. But usually you can do a last solution for all the coefficients if you've gotten close enough. The higher the order, the closer you need to be. Gnuplot also has lots of other curve fitting algorithms available.

author: mrflibble
author_rank: Super Contributor
timestamp: March 13, 2019, 02:43:36 am
content: Quote from: golden_labels on March 11, 2019, 12:00:48 pmAgreed. That step at 200 Volt would suggest a ranging switch. If you check the graph then you can see that the zig-zag pattern is continuous ... except that at 200 V there is a different offset. So that step you see is the difference in offset of the two ranges used. Or at least, that would be my guess. And if this is indeed the case, it might be a good idea to redo the measurements with the DMM set to fixed range. That, and it would be interesting to see what influence temperature has on the result.QuoteYeah, incorporating the measurement uncertainty of the DMM into the calibration would make sense. That way you'd get some idea of how much confidence you can have in the end result of your calibration procedure. Mainly it depends on how much effort the OP would want to put into this.

author: mrflibble
author_rank: Super Contributor
timestamp: March 13, 2019, 03:30:12 am
content: Quote from: rhb on March 11, 2019, 01:19:51 pmDon't you think damped least squares is a tiny bit overkill for this?The data would suggest either linear or piecewise linear, depending on required fit. If you check the plots a few posts back, you can see that the residue plot has a distinct sawtooth shape to it. Which to me would suggest using a piecewise linear function as curve fit.Another reason for piecewise linear is that I'd guess that sawtooth shape is due to the hypothetical layout of the hypothetical ADC. To be fair, with this few datapoints this is a reasonably wild guess. At this point we're playing the"Guess my calibration procedure!"game, so could go either way.

author: rhb
author_rank: Super Contributor
timestamp: March 13, 2019, 11:30:35 pm
content: Learning to use the tool is what's important. It makes it very easy to examine the residual error of the fit.My preferred practice is to plot the data divided by the approximation. I started doing that when I was working on the equations of state of reservoir fluids. It's pretty much the standard way that thermodynamic properties are handled. It has the great virtue of making errors in your choice of approximation and data outliers obvious. The cost of making measurements over a wide range of temperatures and pressures make experimental data scarce in that field.And it will generate publication quality EPS for inclusion in a document.

author: rs20
author_rank: Super Contributor
timestamp: March 15, 2019, 12:48:18 am
content: Quote from: rhb on March 13, 2019, 11:30:35 pmWhat's your strategy to avoid overfitting (or put another way, what's your strategy for distinguishing noise from signal?)

author: rhb
author_rank: Super Contributor
timestamp: March 15, 2019, 01:14:38 am
content: A general answer to that is difficult. Usually I have had some basic physics to guide me. I intensely dislike neural nets and such because they hide the actual connection to reality.At the moment looking at the spectrum of the residual error to see if it approximates expected noise processes is the best response I can think of. DeBoor talks about that in his book on spline fitting.My preference is having a huge amount of data, generate a probability density function and fit that. I'll ponder the matter and see what I think of in the morning.

author: basinstreetdesign
author_rank: Frequent Contributor
timestamp: March 15, 2019, 05:29:54 am
content: Yeah, I expect the jaggedness of the data is due to random errors of some sort. But when presented with a problem like this I usually turn to a tool that I got for free a while ago.A US professor had created a methodology not for fitting a data set to a given function but forfinding an optimal functionto fit through the data set. He was the speaker in a fascinating YT vid on the subhect. He called it Formulize and offerred it for FREE to all comers but without a couple of enhancements. Then changed the name to Eureqa and kept improving it. That's when I got a copy of it for WIN 7. In the last 2-3 years his outfit must have been sold to another that markets it under the name of Nutonian and they now still sell copies of it for cash only - sigh, but a 30-day free trial is still available.Anyway, I put your 32 point dataset into my copy and this is what it came up with in 10 minutes. Errors were input as percent figures. First your data,Then the result. The top right hand chart is a comparison of the error values (red line) against the Vin data as compared with the generated function (blue dots). The function displayed is the best fit of several functions that it tried in the list to the left.The function shown is:0.0923823416426414 + 0.00055657868106123*Vin^2 + 3.64813221897325e-11*Vin^5 - 0.0337946466493136*Vin - 2.31333395165299e-16*Vin^7 - 3.06788272866507e-6*Vin^3 = ErrorIt has a "R^2 goodness of fit" of 0.8809998, a correlation coefficient of 0.94465699 and Mean Square Error of 0.0058587105I limited the function generated to constants, arithmetic, trig, powers, log and root terms. I have tried allowing others including inverse trig and hyperbolic trig, logical and squashing functions but produced no better results in 10 min.Even if this is useless it at least allowed me to play with this tool and to kill half an hour.Cheers

author: rhb
author_rank: Super Contributor
timestamp: March 15, 2019, 12:21:15 pm
content: What are the physics of the device you are trying to calibrate? That will tell you what functional forms to consider.As an example, if you are trying to calibrate a signal path where you have connectors at a certain distance, then you expect to have some ringing due to reflections between the connectors. So that requires a functional form which includes that with the reflection coefficients and the delay as the fitting variables.Trying functions until you find one that fits is *not* a good idea. Also you really do need a *lot* more data.The king of the hill is the "Dantzig selector" presented by Emmanuel Candes. You create a large matrix of possible solutions, A, collect some data, y, and solve Ax=y for a sparse x using an L1 solver such as linear programming.https://statweb.stanford.edu/~candes/papers/DantzigSelector.pdfIt is far superior to any L2 based method and particularly appropriate wee the data are known to be a superposition of several functions. It handily solves problems that Foreman Acton advised his readers not to attempt in "Numerical Methods That Work". The easiest explanation of the concepts is the section on matching and basis pursuit in Mallat's 3rd ed of "A Wavelet Tour of Signal Processing".I was doing that when I realized I was doing things I'd been taught could not be done. Which is what started me on a 3 year, 3000 page mathematical odyssey.

author: tggzzz
author_rank: Super Contributor
timestamp: March 15, 2019, 02:54:19 pm
content: Quote from: rhb on March 15, 2019, 12:21:15 pmThat accurate and extremely pertinent point has been made at least twice in this thread. It may not have been understoodhttps://www.eevblog.com/forum/projects/curve-fitting-question/msg2249952/#msg2249952https://www.eevblog.com/forum/projects/curve-fitting-question/msg2250018/#msg2250018(as usual, XKCD summarises the issue pithily)