Now, see, I didn't know this:
The equations below are from David Jacobson's Lens Tutorial. MTF is the absolute value of the optical transfer function OTF (MTF = |OTF|), which includes phase and hence can go negative. The OTF for the circle of confusion C is based on a mathematical function called a Bessel function of the first kind (J1), which you won't find in simple programming languages, but which can be adequately approximated using
2 J1(x)/x ~= sinc(0.84x) where sinc(x) = sin(x)/x; below the first null of sin(x); x < π.
Let s = λ N fsp ; a = π C fsp
where λ = wavelength of light (typically 0.0005 or 0.000555 mm for green or yellow-green, near the middle of the visible spectrum; N = f-stop; fsp = spatial frequency; π = 3.14159; C = Circle of confusion. s and a are dimensionless.
For pure diffraction (no focus error; a= C = 0),
OTF(s) = 2/π (arccos(s) - s sqrt(1-s2 )) for s < 1
= 0 for s >= 1
For focus error only with circle of confusion C (no diffraction; s = 0),
OTF(a) = 2 J1(a)/a ; J1 is a first order Bessel function.
~= sin(0.84a)/(0.84a) up to the first null (0.84a < π)
Seriously, those are some good links, and I'll have to spend some time studying a little bit. I've got a holiday coming up, and I want to bring home some good photos. I may end up taking different sets of images at various apertures to be on the safe side.