0
$\begingroup$

I have a data from experimental system concerning temperature of molten lead. In this system, temperature is increased in one place and then is measured when this increase of temperature travels to a different place by natural convection.

Data are pairs time vs. measured temperature. The time have steps of one second (sometimes two, due to the measuring system) and temperatures have steps of 0.1 degree of Celsius.

I would like to find when temperature crossed a certain temperature threshold. Let´s say I have something like:

  • Time [s] - Temperature [°C]
  • 1 - 440.8
  • 2 - 440.9
  • 3 - 441.1
  • 4 - 441.2

I tried linear fit on two points (right below and right above threshold e.g. 441.0) but I would like to try something more "advanced". I know that Excel can do fitting quite well and it is possible to find root by Wolfram Alpha, but it is not an option since I have to evaluate several experiments done each day (thus I have prepared program for it in C# programming language).

Thus I would like to know if there is some plan like saying "take 2 points below threshold and two above, do [something] and you will get time when temperature crossed your chosen threshold". It can use of course more data points. I am not interested in the fitting equation itself, just its root(s).

Thank you for your hints and ideas! Michal

EDIT: My data are somewhat noisy at constant temperature, but when rise of temperature takes place, it is not a problem.

$\endgroup$
2
  • $\begingroup$ You can try a the option best-fit curve of the a computer algebra software like Matlab, Octave or wxMaxima. $\endgroup$
    – Gonenc
    Jul 14 '15 at 10:03
  • $\begingroup$ Thank you for idea, but since I need to do it in my program, I can use this only to verify my solution, not to find it. $\endgroup$
    – Rao
    Jul 14 '15 at 11:55
1
$\begingroup$

If you want to take 4 points, I would still stick with linear approximation. It mostly depends on the noisiness of your data and rate of change of the temperature. You want higher order fit (like Floris described) in case you have low noise and time between observation is big. Your sample data do not seem as the case.

The linear fit is analytical and easy. You just take whatever amount $N$ of points around the threshold you deem appropriate, and compute slope $a$ and intercept $b$ of the best fitting line with the classic formula (bar denotes mean): $$ a = \frac{\sum_N (x_i-\bar{x})(y_i-\bar{y})}{\sum_N(x_i-\bar{x})^2} $$

$$ b = \bar{y}-a\bar{x} $$

Your root $x_{root}$ for threshold $T$ is then trivially: $$ x_{root} = \frac{T-b}{a} $$

If you still choose the quadratic fit you can find quadratic coefficients like this and then compute root of quadratic function.

$\endgroup$
0
$\begingroup$

I would take two points below and two point above the point where the threshold is crossed and fit a parabola. If the points are equally spaced the equations are quite simple. It is a little bit more work if they are not.

You will be solving three equations with three unknowns, where the coefficients of the equation are a function of the $x_i, y_i$ data points.

The equations you need are described in http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html

Basically you will create the Vandermonde matrix (see link) and solve the set of equations.

To make things work more robustly you should subtract the mean from the data before you start - otherwise, since you are taking the sum of a bunch of numbers to the sixth power, numerical errors will creep in.

When I get near a laptop I may write the C code to show how this is done.

$\endgroup$
2
  • $\begingroup$ A parabolic spline needs three points. If you have four points, they describe a cubic. You're not doing least squares unless you are fitting more points than your spline has degrees of freedom. $\endgroup$ Jul 14 '15 at 12:14
  • $\begingroup$ @MikeDunlavey - I am recommending using a parabolic fit through four points - not a cubic spline. Hence the link to "least squares fitting". It takes a little bit of the noise out... $\endgroup$
    – Floris
    Jul 14 '15 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.