- % 定义输入参数
- wavelength = 266e-9; % 波长
- beam_radius = 0.01; % 光束半径
- filter_radius = 0.02; % 滤波片半径
- filter_thickness = 0.001; % 滤波片厚度
- filter_transmission = @(r) exp(-r.^2/(2*(filter_radius^2))); % 滤波片透过率函数
- % 定义空间网格
- Nx = 100; % 横向网格点数
- Ny = 100; % 纵向网格点数
- xmin = -0.02; % x方向最小值
- xmax = 0.02; % x方向最大值
- ymin = -0.02; % y方向最小值
- ymax = 0.02; % y方向最大值
- x = linspace(xmin, xmax, Nx);
- y = linspace(ymin, ymax, Ny);
- [X, Y] = meshgrid(x, y);
- % 初始化相位分布和光强分布
- phase_before = zeros(Nx, Ny);
- intensity_before = zeros(Nx, Ny);
- % 计算滤波片前的相位分布和光强分布
- for i = 1:Nx
- for j = 1:Ny
- r = sqrt(X(i,j)^2 + Y(i,j)^2);
- phase_before(i,j) = exp(1i*2*pi/wavelength*r);
- intensity_before(i,j) = abs(phase_before(i,j))^2;
- end
- end
- % 计算滤波片后的相位分布和光强分布
- phase_after = phase_before .* filter_transmission(sqrt(X.^2 + Y.^2));
- intensity_after = abs(phase_after).^2;
- % 绘制滤波片前后的彩色三维相位分布图
- figure;
- surf(X, Y, angle(phase_before), intensity_before, 'LineStyle', 'none');
- title('Phase Distribution Before Filter');
- xlabel('X');
- ylabel('Y');
- colorbar;
- figure;
- surf(X, Y, angle(phase_after), intensity_after, 'LineStyle', 'none');
- title('Phase Distribution After Filter');
- xlabel('X');
- ylabel('Y');
- colorbar;
- % 绘制滤波片前后的彩色三维光强分布图
- figure;
- surf(X, Y, intensity_before, 'LineStyle', 'none');
- title('Intensity Distribution Before Filter');
- xlabel('X');
- ylabel('Y');
- colorbar;
- figure;
- surf(X, Y, intensity_after, 'LineStyle', 'none');
- title('Intensity Distribution After Filter');
- xlabel('X');
- ylabel('Y');
- colorbar;
- % 计算滤波片前后的光强横截面图
- y_cross_section = Ny/2; % 取中心横截面
- intensity_before_cross_section = intensity_before(:, y_cross_section);
- intensity_after_cross_section = intensity_after(:, y_cross_section);
- % 绘制滤波片前后的光强横截面图
- figure;
- plot(x, intensity_before_cross_section, 'b-', 'LineWidth', 2);
- hold on;
- plot(x, intensity_after_cross_section, 'r--', 'LineWidth', 2);
- hold off;
- title('Intensity Cross Section');
- xlabel('X');
- ylabel('Intensity');
- legend('Before Filter', 'After Filter');
- % 计算滤波片前后的光束的空间能量分布图
- energy_before = sum(intensity_before(:));
- energy_after = sum(intensity_after(:));
- fprintf('Energy Before Filter: %.4f\n', energy_before);
- fprintf('Energy After Filter: %.4f\n', energy_after);
复制代码
这段代码会生成滤波片前后的彩色三维相位分布图、彩色三维光强分布图、光强横截面图,并打印出滤波片前后的光束的空间能量分布。你可以在MATLAB中运行这段代码,并根据需要进行绘图或调整参数。
--- 光学专家Gpt |