ExtendedDOFdemo.docx

advertisement
%FILE: ThruFocusEDOF.m
%Demonstrates extended depth of field
% for a cubic phase pupil
%
%Make the array 5 times the size of the pupil,
% for adequate PSF resolution:
Asize = 5;
N = 101; %Size of array;
x = linspace(-Asize,Asize,N);
[X,Y] = meshgrid(x,x);
R = sqrt(X.^2 + Y.^2);
%R is now an array with values equal to the distance
% from the center of the N x N array:
%Create a circular, uniform pupil:
P = zeros(N,N);
P(R<=1) = 1;
%
%Add cubic phase to the pupil:
Ac = 1.5; %Waves of cubic phase at edge of pupil
C = Ac*(X.^3 + Y.^3);
P = P.*exp(i*2*pi*C);
P(R>1) = 0; %Clip amplitude and phase to actual pupil size.
%
Defocus = -2:.5:2; %Array of defocus amounts to use on Pupil
%The defocus is in waves at the edge of the pupil:
NDefocus = length(Defocus);
%Calculate the psf through focus:
PSFs = zeros(N,N,1,NDefocus);
for ii = 1:NDefocus
DF = exp(i*2*pi*Defocus(ii)*R.^2);
DF(P==0) = 0; %Truncate to aperture
DP = P.*DF; %Defocus phase added to pupil
%Transform and square the pupil to get the PSF array:
psf = abs(fftshift(fft2(ifftshift(DP)))).^2;
%Normalize the psf:
psf = psf/max(max(psf));
PSFs(:,:,1,ii) = psf;
%Calculate the MTFs while we're at it:
%(We don't use 'fftshift', since we only want to extract
% a central slice, and that will be at the edge of the
% array before shifting.)
mtf = abs(fft2(psf));
mtf = mtf(1,1:20)';
mtf = mtf/max(mtf); %Normalize to 1.0
MTFs(:,ii) = mtf;
end
%
%Create a montage of the through-focus PSFs
figure
montage(PSFs)
title('-2\lambda : 0.5\lambda : 2\lambda Misfocus')
xlabel([num2str(Ac) ' \lambda cubic phase'])
%Plot the associated MTFs:
xm = linspace(0,1,length(mtf));
figure
for ii = 1:NDefocus
subplot(3,3,ii)
plot(xm,MTFs(:,ii))
title(['Defocus: ' num2str(Defocus(ii)) ' \lambda']);
end
Download