基于MATLAB的光学系统像差仿真实现

一、像差建模与仿真框架

光学像差仿真需结合几何光学与波动光学原理,以下为关键模块:

1. Zernike多项式建模

Zernike多项式是描述光学像差的核心工具,其数学表达式为:

\(Z_n^m(ρ,θ)=R_n^m(ρ)e^{imθ}\)

其中,径向多项式 Rnm(ρ)定义如下:

  • 球差:对应 \(Z_4^0\)
  • 彗差:对应 \(Z_3^1\)\(Z_3^{−1}\)
  • 像散:对应 \(Z_4^{±2}\)
  • 场曲:对应 \(Z_4^0\)的高阶项

MATLAB实现代码

function Z = zernike(n, m, rho, theta)
    % 递归计算径向多项式
    if m == 0
        R = legendreP(n, 2*rho.^2 - 1);
    else
        R = (2*n-1)*rho.*zernike(n-1, m, rho, theta) - (n+m-1)*zernike(n-2, m, rho, theta);
    end
    Z = R .* exp(1i*m*theta);
end
2. 光线追迹与波前计算

基于近轴光学公式和光线追迹算法,模拟光线通过光学系统后的波前畸变:

function [x2, y2] = ray_tracing(x1, y1, theta1, n1, n2, R)
    % 单球面折射光线追迹
    sin_theta2 = (n1/n2)*sin(theta1);
    theta2 = asin(sin_theta2);
    x2 = x1 + (y1*(1 - (n1/n2)*(1 - cos(theta1))))/cos(theta1);
    y2 = y1 + (x2 - x1)*tan(theta2);
end

二、像差仿真实现

1. 单色像差仿真
  • 球差仿真

    % 参数设置
    n = 4; m = 0;  % Z4^0对应球差
    rho = linspace(0, 1, 100);
    theta = linspace(0, 2*pi, 100);
    [Rho, Theta] = meshgrid(rho, theta);
    Z = zernike(n, m, Rho, Theta);
    
    % 波前误差可视化
    figure;
    surf(Rho.*cos(Theta), Rho.*sin(Theta), real(Z));
    title('球差波前分布');
    xlabel('X'); ylabel('Y'); zlabel('波前误差');
    
  • 彗差仿真

    % 组合Z3^1和Z3^-1
    Z3_1 = zernike(3, 1, rho, theta);
    Z3_-1 = zernike(3, -1, rho, theta);
    coma = Z3_1 + Z3_-1;
    
    % 光路图绘制
    figure;
    quiver(x, y, real(coma), imag(coma));
    title('彗差光路图');
    
2. 色差仿真

通过多波长叠加模拟轴向色差:

lambda = [0.486, 0.546, 0.656](@ref);  % 蓝、绿、红光波长
focal_length = 100;  % 焦距(mm)
colors = hsv(length(lambda));
figure;
hold on;
for i = 1:length(lambda)
    [x, y] = focal_spot(lambda(i), focal_length);
    plot(x, y, 'Color', colors(i,:));
end
title('色差弥散斑');
hold off;

三、高级功能模块

1. 相位屏模拟

生成随机相位屏模拟大气湍流:

function screen = phase_screen(N, D, r0)
    % N: 屏幕尺寸; D: 直径; r0: 湍流尺度
    x = linspace(-D/2, D/2, N);
    [X, Y] = meshgrid(x, x);
    rho = sqrt(X.^2 + Y.^2);
    screen = exp(1i * 2*pi * (rho.^2)/(lambda*2*r0));
end
2. 像差校正仿真

通过双胶合透镜校正球差:

% 双胶合透镜参数
R1 = 100; R2 = -50; R3 = 80;  % 曲率半径(mm)
n1 = 1.5; n2 = 1.6; n3 = 1.5; % 折射率

% 波前误差对比
[wavefront_before, wavefront_after] = correct_spherical_aberration(R1, R2, R3, n1, n2, n3);
figure;
subplot(1,2,1); surf(wavefront_before); title('校正前');
subplot(1,2,2); surf(wavefront_after); title('校正后');

参考代码 利用matlab实现光学系统像差仿真 www.youwenfan.com/contentcnq/65946.html

四、可视化与分析工具

1. 三维波前显示
% 生成球差波前
[x, y] = meshgrid(linspace(-1,1,500));
z = sqrt(1 - x.^2 - y.^2) + 0.1*sin(5*pi*x).*cos(3*pi*y); % 球差扰动

% 绘制三维曲面
figure;
surf(x, y, z);
shading interp;
xlabel('X'); ylabel('Y'); zlabel('光轴方向位移(mm)');
2. 点列图与Ray Fan图
% 生成点列图
num_rays = 1000;
heights = linspace(-10,10,100);  % 入射高度(mm)
[x_spot, y_spot] = ray_bundle(heights, 100);  % 100mm焦距

% 绘制Ray Fan图
figure;
plot(heights, x_spot, 'b.', heights, y_spot, 'r.');
xlabel('入射高度(mm)');
ylabel('像面偏移(mm)');
legend('X方向', 'Y方向');

五、完整仿真流程示例

  1. 输入参数

    lambda = 0.55e-3;  % 波长(mm)
    aperture = 25;     % 孔径(mm)
    focal_length = 100; % 焦距(mm)
    
  2. 生成像差

    aberration = 0.1*zernike(4,0,rho,theta);  % 球差系数0.1
    
  3. 光线追迹

    [x2, y2] = ray_tracing_system(aberration, num_rays);
    
  4. 结果分析

    rms_error = sqrt(mean(aberration(:).^2));  % RMS误差
    strehl_ratio = exp(-(2*pi*rms_error)^2);   % Strehl比率
    

六、工程应用扩展

  1. 自适应光学校正

    % 基于Zernike系数的波前重构
    [Z_coeff, ~] = zernike_decompose(wavefront);
    corrected_wavefront = wavefront - Z_coeff*actuator_response;
    
  2. 多通道并行仿真

    parpool(4);  % 启动并行计算
    results = cellfun(@(lambda) simulate_aberration(lambda), lambdas, 'UniformOutput', false);
    
posted @ 2026-01-22 16:55  康帅服  阅读(2)  评论(0)    收藏  举报