A toolkit for astronomical instrumentation development, including spectrograph design, fibre optics analysis, optical performance modelling, Zemax optimization, and experimental spectral data processing.
This repository collects MATLAB and Zemax tools developed for the design and analysis of astronomical spectrographs, with particular emphasis on fibre-fed and integral field spectroscopy.
The workflow covers several stages of instrument development:
- first-order spectrograph sizing;
- geometrical and diffraction-limited performance analysis;
- fibre-image overlap and crosstalk modelling;
- Zemax optical optimization;
- detector data extraction and wavelength calibration;
- experimental resolving-power measurements.
The tools were originally developed during MSc thesis work on an integral field spectrograph for exoplanet science.
% Multi-band spectrograph parameter analysis
[optimal_params, analysis_data] = spectrograph_parameter_sweep({'Y','J','H'}, ...
'resolving_power', [5000,5000,5000], ...
'name', 'MCIFU_5000_950');
% Geometrical spectrograph analysis
[performance_metrics, geometric_params] = spectrograph_geometric_analysis(...
'R_Y', 7880, ...
's1', 7.3e-6, ...
'nPix', 2000, ...
'pix', 18e-6);
% Fibre crosstalk analysis
[crosstalk_results, analysis_data] = fibre_crosstalk_simulator('airy', ...
'fibre_separation', 25e-6, ...
'wavelength', 1.55e-6);
% Geometric-to-diffraction-limited transition
[transition_data, performance_metrics] = diffraction_limit_analysis(...
'grating_density', 650e3, ...
'beam_size', 14.8e-3, ...
'f_number', 3.57);spectrograph-toolkit/
βββ π MATLAB/
β βββ Optical_Geometry/
β β βββ spectrograph_parameter_sweep.m
β β βββ spectrograph_geometric_analysis.m
β β βββ diffraction_limit_analysis.m
β β βββ geometric_spectrograph_sweep.m
β β βββ geometric_spectrograph_evaluation.m
β β
β βββ Fibre_Optics/
β β βββ fibre_crosstalk_simulator.m
β β
β βββ Data_Processing/
β βββ extract_1d_spectrum.m
β βββ wavelength_calibration.m
β βββ apply_wavelength_calibration.m
β βββ measure_spectral_resolution.m
β βββ integrate_spectral_peak.m
β
βββ π Zemax_Templates/
β βββ Merit_Functions/
β β βββ collimator_optimization.MF
β β βββ spectrograph_optimization.MF
β β
β βββ Macros/
β βββ glass_substitution_tool.zpl
β
βββ π§ͺ Examples/
βββ airy_psf_example.png
βββ spectrograph_transition_example.png
βββ calibrated_spectrum_example.png
- spectrograph_parameter_sweep.m β Multi-band spectrograph parameter analysis for Y, J, and H bands, including grating-density matching between spectral channels.
- spectrograph_geometric_analysis.m β First-order analysis of resolving power, detector coverage, diffraction sampling, fibre-image separation, and optical geometry.
- geometric_spectrograph_sweep.m β Explores slit-limited spectrograph configurations over resolving power, slit width, grating density, detector geometry, and optical parameters.
- geometric_spectrograph_evaluation.m β Evaluates dispersion, sampling, detector coverage, and resolving power for a selected geometrical spectrograph configuration.
- diffraction_limit_analysis.m β Compares slit-limited and diffraction-limited resolving power and determines the transition between the two regimes.
- fibre_crosstalk_simulator.m β Models leakage between neighbouring fibre images using Airy, Gaussian, and dispersed-spectrum PSFs.
- Includes both continuous and detector pixel-integrated calculations.
- Supports analysis of fibre separation and PSF evolution with wavelength.
- extract_1d_spectrum.m β Extracts a one-dimensional spectrum from a raw detector image using spatial-region detection and local background subtraction.
- wavelength_calibration.m β Derives a polynomial wavelength solution from Neon reference lines and evaluates calibration residuals.
- apply_wavelength_calibration.m β Applies a previously determined wavelength calibration to an extracted spectrum.
- measure_spectral_resolution.m β Measures the FWHM of an isolated spectral line and estimates the experimental resolving power.
- integrate_spectral_peak.m β Performs local baseline subtraction and numerical integration of spectral peaks.
- collimator_optimization.MF β Merit function for collimator optimization using focal-length, throughput, and angular-aberration constraints.
- spectrograph_optimization.MF β Merit function for full spectrograph optimization using first-order constraints and RMS spot performance.
- glass_substitution_tool.zpl β ZPL macro for testing alternative optical materials during optimization.
The repository is organized around a typical spectrograph development sequence:
Instrument requirements
β
First-order parameter sweep
β
Geometrical spectrograph sizing
β
Zemax optical optimization
β
Diffraction and fibre crosstalk analysis
β
Experimental detector acquisition
β
1D spectral extraction
β
Wavelength calibration
β
Measured spectral performance
The MATLAB models are intended primarily for first-order design studies and parameter exploration.
Detailed imaging performance should subsequently be evaluated using a complete optical model and, where available, experimental measurements.
The analytical calculations use standard relations from geometrical and Fourier optics.
For first-order Littrow operation:
where
The slit-limited resolving power is evaluated from the projected slit width and spectrograph geometry.
The general model used in the toolkit is:
where:
-
$m$ is the diffraction order; -
$G$ is the grating line density; -
$F$ is the relevant focal ratio; -
$W$ is the illuminated grating width; -
$s$ is the slit width.
The diffraction limit is estimated using the Airy-disk criterion:
The transition between slit-limited and diffraction-limited behaviour occurs when:
Detector sampling is evaluated from the wavelength dispersion and projected slit or PSF size.
The local wavelength dispersion is derived from the grating equation and camera focal length.
The tools evaluate:
- wavelength coverage on the detector;
- number of detector pixels required;
- pixels per resolution element;
- resolving power as a function of wavelength;
- spectral extent across the focal plane.
These calculations can be used to compare detector formats and grating configurations during preliminary design.
The fibre-analysis routine estimates contamination between neighbouring fibre spectra using several PSF models.
Supported models include:
- Airy PSF;
- Gaussian PSF;
- dispersed spectral PSF.
For each model, crosstalk is estimated from the fraction of the source PSF falling inside a neighbouring extraction region.
Detector effects can also be included through pixel integration.
The analysis is intended as a first-order estimate of fibre-image leakage and extraction overlap rather than a complete detector or extraction-pipeline simulation.
The experimental routines connect the analytical design to measurements from a real detector.
A typical reduction sequence is:
raw detector image
β
extract_1d_spectrum.m
β
wavelength_calibration.m
β
apply_wavelength_calibration.m
β
measure_spectral_resolution.m
β
integrate_spectral_peak.m
The detector image is reduced by:
- identifying the illuminated spatial region;
- selecting a nearby dark region;
- estimating the column-dependent background;
- subtracting the background;
- integrating the signal along the spatial direction.
Detected Neon emission lines are matched to known reference wavelengths.
A polynomial relation
is fitted between detector pixel coordinate
Calibration quality is evaluated through:
- RMS residual in nanometres;
- RMS residual in detector pixels;
- maximum wavelength residual;
- local spectral dispersion.
For an isolated spectral line, the measured resolving power is estimated from:
where
This allows direct comparison between analytical predictions and experimental performance.
The Zemax merit functions complement the MATLAB first-order calculations.
The collimator merit function includes:
- effective focal-length constraints;
- throughput constraints;
- angular aberration minimization.
Angular aberration operands are used because the main objective of the collimator is to produce a well-collimated output beam.
The full spectrograph merit function includes:
- subsystem focal-length constraints;
- throughput requirements;
- RMS transverse aberration optimization at the detector plane.
This allows the first-order geometry obtained in MATLAB to be refined using full ray tracing.
The toolkit can be used for:
- astronomical spectrograph sizing;
- integral field spectrograph design;
- fibre-fed spectroscopy;
- detector selection and sampling analysis;
- diffraction-performance budgeting;
- fibre-crosstalk estimation;
- Zemax optimization;
- laboratory spectrograph characterization;
- wavelength calibration and spectral-resolution measurements.
- VPH Grating Design β Efficiency calculations and Bragg-condition optimization.
- Tolerance Analysis β Sensitivity to manufacturing and alignment errors.
- Additional Zemax Tools β Multi-configuration and automated optimization utilities.
This toolkit is available under the MIT License for academic and research use.
See the LICENSE file for details.
The tools in this repository were developed during MSc thesis work on:
βDevelopment of an Integral Field Spectrograph for Exoplanet Scienceβ at Politecnico di Milano and INAF β Osservatorio Astronomico di Brera.