Hey everyone,
I've been working on this code based on Chapter 5 of the book 'Numerical Simulation of Optical Wave Propagation with Examples in MATLAB'. It's about imaging systems. I wanted to represent defocus aberration, and I came up with the following code. I didn't use the 'zernike.m' and 'zernike.index' files like in the book. I kept it simple and just used the expression for the defocus mode z(0,2). < 2*r^.2-1
Here's the code:
[x, y] = meshgrid((-N/2 : N/2-1) * delta);
[theta, r] = cart2pol(x, y);
W = 0.05 * sqrt(3)*(2*r.^2-1);
P = circ(x, y, D).* exp(-1i * 2*pi * W);
[u, v] = meshgrid((-N/2 : N/2-1) * U);
obj = (rect((u-1.4e-4)/5e-5) + rect(u/5e-5)+ rect((u+1.4e-4)/5e-5)) .* rect(v/2e-4);
img = myconv2(abs(obj).^2, PSF, 1);
psf_img = psf_img / max(psf_img(:));
title('Point Spread Function (PSF)');
title('Simulated Image');
>> Code used for performing convolution
function C = myconv2(A, B, delta)
C = ift2(ft2(A, delta) .* ft2(B, delta), 1/(N*delta));
>> Code used for Fourier transform
function G = ft2(g, delta)
G = fftshift(fft2(fftshift(g))) * delta^2;
>> Code used for inverse Fourier transform
function g = ift2(G, delta_f)
g = ifftshift(ifft2(ifftshift(G))) * (N * delta_f)^2;
>> Code used to create the amplitude function
function z = circ(x, y, D)
>> Code used for generating the object
if nargin == 1, D = 1; end
So, my question is, in the original book's code, changing the constants in N, L, D, delta, wvl, z, and W should affect the blurriness of the image. But for me, changing the constant in the W equation (like, say, 0.2 or 1) doesn't seem to influence the blur and the PSF's shape. The other values do affect the result, but not this W equation's constant value.
Can anyone point out where the issue might be in my code? I've attached the relevant parts of the code I'm using.