Blood caffeine concentration: part 2

Note: I used KaTeX to render the equations here. There are a couple issues with the CSS that I haven’t had the time to work through, so the equations appear a bit messed up.

In a previous post, I mentioned that I’d integrate the formula so that coffee consumption could be considered an event of finite duration instead of a point event. Even if you bolt down a cup of coffee, it’s not instant. (If you really want to, you can use a Dirac delta function, also known as an impulse function, to model instant consumption. The following equations will still hold.)

I was going to simply integrate, but after rereading Animate Your Way to Glory I decided to derive it as a filter instead. This should come out to the exact same result, but with a method that’s a bit easier to grasp intuitively.

In the second demo, slide 66, the following equation appears:

pi=qiri=k=qkrikp _ i = q _ i \otimes r _ i = \sum _ {k=-\infty}^{\infty} q _ k\, r _ {i-k}

This represents a convolved function, and as Wittens describes and demonstrates, convolution effectively “slides” one function along the mirror image of the other. In this case, qiq _ i is the filter and rir _ i is the signal.

The unique thing about our application is that we’re not looking for a signal of similar magnitude to the input; we’re literally just summing events. Wittens says that the area under the curve for qiq _ i needs to equal 1, but in our case that’s not so.

Converting this from discrete events into a continuum is easy; just switch around the notation:

p(t)=q(t)r(t)=q(u)r(tu)dup(t) = q(t) \otimes r(t) = \int_{-\infty}^{\infty}q(u)\;r(t-u)\;du

p(t)p(t) represents the output we want: the amount of caffeine in the body at time tt. r(t)r(t) is easy; that’s our consumption, or rate of input of coffee. For one cup consumed between time t1it _ {1 _ i} and t2it _ {2 _ i}, with aia _ i being amount of caffeine in the cup:

r(t)={ait2it1i,t1itt2i0elsewherer(t) = \begin{cases} \frac{a _ i}{t _ {2 _ i}-t _ {1 _ i}}, & t _ {1 _ i}\le t \le t _ {2 _ i}\\ 0\; & \text{elsewhere} \end{cases}

Now, though, we must deal with the annoying fact that we don’t actually know what our filter is. Let’s derive it starting with our original formula.

i(aiexp((tti)ln2λ)(1exp((tti)ln0.05α))ML)\sum_i \left( \frac{ a _ i \exp\left({\frac{-(t-t _ i)\ln 2}{\lambda}}\right) \left( 1 - \exp\left(\frac{(t-t _ i)\ln 0.05}{\alpha}\right) \right)} {ML} \right)

That sigma is annoying; let’s convert it to an integral. Letting aua_u represent rate of caffeine consumption:

p(t)=1MLa(u)e((tu)ln2λ)(1e((tu)ln0.05α))dup(t) = \frac 1 {ML} \int_{-\infty}^{\infty} { a(u)\; e^{\left( \frac{-(t-u)\ln 2} {\lambda} \right)} \left( 1 - e^{\left( \frac{(t-u)\ln 0.05}{\alpha} \right)} \right) } \;du

This is actually our answer, but I want to pick it apart a little bit before I call it a day. If you consider the consumption events used in our previous model as point events, you can model them with a Dirac delta function and the above formula still works.

And look, the (tu)(t-u) terms stayed intact! Meaning that our filter is simply:

q(t)=e(tln2λ)(1e(tln0.05α))q(t) = e^{\left(\frac{-t\ln 2}{\lambda}\right)} \left(1-e^{\left(\frac{t\ln 0.05}{\alpha}\right)} \right)

We can do one better though. If we define the following:

A=at2t1k1=ln2λk2=ln0.05αL=liters of blood per kg of mass in the typical human0.007LkgM=body massλ=half-life of caffeine in the body5 hoursα=absorption rate1 hour\begin{array}{rcl} A &= &\frac a {t_2 - t_1} \\ k_1 &= &-\frac {\ln 2}\lambda \\ k_2 &= &\frac{\ln 0.05}{\alpha} \\ L &= &\text{liters of blood per kg of mass in the typical human} \\ &\approx & 0.007 \frac{\mathrm{L}}{\mathrm{kg}} \\ M &= &\text{body mass} \\ \lambda &=& \text{half-life of caffeine in the body} \\ &\approx & 5 \text{ hours} \\ \alpha &=& \text{absorption rate} \\ &\approx & 1\text{ hour} \end{array}

Then a cup of coffee containing amount aa of caffeine consumed between times t1t _ 1 and t2t _ 2 will, at time tt, cause the following amount of caffeine to remain in the body:

p(t)=AML[e(k2+k1)(tu)k2+k1ek1(tu)k1]u=t1t2p(t) = \frac A {ML} \left[ \frac{e^{(k _ 2+k _ 1)(t-u)}}{k _ 2+k _ 1} - \frac{e^{k _ 1(t-u)}}{k _ 1} \right] _ {u=t _ 1}^{t _ 2}

For multiple cups, we simply need to evaluate the above expression once for each cup. I don’t think we can really get any more accurate without a cup that constantly measures the level of liquid in it. Even if we tried this, it’s likely that the model would begin to break down. When you’re measuring on such small timescales, you’d need to keep track of things like esophagaus movement and salivation. Our model is about as good as it gets without delving into some of the crazier realms.