MATLAB Answers

Point Spread Function of an optical system

317 views (last 30 days)
Vanessa
Vanessa on 6 Jun 2017
Answered: Tilkesh on 15 Jan 2020
Hi all,
I need to estimate the PSF of an optical system. I have all the parameters and have been following an excellent code that was mentioned in the 'Spherical aberration and Chromatic aberration' question ( https://de.mathworks.com/matlabcentral/answers/36064-spherical-aberration-and-chromatic-aberration ). I am trying to model the PSF of an optical system and then apply it to an image to see how blurry the image would be.
Everything works great but the only problem is the pixel sampling. With the code I am having trouble with the psf_sampling. My psf_sampling is larger (10e-6) and every time I run the code I get the following error:
'Sampling is not sufficient to reconstruct the entire wavefront.'
Please help me with this, much appreciated.
Kind regards,
Vanessa
%%Define parameters
clear all;close all;
psf_sampling = 0.5e-6;%focal plane sampling in meters
lambda = 0.6328e-6;%wavelength in meters
N = 256;
aperture_diameter = 0.0254;%meters; 1 inch
focal_length = 5*aperture_diameter;%meters
RMS_SA = 0.25;%RMS spherical aberration content in waves
%%Calculate pupil plane sampling
delta_fx = 1/(psf_sampling*N);
x_pupil = (-fix(N/2):fix((N-1)/2)) * delta_fx * lambda * focal_length;
[X_pupil,Y_pupil] = meshgrid(x_pupil);
R_pupil = sqrt(X_pupil.^2 + Y_pupil.^2);
R_norm = R_pupil/(aperture_diameter/2);%Pupil normalized to aperture diameter
assert(max(R_norm(:))>=sqrt(2),'Sampling is not sufficient to reconstruct the entire wavefront.');
%%Create wavefront
W = RMS_SA * sqrt(5) * (6*R_norm.^4 - 6*R_norm.^2 + 1);%Spherical Aberration wavefront
W(R_norm>1) = 0;
E = exp(1i*2*pi*W);%Complex amplitude
E(R_norm>1) = 0;%Impose aperture size
figure;imagesc(angle(E)/(2*pi));colorbar;title('Wavefront Phase (waves)');
%%Create point-spread function
psf = abs(fftshift(fft2(ifftshift(E)))).^2;
psf = psf/sum(psf(:));%Normalize to unity energy
x_psf = (-fix(N/2):fix((N-1)/2)) * psf_sampling;
figure;imagesc(x_psf*1e6,x_psf*1e6,psf);
title(sprintf('PSF with %.4f waves RMS of Spherical Aberration', RMS_SA));
xlabel(sprintf('Position (\\mum)'));
ylabel(sprintf('Position (\\mum)'));

Answers (3)

Eric
Eric on 20 Jun 2017
Sorry, I was out on vacation for a couple weeks, then I posted to
Here's that response:
The assert statement is checking that the sampling allows reconstruction of the entire wavefront. If this assertion fails, then the pupil sampling is such that you cannot reconstruct the entirety of the wavefront area. This can happen if the pixel pitch is relatively large. Assuming you don’t want to adjust the aperture diameter, you need to increase the values in R_norm.
For instance, if I set the psf_sampling to 10e-6 meters, the code from the page results in max(R_norm(:)) of 0.4475.
A simple fix is to calculate the PSF at a finer resolution and then bin that PSF to the desired low-resolution. So for the case where you want a PSF sampling of 10 microns, you could calculate the PSF at a sampling of 2.0 microns. Calculate the psf as shown in the script. Then do the following:
kernel = ones(5,5)/5^2;
psf_lowres_all = conv2(psf, kernel, 'same');
psf_lowres = psf_lowres_all(3:5:end,3:5:end);
In this case you’re doing convolution to spatially sum 5x5 neighborhoods of the high-resolution PSF (5 is the correct value because it’s the ratio of the desired low-resolution pixel spacing to the calculated spacing). This convolution produces 25 possible low-resolution PSFs, each at a different registration of the optical PSF to the pixel grid. In the last line I’ve selected the one in the middle. In the indexing you skip by 5 because you want to get sums of adjacent blocks (i.e., not sliding blocks). You can change the indexing to select another possible low-resolution PSF. For instance, you could also use
psf_lowres = psf_lowres_all(1:5:end,4:5:end);
to select another PSF.
You’ll notice when this is done that the wavefront calculation area is zero-padded to be larger than the specified system aperture. You can check this by plotting abs(E).
  3 Comments
Vanessa
Vanessa on 20 Jun 2017
Thank you so much Eric!!! I really appreciate this, it will definetly help with my thesis! I also hope you had a good vocation!

Sign in to comment.


Image Analyst
Image Analyst on 6 Jun 2017
Decrease psf_sampling back to the range where it is valid. If you sample the PSF too coarsely, you're not going to be able to get it's shape at all.
  6 Comments
Eric
Eric on 20 Jun 2017
If you comment out the assert statement, you'll get poor results. You will reconstruct a wavefront that is smaller than the aperture of your system.

Sign in to comment.


Tilkesh
Tilkesh on 15 Jan 2020
If we just take thin lens function to find the PSF then this code does not work. (No aberrations simple lens equation)
For any simple lens with diameter=25mm, focal lengh=100mm. How to determine sampling for this code. What is the criteria? I choose Q>2 as mentioned by author still this code does not work.
If we want to find the Airy disc diameter from this code then it should be independent of PSF sampling and should only depend on wavelength and aperture diameter but it does not work why? I am unable to find it. Is it the physical problem of computentional or both still not clear to me. Please help for the benifit of many many reserachers.
%%Define parameters
clear all;close all;
psf_sampling = 0.5e-6;%focal plane sampling in meters
lambda = 0.6328e-6;%wavelength in meters
N = 256;
aperture_diameter = 0.0254;%meters; 1 inch
focal_lengt%%Define parameters
clear all;close all;clc;
psf_sampling = .01e-6;%focal plane sampling in meters
lambda = 0.6328e-6;%wavelength in meters
N = 256;
aperture_diameter = 0.0254;%meters; 1 inch
focal_length = 5*aperture_diameter;%meters
RMS_SA = 0.25;%RMS spherical aberration content in waves
%%Calculate pupil plane sampling
delta_fx = 1/(psf_sampling*N);
x_pupil = (-fix(N/2):fix((N-1)/2)) * delta_fx * lambda * focal_length;
[X_pupil,Y_pupil] = meshgrid(x_pupil);
R_pupil = sqrt(X_pupil.^2 + Y_pupil.^2);
R_norm = R_pupil/(aperture_diameter/2);%Pupil normalized to aperture diameter
assert(max(R_norm(:))>=sqrt(2),'Sampling is not sufficient to reconstruct the entire wavefront.');
%%Create wavefront
W =(-(2*pi/(lambda*focal_length))*((X_pupil.^2 + Y_pupil.^2)));
E = exp(1i*W);%Complex amplitude
figure;imagesc(angle(E)/(2*pi));colorbar;title('Wavefront Phase (waves)');
%%Create point-spread function
psf = abs(fftshift(fft2(ifftshift(E)))).^2;
psf = psf/sum(psf(:));%Normalize to unity energy
x_psf = (-fix(N/2):fix((N-1)/2)) * psf_sampling;
figure;imagesc(x_psf*1e6,x_psf*1e6,psf);
title(sprintf('PSF with %.4f waves RMS of Spherical Aberration', RMS_SA));
xlabel(sprintf('Position (\\mum)'));
ylabel(sprintf('Position (\\mum)'));
Q=(lambda*focal_length)./(aperture_diameter*psf_sampling)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!