Metadata-Version: 2.4
Name: quadrature-interferometer-sim
Version: 0.1.0
Summary: Simulates a Michelson interferometer with quadrature (I/Q) homodyne detection and realistic detector noise, and implements the analysis pipeline that recovers nanometer-scale mirror displacement and vibration from the resulting fringe signals.
Author: Nishad Suresh
License: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy==2.2.6
Requires-Dist: scipy==1.15.3
Requires-Dist: matplotlib==3.10.9
Dynamic: license-file

# Quadrature Interferometer Simulator

**Nishad Suresh**

## Abstract

This project simulates a Michelson interferometer with realistic detector noise and implements the analysis pipeline required to recover nanometer-scale mirror displacement and vibration from the resulting fringe signals. A naive single-photodiode approach was tested during design and found to fail (54% displacement error, with a fundamental direction ambiguity since cos(phi) cannot distinguish +phi from -phi). This motivated a switch to quadrature (I/Q) homodyne detection, using two detectors 90 degrees apart, which resolves the ambiguity via atan2(Q, I) and gives an unambiguous, monotonic phase estimate. The resulting pipeline recovers displacement to 0.0395% RMS error and vibration frequency to 0.0019% error, and remains under 1% error across a detector-noise sweep from 0% to 6%. A subsequent extension (Section 6) tests whether a nonlinearity-correction technique validated on real interferometer hardware generalizes to this simulator; the result is conditional, matching the real-hardware failure modes documented in that work rather than exceeding them.

**Status:** all 5 phases complete; Section 6 extension complete.

## 1. Motivation

This is the one project in this portfolio tied to ongoing optics research rather than an abstract simulation exercise. The central engineering decision -- moving from single-detector to quadrature (I/Q) homodyne detection -- is the primary instrumentation content of the project, not an implementation detail, and is treated as such throughout this document.

## 2. Physics

For a Michelson interferometer with one mirror displaced by `x(t)`, the round-trip path length changes by `2x(t)`, giving phase `phi(t) = 4*pi*x(t)/lambda`. The two quadrature detectors measure:

```
I(t) = I0 * (1 + V*cos(phi(t)))
Q(t) = I0 * (1 + V*sin(phi(t)))
```

## 3. Setup

The `src/` layout is an installable package (`quadrature_interferometer_sim`). Either install it (editable, for development) or just point `PYTHONPATH` at `src/` -- both work with the commands below.

```bash
python -m venv .venv && source .venv/bin/activate
pip install -e .          # or: pip install -r requirements.txt && export PYTHONPATH=src

python tests/test_phase1.py   # fringe spacing check
python -m quadrature_interferometer_sim.validate    # displacement recovery
python tests/test_phase3.py   # vibration detection
python tests/test_phase4.py   # noise sweep
python -m quadrature_interferometer_sim.dashboard   # full visualization

# ellipse-distortion nonlinearity-correction extension (Section 6)
python tests/test_ellipse_distortion.py   # distortion model, bit-for-bit at defaults
python tests/test_circle_fit_degrades.py  # confirms the circle-fit pipeline breaks down
python tests/test_ellipse_fit.py          # ellipse-fit correction, verified in isolation
python tests/test_ellipse_sweep.py        # answers the generalization question
python tests/test_hysteresis.py           # direction-dependent hysteresis (stretch goal)
```

Note: `validate.py` and `dashboard.py` now live inside the package and use relative imports internally, so they must be run with `-m` (as above) rather than as bare scripts -- `tests/*.py` are unaffected and still run as plain scripts because of their `sys.path.insert` shim.

## 4. Methodology and Results

| # | Phase | Acceptance test | Result |
|---|---|---|---|
| 1 | Physics simulation: quadrature I/Q with tunable noise | Fringe spacing matches λ/2 analytically | ✅ 0.000000% error (31 fringes) |
| 2 | Analysis: bias/mains removal, atan2 unwrap, displacement recovery | <1% RMS error on injected displacement | ✅ 0.0395% error |
| 3 | Vibration detection via FFT | Vibration frequency within 1% | ✅ 0.0019% error |
| 4 | Noise sweep | <1% error across tested noise range | ✅ max 0.1234% across 0-6% noise |
| 5 | Validation report + dashboard | A written report a reader can check | ✅ `report/validation_report.md` |

