Author Topic: Need help figuring out how to compare value against a known curve  (Read 1992 times)

0 Members and 1 Guest are viewing this topic.

Offline MatCatTopic starter

  • Frequent Contributor
  • **
  • Posts: 377
  • Country: us
Need help figuring out how to compare value against a known curve
« on: September 09, 2018, 11:23:14 pm »
I am working with a sensor that I have graphed and found it's curve across the points of measurement, but my problem is trying to figure this out against different calibrations.  In one medium the plots will be different values then another, but it all follows the same curve.  My issue is I am not sure how to programatically / mathematically take a calibration value at a known point, and use that to correlate to the known curve. Here I have a screenshot of 3 collected datasets, the orange line has data for each point, for the other 2 datasets I did not collect all points. 


 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Need help figuring out how to compare value against a known curve
« Reply #1 on: September 10, 2018, 01:50:14 am »
Quadratic Regression Analysis (QRA).  There are a number of calculators available via Google.

Once it comes up with the equation of the line, you can plug in an 'x' and get a good fitting 'y' for anything in the domain.

https://keisan.casio.com/exec/system/14059932254941

You are going to have to come up with an explanation for the 3 curves or you are going to have to do 3 different QRAs and have 3 separate equations.

There are higher order versions if a quadratic doesn't fit well.  Search for more info with 'higher order regression analysis'

http://www.xuru.org/rt/pr.asp
« Last Edit: September 10, 2018, 01:53:36 am by rstofer »
 
The following users thanked this post: Mr. Scram

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: Need help figuring out how to compare value against a known curve
« Reply #2 on: September 10, 2018, 01:57:31 am »
Quadratic Regression Analysis (QRA).  There are a number of calculators available via Google.

Once it comes up with the equation of the line, you can plug in an 'x' and get a good fitting 'y' for anything in the domain.

https://keisan.casio.com/exec/system/14059932254941

You are going to have to come up with an explanation for the 3 curves or you are going to have to do 3 different QRAs and have 3 separate equations.

There are higher order versions if a quadratic doesn't fit well.  Search for more info with 'higher order regression analysis'

http://www.xuru.org/rt/pr.asp
I just learnt a bunch. I would have chosen a sloppy interpolation approach, but this is much more elegant.

Thanks!
« Last Edit: September 10, 2018, 02:04:18 am by Mr. Scram »
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11630
  • Country: my
  • reassessing directives...
Re: Need help figuring out how to compare value against a known curve
« Reply #3 on: September 10, 2018, 08:40:40 am »
My issue is I am not sure how to programatically / mathematically take a calibration value at a known point, and use that to correlate to the known curve. Here I have a screenshot of 3 collected datasets, the orange line has data for each point, for the other 2 datasets I did not collect all points. 
your data seem to follow y = (A / (x + B)) + C curve, try to find value for A, B and C (start with B and C = 0) that closely match your curve and use the values for interpolation purpose.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline CatalinaWOW

  • Super Contributor
  • ***
  • Posts: 5231
  • Country: us
Re: Need help figuring out how to compare value against a known curve
« Reply #4 on: September 10, 2018, 11:41:38 am »
Beware when fitting data to an arbitrary equation.  It is easy to convince yourself that the equation, not the data, is correct.

Your data seems to follow a simple curve, but may indicate different behavior for low values of the x coordinate.  Either be suspicious of fitted behavior in this region, or look for reasons for changed behavior.  A zener threshold crossed, or a stage saturated, or .....
 

Offline MatCatTopic starter

  • Frequent Contributor
  • **
  • Posts: 377
  • Country: us
Re: Need help figuring out how to compare value against a known curve
« Reply #5 on: September 10, 2018, 09:33:33 pm »
Just to give some background on what it is, the sensor is a capacitive sensor that is detecting the level of moisture in a tank.  The data points 1 to 15 are incremental measured submersion lengths, the difference between the 3 curves is blue distilled water, orange is tap water, and grey is nutriented water.  Since the sensors voltage output was quite low compared to my ADC I upped the gain to get more resolution as seen in the attached curve, which is tap water as a base reference.  In reality the final system will generally contain nutriented water which is closer to tap then distilled.  I seem to have the resolution to do what I want it's just a matter of the variable difference in water people will use and fitting it to the curve to approximate as best as I can, at least the highest resolution  is towards when the tank will be empty which is more important then when its half full or full.

 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3238
  • Country: gb
Re: Need help figuring out how to compare value against a known curve
« Reply #6 on: September 11, 2018, 02:54:56 pm »
A second fixed capacitive sensor at the bottom of the tank could be used to calculate the dielectric constant of the liquid.  Knowing this you can correct your measurement.
 

Offline MatCatTopic starter

  • Frequent Contributor
  • **
  • Posts: 377
  • Country: us
Re: Need help figuring out how to compare value against a known curve
« Reply #7 on: September 25, 2018, 08:13:05 pm »
It's been a few weeks and I still haven't figured out how to make this comparison, surely someone out there has a good code example of how this can be done.
 

Offline rhb

  • Super Contributor
  • ***
  • Posts: 3481
  • Country: us
Re: Need help figuring out how to compare value against a known curve
« Reply #8 on: September 25, 2018, 10:51:50 pm »
Get gnuplot.  Learn to use it.  Done.

Seriously,  fit the appropriate curves to each set of measurements and plot your heart out.

The following reads two columns of input in an ASCII text file separated by spaces (the default), fits a polynomial and then plots the polynomial and the data points.

a(x) = A + B*x + C*x**4
fit a(x) 'data_file' using 1:2 via A,B,C
plot 'data_file' u 1:2, a(x)
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Need help figuring out how to compare value against a known curve
« Reply #9 on: September 25, 2018, 11:33:00 pm »
Once you have the coefficients for a good fitting polynomial of some power, you will have an equation like given above.  For a fourth degree polynomial it will look like

y = Ax^4 + Bx^3 + Cx^2 + Dx + E  - A,B,C,D & E are the coefficients you gained from the curve fit.

Now, take a reading and call it 'x' and stuff it back into the equation with the appropriate coefficients and the resulting 'y' is the value you seek.

You really don't want to have to form all those powers of x so you can factor and solve thusly:

y = (((A*x+B)*x+C)*x+D)*x+E
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Need help figuring out how to compare value against a known curve
« Reply #10 on: September 25, 2018, 11:40:31 pm »
Your plot looks like an exponential.  About half way down this page is an example of fitting an exponential curve using Excel:

http://www.engineerexcel.com/nonlinear-curve-fitting-in-excel/

I haven't tried it but it looks pretty nice!  It's also pretty tricky because it tries to use linear math on an exponential.

Again, you get coefficients and then you use them to get a y value from a given x value.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf