Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Implementation of Fresnel Diffraction in MatLab

  1. May 22, 2015 #1
    I'm trying to simulate the Fresnel Diffraction in MatLab using the Fast Fourier Transform syntax. But I'm not getting really good diffraction patterns. Here is the code:

    %% Fourier Transform for G(p, q)
    g = layer.*exp(((1i*pi)/(lambda*z))*(r_obj));
    G = fftshift(fft2(g));

    %% Fourier Transform for H(p, q)
    h = (exp(1i*k*z)/(1i*lambda*z))*exp(((1i*k)/(2*z))*(r_img));
    H = fftshift(fft2(h));

    U = fftshift(ifft2(H.*G));

    And these are the value for r_obj and r_img:
    r_obj = ones(size(layer));
    r_img = ones(size(layer));
    for j = 1: obj_size(2);
    for i = 1: obj_size(1);
    r_obj(i, j) = x_prime(i)^2 + y_prime(j)^2;
    r_img(i, j) = x(i)^2 + y(j)^2;

    I don't know what's wrong with my code (or with my equations).
  2. jcsd
  3. May 26, 2015 #2


    User Avatar
    Gold Member

    I recommend posting a code snippet that can run. The first thing I tried to do was run the code you posted, and then I realized none of the variables are defined. I'm sure you have them defined in your script, so just post them here as well so that the code can be copy/pasted to run.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook