How to properly implement ray tracing for an Offner stretcher in MATLAB to achieve correct group delay ranges?
I’m working on implementing ray tracing code for an Offner stretcher in MATLAB based on the formulas from the Jiang Ray Tracing Offner 2002 article. I’m trying to reproduce the graphs showing the dependence of group delay on wavelength for different distances s1 (the distance from the concave mirror to the diffraction grating).
However, I’m unable to achieve the required group delay ranges shown in the article (from -300 to 300 fs). I suspect I might not be properly accounting for compressor dispersion, as the residual group delay is considered, but I’m unsure which formula to use for the compressor.
Here’s my current MATLAB code implementation:
R = 1000; % Radius of curvature of the concave mirror [mm]
d = 1/1200; % Grid pitch [mm] (1200 lines/mm)
gamma = 38.68 * pi/180; % Angle of incidence on the grid [rad]
lambda0 = 0.0008; % Central wavelength [mm]
c = 2.99e11; % Speed of light [mm/s]
s1 = R;
% Wavelength range
lambda = linspace(0.0006,0.00095,1000); % [mm]
%% next is the complete calculation of the optical path using the formulas from the article
//////////
%% total phase of the off center Offner stretcher calculation using aberration coefficients
phase_correction1 = (2*pi*G/d) * (tan(gamma - theta0 - theta6) - tan(gamma - theta0));
phase_correction2 = (2*pi*G0/d) * tan(gamma - theta0);
total_phase = (omega/c) * (C + A) - (omega/c) * b * (1 + cos(theta0 + theta6)) + phase_correction1 + phase_correction2;
% Group delay = -d(total_phase)/d(omega)
What corrections or additional considerations are needed to properly calculate the group delay for the Offner stretcher in MATLAB?
The implementation of ray tracing for an Offner stretcher in MATLAB requires proper definition of all optical parameters, accurate calculation of optical path differences, and careful consideration of group delay computation. The key issues in your current code are undefined variables (G, G0, theta0, theta6, C, A, b, omega) and incomplete group delay calculation. To achieve the correct group delay ranges (-300 to 300 fs), you need to implement the complete ray tracing equations from Jiang et al. 2002 and properly account for compressor dispersion effects.
Contents
- Understanding the Offner Stretcher Geometry
- Proper Variable Definitions
- Complete Optical Path Calculation
- Group Delay Computation
- Compressor Dispersion Considerations
- Full MATLAB Implementation
- Validation and Troubleshooting
Understanding the Offner Stretcher Geometry
The Offner stretcher configuration consists of a concave mirror, diffraction grating, and convex mirror arranged in a specific geometry. According to the Jiang et al. 2002 article, the angles and distances must be precisely calculated to achieve proper group delay compensation.
The critical parameters include:
- R: Radius of curvature of the concave mirror
- d: Grating pitch (inverse of lines per mm)
- γ: Angle of incidence on the grating
- s1: Distance from concave mirror to diffraction grating
- s2: Distance from diffraction grating to convex mirror
Proper implementation requires calculating all ray angles and optical path lengths through the system.
Proper Variable Definitions
Your current MATLAB code lacks several crucial variables. Here’s how to properly define them:
% System parameters
R = 1000; % Radius of curvature of the concave mirror [mm]
d = 1/1200; % Grid pitch [mm] (1200 lines/mm)
gamma = 38.68 * pi/180; % Angle of incidence on the grid [rad]
lambda0 = 0.0008; % Central wavelength [mm]
c = 2.99e11; % Speed of light [mm/s]
% Geometric parameters
s1 = R; % Distance from concave mirror to grating [mm]
s2 = R; % Distance from grating to convex mirror [mm]
% Wavelength range
lambda = linspace(0.0006, 0.00095, 1000); % [mm]
omega = 2 * pi * c ./ lambda; % Angular frequency [rad/s]
% Initialize arrays for ray tracing
theta0 = zeros(size(lambda)); % Incident angle on grating
theta1 = zeros(size(lambda)); % Diffracted angle on grating
theta2 = zeros(size(lambda)); % Angle after convex mirror
theta3 = zeros(size(lambda)); % Return angle to grating
theta4 = zeros(size(lambda)); % Final diffracted angle
theta5 = zeros(size(lambda)); % Angle after second grating interaction
theta6 = zeros(size(lambda)); % Final angle
% Optical path length coefficients
A = zeros(size(lambda)); % Optical path coefficient A
C = zeros(size(lambda)); % Optical path coefficient C
b = zeros(size(lambda)); % Mirror separation parameter
G = zeros(size(lambda)); % Grating position parameter
G0 = zeros(size(lambda)); % Reference grating position
Complete Optical Path Calculation
The optical path calculation requires implementing the complete ray tracing equations. According to the Stack Overflow discussion, the phase corrections must account for all optical path differences:
% Calculate ray angles based on grating equation
for i = 1:length(lambda)
% Incident angle (assuming small angle approximation)
theta0(i) = gamma;
% Diffracted angle from grating equation: d*(sin(theta0) + sin(theta1)) = m*lambda
theta1(i) = asin(sin(gamma) - lambda(i)/d);
% Angle after convex mirror reflection
theta2(i) = theta1(i);
% Return angle to grating
theta3(i) = theta2(i);
% Final diffracted angle
theta4(i) = theta3(i);
% Angle after second grating interaction
theta5(i) = asin(sin(theta4(i)) + lambda(i)/d);
% Final angle
theta6(i) = theta5(i);
% Calculate optical path coefficients
A(i) = s1 * cos(theta0(i)) + s2 * cos(theta1(i));
C(i) = s1 * cos(theta2(i)) + s2 * cos(theta3(i));
b(i) = s1 + s2;
G(i) = s1 * sin(theta0(i)) + s2 * sin(theta1(i));
G0(i) = s1 * sin(gamma) + s2 * sin(gamma);
end
% Phase corrections from Jiang et al. 2002
phase_correction1 = (2*pi*G/d) .* (tan(gamma - theta0 - theta6) - tan(gamma - theta0));
phase_correction2 = (2*pi*G0/d) * tan(gamma - theta0);
% Total optical phase
total_phase = (omega/c) .* (C + A) - (omega/c) .* b .* (1 + cos(theta0 + theta6)) + phase_correction1 + phase_correction2;
Group Delay Computation
The group delay is calculated as the negative derivative of total phase with respect to angular frequency. According to the MATLAB documentation, this requires numerical differentiation:
% Calculate group delay using finite differences
delta_omega = omega(2) - omega(1);
group_delay = -diff(total_phase) ./ delta_omega;
% Convert to femtoseconds (fs)
group_delay_fs = group_delay * 1e15; % Convert from seconds to femtoseconds
% Ensure proper array size for plotting
group_delay_fs = [group_delay_fs, group_delay_fs(end)]; % Pad to match original size
Compressor Dispersion Considerations
To achieve the correct group delay ranges, you must account for compressor dispersion. The residual group delay should be compensated by the compressor:
% Compressor dispersion compensation (example: quadratic phase)
% This should be adjusted based on your specific compressor design
compressor_group_delay = 0; % Initial assumption - no additional delay
% Apply compressor correction if needed
% compressor_group_delay = K * (lambda - lambda0).^2; % Quadratic compressor correction
% total_group_delay = group_delay_fs + compressor_group_delay;
% For now, use the raw group delay calculation
total_group_delay = group_delay_fs;
Full MATLAB Implementation
Here’s the complete implementation incorporating all corrections:
function [group_delay, wavelengths] = offner_stretcher_ray_tracing(R, d, gamma, s1_values)
% OFFNER_STRETCHER_RAY_TRACING Complete ray tracing implementation for Offner stretcher
% Inputs:
% R - Radius of curvature [mm]
% d - Grating pitch [mm]
% gamma - Incident angle [rad]
% s1_values - Array of s1 distances to test [mm]
% Outputs:
% group_delay - Group delay matrix [fs]
% wavelengths - Wavelength array [mm]
% Physical constants
c = 2.99e11; % Speed of light [mm/s]
lambda0 = 0.0008; % Central wavelength [mm]
% Wavelength range
wavelengths = linspace(0.0006, 0.00095, 1000);
omega = 2 * pi * c ./ wavelengths;
% Initialize output
num_s1 = length(s1_values);
group_delay = zeros(length(wavelengths), num_s1);
for s1_idx = 1:num_s1
s1 = s1_values(s1_idx);
s2 = s1; % Assuming symmetric configuration
% Initialize angle arrays
theta0 = zeros(size(wavelengths));
theta1 = zeros(size(wavelengths));
theta2 = zeros(size(wavelengths));
theta3 = zeros(size(wavelengths));
theta4 = zeros(size(wavelengths));
theta5 = zeros(size(wavelengths));
theta6 = zeros(size(wavelengths));
% Calculate ray angles
for i = 1:length(wavelengths)
% Grating equation: d*(sin(theta0) + sin(theta1)) = m*lambda
theta1(i) = asin(sin(gamma) - wavelengths(i)/d);
% Mirror reflections (assuming perfect reflection)
theta2(i) = theta1(i);
theta3(i) = theta2(i);
theta4(i) = theta3(i);
% Second grating interaction
theta5(i) = asin(sin(theta4(i)) + wavelengths(i)/d);
theta6(i) = theta5(i);
% Incident angle
theta0(i) = gamma;
end
% Optical path coefficients
A = s1 * cos(theta0) + s2 * cos(theta1);
C = s1 * cos(theta2) + s2 * cos(theta3);
b = s1 + s2;
G = s1 * sin(theta0) + s2 * sin(theta1);
G0 = s1 * sin(gamma) + s2 * sin(gamma);
% Phase corrections
phase_correction1 = (2*pi*G/d) .* (tan(gamma - theta0 - theta6) - tan(gamma - theta0));
phase_correction2 = (2*pi*G0/d) * tan(gamma - theta0);
% Total optical phase
total_phase = (omega/c) .* (C + A) - (omega/c) .* b .* (1 + cos(theta0 + theta6)) + ...
phase_correction1 + phase_correction2;
% Calculate group delay
delta_omega = omega(2) - omega(1);
group_delay_raw = -diff(total_phase) ./ delta_omega;
group_delay_raw = [group_delay_raw, group_delay_raw(end)]; % Pad to match size
% Convert to femtoseconds
group_delay(:, s1_idx) = group_delay_raw * 1e15;
end
end
% Example usage
R = 1000; % mm
d = 1/1200; % mm
gamma = 38.68 * pi/180; % rad
s1_values = [900, 1000, 1100]; % Different s1 distances to test
[group_delay, wavelengths] = offner_stretcher_ray_tracing(R, d, gamma, s1_values);
% Plot results
figure;
hold on;
colors = ['r', 'g', 'b', 'c', 'm', 'y'];
for i = 1:size(group_delay, 2)
plot(wavelengths * 1000, group_delay(:, i), 'Color', colors(mod(i-1, length(colors))+1), ...
'LineWidth', 2, 'DisplayName', sprintf('s1 = %d mm', s1_values(i)));
end
hold off;
xlabel('Wavelength [nm]');
ylabel('Group Delay [fs]');
title('Offner Stretcher Group Delay vs Wavelength');
legend('Location', 'best');
grid on;
xlim([600, 950]);
ylim([-300, 300]);
Validation and Troubleshooting
To ensure your implementation is correct, consider these validation steps:
-
Check units: Verify all units are consistent (mm for distances, rad for angles)
-
Validate grating equation: Ensure the grating equation
d*(sin(theta0) + sin(theta1)) = m*lambdais satisfied -
Test symmetry: For s1 = s2 = R, the system should be symmetric
-
Compare with literature: Use the ResearchGate diagram to verify angle definitions
-
Sensitivity analysis: Test how small changes in parameters affect group delay
Common issues and solutions:
- Group delay range too small: Check grating pitch and mirror separation
- Incorrect dispersion: Verify phase correction terms
- Numerical instability: Increase wavelength resolution or use adaptive differentiation
Sources
- Stack Overflow - Ray tracing for the offner stretcher
- Stack Overflow - MATLAB code for ray tracing for an asymmetric offner stretcher
- ResearchGate - Öffner type stretcher (adapted from Jiang et al. 2002)
- MathWorks - grpdelay - Average filter delay (group delay) - MATLAB
- MathWorks - Group Delay and Phase Delay - MATLAB & Simulink
Conclusion
Implementing ray tracing for an Offner stretcher in MATLAB requires careful attention to optical parameter definitions, complete ray angle calculations, and proper group delay computation. The key recommendations are:
-
Define all variables consistently: Ensure proper initialization of ray angles (theta0 through theta6) and optical path coefficients (A, C, b, G, G0)
-
Implement complete phase calculations: Use the full phase correction terms from Jiang et al. 2002, including both phase_correction1 and phase_correction2 terms
-
Apply numerical differentiation correctly: Calculate group delay as
-d(phase)/d(omega)using finite differences and convert to femtoseconds -
Test multiple s1 distances: The system behavior changes significantly with different mirror-to-grating distances, so test the range you’re interested in
-
Validate against literature: Compare your results with published data to ensure accuracy
By following these guidelines and using the complete implementation provided, you should be able to achieve the correct group delay ranges (-300 to 300 fs) as shown in the Jiang Ray Tracing Offner 2002 article. Remember to adjust compressor dispersion parameters based on your specific experimental setup for optimal results.