Skip to content
PreciSim
Lab manual
lab4-z-focus

Lab 4 · Z focus calibration

Goal
Find the best focal plane from a sharpness curve, and watch noise push it around.
Estimated time
40min
Level
Intermediate
Prerequisites
Complete Lab 1.

Goal

Locate the focal plane with repeatability inside ±10 µm, then raise the noise, watch it degrade, and recover it.

Steps

  1. Calibration → Z focus, range ±3 mm, step 0.2 mm, measure Tenengrad.
  2. Export the sharpness curve (Results → Export CSV) and plot it.
  3. Repeat ten times and compute the standard deviation of the focus position — that is focus repeatability.
  4. Devices → Virtual devices → cam0 → Noise: raise readNoiseE from 2.3 to 15. Repeat step 3.
  5. Turn on frame averaging (avgFrames = 8) and repeat step 3.
  6. Change the step from 0.2 mm to 1.0 mm and see whether parabola fitting still holds precision.

Pass criteria

Item Criterion
Step 3 focus repeatability (1σ) < 10 µm
Step 4 focus repeatability clearly worse (typically 5× or more)
Step 5 focus repeatability back inside 15 µm
Step 6 precision drops, but should not degrade to the step size

Common mistakes

  • Search range narrower than the depth of field. The curve is monotonic with no peak. Depth of field on this machine is about 2.14 mm.
  • Taking the maximum sample directly. Precision is then capped at the step size; fit the parabola.
  • Dragging far-defocused points into the fit. The curve is not parabolic out there and the fit gets worse.
  • Thresholding on absolute sharpness. Change the exposure and everything breaks. Only the peak position carries meaning.

Review questions

  1. Why does noise flatten the sharpness curve rather than simply shifting it up?
  2. Averaging 8 frames should cut noise to 1/√8 ≈ 0.354. Did focus repeatability improve by that much? Why not?
  3. How does the peak change with variance or Laplacian energy instead? Which suffers most from noise?
  4. On real hardware there is no truth. How would you convince yourself that the plane you found is genuinely the sharpest, and not a local maximum of your measure?