### 4.1 Full dashboard

![dashboard](results/dashboard.png)

Fringes, displacement recovery, and vibration spectrum, generated from a single validated simulation run.

### 4.2 Noise robustness

![noise sweep](results/noise_sweep_plot.png)

Full validation writeup with all equations and numbers is available at `report/validation_report.md`.

## 5. A Methodology Issue Found During Review

The original DC-bias estimator, a whole-record mean, only worked correctly because every test case up to that point included a large phase ramp. Pure steady-state vibration sensing with no ramp, one of this project's two stated goals, silently produced 58%+ recovery error under that estimator. This was corrected by geometrically fitting a circle to the (I, Q) trajectory instead (see `report/validation_report.md` for the full account, including a first fix attempt using low-pass filtering that did not actually resolve the issue). Every result reported in Section 4 reflects the corrected code.

A later independent review caught two smaller loose ends left over from that fix: `analysis.py`'s module docstring still described the old low-pass-filter approach rather than the circle fit that had replaced it, and `dashboard.py` re-simulated the interferometer a second time using its own hand-copied parameters instead of reusing `validate.py`'s single source of truth, a real risk of the two silently drifting apart. Both were corrected; `dashboard.py` now pulls I/Q directly from a single `run_validation()` call.

## 6. Extension: Ellipse-Distortion Nonlinearity Correction

Sections 1 through 5 assume the (I, Q) trajectory is a perfect circle, true for this simulator's default output but not for real quadrature detectors. C. Lehmann et al. [1] show that real homodyne quadrature interferometer (HoQI) hardware traces a tilted ellipse instead, from amplitude imbalance, non-90-degree quadrature phase error, and DC offset between channels, and correct it with a Heydemann ellipse fit. This section asks and answers, empirically, a question the source paper does not address: does that real-hardware correction generalize to a from-scratch simulator?

**Distortion model.** New optional parameters on `simulate_interferometer` (`amplitude_ratio`, `quadrature_error_rad`, `dc_offset_i`, `dc_offset_q`), defaulting to zero distortion, bit-for-bit identical to Sections 1-5. Magnitudes are calibrated to the source paper's own measured hardware ellipse: amplitude ratio up to 1.086 (8.6% channel imbalance), quadrature error up to 0.166 rad (~9.5 degrees).

**The existing circle-fit pipeline breaks down.** Sweeping distortion magnitude, arc coverage (what fraction of a full circle the trajectory traverses), and detector noise, the circle-fit recovery error grows from 0% (undistorted) to 1.03% at the paper's full measured distortion at full arc coverage, and up to 2.32% under partial arc coverage.

**Ellipse-fit correction, verified in isolation.** A Halir and Flusser [5] direct least-squares ellipse fit, paired with a closed-form (not eigendecomposition-based) conversion to the distortion parameters above, implemented alongside, not replacing, the circle fit. The conversion was verified against hand-built synthetic distorted circles with known parameters before being run on simulator output, recovering injected values to under 1e-6, across both positive and negative quadrature error.

**Does it generalize?** Ellipse-fit correction beats the circle fit, and a static correction survives at least 50% relative parameter drift (the source paper measured about 20% drift over hours of real operation), whenever arc coverage is full at any noise level, or noise is zero at any arc coverage. It degrades, in some cases to over 1000% error, specifically when limited arc coverage and nonzero noise occur together. This was confirmed to be a genuine ill-conditioned-fit finding rather than an implementation defect by inspecting the fitted conic directly: it is a valid ellipse, just the wrong one, since noisy, partial-arc data supports multiple very different ellipses with nearly equal fit residual. This reproduces, in simulation, the identical failure mode the source paper reports for real sub-FSR HoQI hardware data, which is why its authors used a constrained two-parameter search rather than a direct fit for that regime.

