感谢你的反馈。我们可以进一步修正代码,以确保微透镜阵列包含完整的64个透镜,并在四个边缘预留20微米的空间。另外,我会重新加入焦点处的强度图模拟。
下面是经过调整的代码:
- % Parameters
- microlens_diameter = 50e-6; % 50 micrometers
- microlens_spacing = 10e-6; % 10 micrometers
- focal_length = 300e-6; % 300 micrometers
- curvature_radius = 2.1e-3; % 2.1 micrometers (converted to mm for better scaling)
- wavelength = 1000e-9; % 1000 nm
- array_size = 64; % 64x64 microlens array
- points_per_lens = 100; % Sampling points per microlens
- edge_margin = 20e-6; % 20 micrometers on each edge
- % Grid dimensions for simulation
- individual_lens_size = microlens_diameter + microlens_spacing;
- grid_points = round(array_size * points_per_lens * (individual_lens_size + 2 * edge_margin) / individual_lens_size);
- % Create mesh grid for the shape of a single microlens
- [x, y] = meshgrid(linspace(-microlens_diameter/2, microlens_diameter/2, points_per_lens));
- % Calculate the surface profile of a single microlens
- R = curvature_radius;
- z_single = R - sqrt(R^2 - x.^2 - y.^2);
- z_single(x.^2 + y.^2 > (microlens_diameter/2)^2) = 0; % Mask out areas outside the lens
- % Initialize the entire microlens array
- z_array = zeros(grid_points);
- % Calculate actual grid size including margins
- actual_grid_size = array_size * individual_lens_size + 2 * edge_margin;
- % Fill the microlens array with individual microlens profiles
- for i = 0:(array_size-1)
- for j = 0:(array_size-1)
- % Calculate position for each microlens in the array
- x_offset = round(edge_margin + i * individual_lens_size) * points_per_lens / microlens_diameter;
- y_offset = round(edge_margin + j * individual_lens_size) * points_per_lens / microlens_diameter;
-
- z_array(x_offset+1:x_offset+points_per_lens, y_offset+1:y_offset+points_per_lens) = ...
- max(z_array(x_offset+1:x_offset+points_per_lens, y_offset+1:y_offset+points_per_lens), z_single);
- end
- end
- % Plot microlens array surface
- figure;
- surf(linspace(-actual_grid_size/2, actual_grid_size/2, grid_points)*1e6, ...
- linspace(-actual_grid_size/2, actual_grid_size/2, grid_points)*1e6, z_array*1e6);
- title('Microlens Array Surface Profile');
- xlabel('X (micrometers)');
- ylabel('Y (micrometers)');
- zlabel('Height (micrometers)');
- shading interp;
- axis tight;
- colormap jet;
- view(3);
- % Simulate the diffraction pattern at the focal plane
- k = 2*pi / wavelength;
- [X, Y] = meshgrid(linspace(-actual_grid_size/2, actual_grid_size/2, grid_points));
- lens_phase = exp(-1j * k/(2*focal_length) * (X.^2 + Y.^2));
- field_at_lens = lens_phase .* exp(-1j*k*z_array); % Initial field passing through the lens
- % FFT to compute the field at the focal plane
- Eout = fftshift(fft2(ifftshift(field_at_lens)));
- intensity_pattern = abs(Eout).^2;
- % Normalize intensity
- intensity_pattern = intensity_pattern / max(intensity_pattern(:));
- % Plot intensity pattern at the focal plane
- figure;
- imagesc(linspace(-actual_grid_size/2, actual_grid_size/2, grid_points)*1e6, ...
- linspace(-actual_grid_size/2, actual_grid_size/2, grid_points)*1e6, intensity_pattern);
- title('Intensity Pattern at Focal Plane');
- xlabel('X (micrometers)');
- ylabel('Y (micrometers)');
- colormap hot;
- colorbar;
- axis equal tight;
复制代码
### 修正和增强的要点:
1. **边缘预留**:在计算阵列尺寸时,包括了20微米的边缘预留,这样整个阵列能正确地显示出来。
2. **微透镜阵列填充**:通过调整偏移量,确保准确放置64×64个透镜。
3. **衍射图案的恢复**:重新加入了模拟激光通过微透镜后的强度图部分。
现在这个代码应该能够更准确地展示微透镜阵列及其聚焦效果。
--- 光学专家Gpt |