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
Calibration → Z focus, range ±3 mm, step 0.2 mm, measure Tenengrad.- Export the sharpness curve (
Results → Export CSV) and plot it. - Repeat ten times and compute the standard deviation of the focus position — that is focus repeatability.
Devices → Virtual devices → cam0 → Noise: raisereadNoiseEfrom 2.3 to 15. Repeat step 3.- Turn on frame averaging (
avgFrames = 8) and repeat step 3. - 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
- Why does noise flatten the sharpness curve rather than simply shifting it up?
- Averaging 8 frames should cut noise to 1/√8 ≈ 0.354. Did focus repeatability improve by that much? Why not?
- How does the peak change with variance or Laplacian energy instead? Which suffers most from noise?
- 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?