**Direction-dependent hysteresis.** The source paper explicitly flags one nonlinearity source, path-dependent hysteresis near motion turning points, as only partially correctable even on real hardware. Modeling this as a radial perturbation dependent on the local direction of phase motion, a single static ellipse fit, direction-independent by construction, cannot fully correct it: residual error grows monotonically from 0% to 4.2% with hysteresis magnitude, matching the source paper's own finding that its per-direction spline correction for this nonlinearity was an explicitly partial fix.

Full numeric detail, tables, and plots are in `report/validation_report.md`, under "Nonlinearity-corrected pipeline."

## 7. Limitations

**Simulation only.** Every number reported above is computed on simulated detector data, not a real optical bench. This is framed throughout as validation of the analysis pipeline, not as a claim of having built a physical interferometer.

**No comparison to real bench data yet.** This is the natural next step, planned in collaboration with an optics research mentor, to strengthen the empirical tie beyond simulation. Noted as future work in the validation report. The Section 6 extension calibrates against the source paper's reported hardware numbers, which is not a substitute for validating against real bench data directly.

**Simplified noise model.** Shot noise is modeled as intensity-independent Gaussian noise for tunability, rather than true signal-dependent Poisson shot noise. This is a reasonable approximation at the noise levels tested, but a real bench's noise floor may behave somewhat differently.

**Extension's ill-conditioning failure mode is demonstrated, not fixed.** The partial-arc-coverage-plus-noise regime where ellipse-fit correction breaks down is characterized in Section 6, but the source paper's own solution, a constrained two-parameter search, was not implemented here.

## 8. Summary

This project implements and validates the complete quadrature-detection analysis pipeline required by a real Michelson interferometer, recovering nanometer-scale displacement to 0.0395% error and vibration frequency to 0.0019% error, and remaining robust to detector noise up to 6%. An extension further shows that a real-hardware nonlinearity correction generalizes to this simulator conditionally: reliably at good arc coverage, and not when limited arc coverage combines with detector noise, matching rather than exceeding the limits the source hardware paper itself documents.

## References

Sources used to design, validate, and cross-check this project's methodology:

[1] C. Lehmann et al., "Nonlinearity correction for homodyne quadrature interferometers," arXiv:2511.04386, Nov. 2025 (Max Planck Institute for Gravitational Physics). https://arxiv.org/abs/2511.04386 -- source of the ellipse-distortion model and Heydemann correction technique implemented in Section 6, including the paper's own measured ellipse parameters used to calibrate the distortion sweep.

[2] G. Cooper et al., "A compact, large-range interferometer for precision measurement and inertial sensing," Class. Quantum Grav. 35, 095007 (2018). arXiv:1710.05943. https://arxiv.org/abs/1710.05943

[3] O. Smetana et al., "Compact Michelson interferometers with subpicometer sensitivity," arXiv:2202.10274. https://arxiv.org/abs/2202.10274

[4] S. M. Kranzhoff et al., "A vertical inertial sensor with interferometric readout," Class. Quantum Grav. 40, 015007 (2023). https://doi.org/10.1088/1361-6382/aca580

[5] R. Halir and J. Flusser, "Numerically stable direct least squares fitting of ellipses," WSCG'98 Conference Proceedings, 1998. -- the direct least-squares ellipse fit implemented as `fit_ellipse_conic` in `src/analysis.py` and used throughout Section 6.

[6] I. Kasa, "A circle fitting procedure and its error analysis," IEEE Trans. Instrumentation and Measurement, vol. 25, no. 1, 1976, pp. 8-14. https://doi.org/10.1109/TIM.1976.6312298 -- the algebraic circle-fit method `src/analysis.py` implements for DC-bias recovery.

[7] P. Hariharan, Basics of Interferometry, 2nd ed., Academic Press, 2007. -- general reference for Michelson interferometer theory and fringe formation underlying `src/physics.py`.
