Freesteel Blog » Exponential decay curve fitting

Exponential decay curve fitting

Tuesday, October 14th, 2014 at 12:37 pm Written by:

Suppose we have a temperature sequence like this one gathered from last September in our kitchen when we started to put the fire on in the late evenings. The central heating wasn’t on yet, so there’s no second temperature “bump” in the mornings. (The three bumps in the first peak are the three logs we put on the fire.)

You get an appreciably square looking graph by plotting the data as units of an hour in X, and units of a degree centigrade in Y, so a 45degree slope would represent a 1 degree difference per hour, which is the right scale of change in our environment.

My immediate observation from the first moment I saw such a temperature sequence (roughly in the middle of last summer when we visited megni in North Wales) was that these are exponential decay curves.

The trick is to find them and fit them.

An exponential decay curve can be defined by three parameters, vL, t10 and d combined into the following formula (where v=temperature and t=time)

    v = 10 exp(-d (t - t10) ) + vL
    vL - lower asymptote of the temperature
    t10 - absolute time when temperature would be 10 degrees above vL
    d - exponential decay constant

The choice of t10 is that it makes it human readable and unambiguous. If the temperature in the house is exactly 10 degrees above the ambient temperature vL that everything would cool down to when all the heating was turned off, then t10 is now.

To fit an exponential decay curve to a slice of your temperature time sequence, you first find a tangent point (tS, vS) with slope -s. You need to do this geometrically from the measurement curve itself, probably by blurring it and doing something fudgy with that.

For a quick and dirty method, suppose you have a short sequence of measurements tvs:

  tvs = [ (t1, v1), ..., (tn, vn) ]
  s = -(vn - v1) / (tn - t1)       average slope of sequence
  sd = min{ s ti + vi  | i = 1, ..., n} / (1 + s^2)     
              [ minimum of dot products of (ti, vi) and anti-clockwise 
                    perpendicular of (1, -s) ]

  The values s and sd define the tangent line.  
  The point of tangency (tS, vS) is related by:
      vS = sd - s (tS - sd s)

  Set tS to the midpoint of the region of closest 
  approach to the tangent line defined by s and sd

Once you have chosen your s, tS and vS, you need to set a value of d for the exponential decay constant. It’s going to be some number between 0.1 and 2. Then you can calculate t10 and vL as follows:

  t10 = tS - ( log(10) - log(s/d) ) / d
  vL = vS - s/d

How do you set the value of d?

Well, you try out a bunch of different values, and see whether each one bends inwards or on the outside of the curve we are trying to fit:

This fits exponential decay curves to the measurements well enough for now. I’m sure if we had to do it properly on a massive scale there’d be some theory like a Fourier transform that would help us out. But the key is, these are not cyclical patterns, like sinusoidal waves.

Instead, they are instances when everything is a “rest”, in a matter of speaking. It’s like having a surface of water over everything that’s rippling like a pool. But every once in a while all the waves flatten out for a short interval so you can glimpse the machinery underneath. You can’t control when these moments come about, but you can watch for them.

Here’s what happens when I tried to detect exponential decay curves on every two hour interval in the time series at 5 minute increments.


The vL values look pretty stable, probably an average of the outside and inside temperature, and it may be declining during the night as the outside temperature continues to dip. The t10 position is also well clumped, meaning that the projection back at most points comes to the same moment. But the decay value d seems to fluctuate a lot. I’m hoping this is noise, because it was the value I’m betting will be an invariant based on the fabric of the building — so that when the building changes, this number changes.



MDS below in the comments pointed out that I should obviously be using logarithms and linear regression to fit exponential curves.

The fact that the value is offset by vL from zero means you need to guess its value before applying the log, thus plotting t against:

    log (v - vL) = log 10 - d (t - t10)

(The t10 thing is starting to look like a stupid idea. If we replace it with 1, then our line passes through the X axis at the time when it is one degree above the asymptote.)

Anyway, by trying different values of vL and plotting it, you get this picture:


This is fantastic, and much better than trying out different values of d at a point tangent, as I was doing above. Instead we look at the curves for different values of vL and note how they inflect from curving upwards to curving downwards on a particular value of vL at various sections, and derive the d and t10 values from the slope in that section, which we can determine more reliably by linear regression.

1 Comment

  • 1. MDS replies at 15th October 2014, 3:03 am :

    Why not least-squares a line to the logarithm of the data?

    Also, low-pass filtering the data, taking the log, and then averaging the derivative (in regions in which it is negative) should give a nice value for d, with much less noise.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>