%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Class: Psych 221/EE 362
% File: ZernikePolynomial
% Author: Patrick Maeda
% Purpose: Calculate and Plot Zernike Polynomials
% Date: 03.03.03
%
% Matlab 6.1: 03.04.03
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This file calculates and plots the Zernike Polynomial specified by:
% n = highest power or order of the radial polynomial term, [a positive integer]
% m = azimuthal frequency of the sinusoidal component, [a signed integer]
% for a given n, m can take on the values -n, -n+2, -n+4,..., n-4, n-2, n
% d = pupil diameter = 2 for normalized pupil coordinates
%
% The Zernike Polynomial definitions used are derived from:
% Thibos, L., Applegate, R.A., Schweigerling, J.T., Webb, R., VSIA Standards Taskforce Members,
% "Standards for Reporting the Optical Aberrations of Eyes"
% OSA Trends in Optics and Photonics Vol. 35, Vision Science and its Applications,
% Lakshminarayanan,V. (ed) (Optical Society of America, Washington, DC 2000), pp: 232-244.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Zernike polynomial selection
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('Zernike Polynomial radial order n, azimuthal frequency m, and mode number j')
%n=4; %[INPUT] highest power or order of the radial polynomial term
%m=4 ; %[INPUT] azimuthal frequency of the sinusoidal component
N=50;
d=10;
r0=1.5;
[n,m]=Jx(N);
%n = [0 1 1 2 2 2 3 3 3 3 4 4 4 4 4];
%m = [0 1 -1 0 -2 2 -1 1 -3 3 0 2 -2 4 -4];
length_n=length(n);
length_m=length(m);
%j=0.5*(n*(n+2)+m); %mode number (0 to 36) from single indexing scheme
%d=250; %pupil diameter
%d=2;
PupilDiameter=d;
PupilRadius=d/2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set-up normalized x,y grid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xn=-5:0.05:5; %normalized x-coordinates
yn=-5:0.05:5; %normalized y-coordinates
%xn=-125:125;
%yn=-125:125;
z1=zeros(length(xn),length(yn));
a(1)=1;
a(2:length(n))=xs(n,m,d,r0);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute Zernike polynomial
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:length_n
for j=1:length_m
if i==j
z=a(i)*zernike(n(i),m(j),xn,yn,d);
z1=z1+z;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot Zernike polynomial
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure
% subplot(2,1,1)
z1=rot90(z1);
z1=flipud(z1);
imagesc(xn,yn,z1);
colormap gray
axis xy
axis square
%set(gca, 'TickDir', 'out')
title('Zernike Polynomial'); %(['Zernike Polynomial Z^{', num2str(m),'}_{', num2str(n),'}'],'FontSize', 10);
xlabel('Normalized x pupil coordinate');
ylabel('Normalized y pupil coordinate');
figure
% subplot(2,1,2)
mesh(xn,yn,z1)
%view(-37.5,45)
title('Zernike Polynomial Z^N');%(['Zernike Polynomial Z^{', num2str(m),'}_{', num2str(n),'}'],'FontSize', 10);
xlabel('Normalized x pupil coordinate');
ylabel('Normalized y pupil coordinate');
zlabel('Amplitude');
% colormap('default')
% colormap([0.8 0 0])
评论16