]> Creatis software - CreaPhase.git/blob - utilities_LW/FresnelTransform_2D.m
Useful functions for simulations (created by LW, free to use)
[CreaPhase.git] / utilities_LW / FresnelTransform_2D.m
1 ## Copyright (C) 2015 Loriane Weber
2 ## 
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 3 of the License, or
6 ## (at your option) any later version.
7 ## 
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 ## GNU General Public License for more details.
12 ## 
13 ## You should have received a copy of the GNU General Public License
14 ## along with Octave; see the file COPYING.  If not, see
15 ## <http://www.gnu.org/licenses/>.
16
17 ## FresnelTransform
18
19 ## Author: Loriane Weber <lweber@hpc2-0601>
20 ## Created: 2015-07-01
21
22
23 function Id = FresnelTransform_2D(ph, B, D, lambda, oversamp, ftot, gtot)
24
25 [m, n]=size(ph);
26 [m_a, n_a] = size(B);
27
28 % check dimensions 
29 if (m_a != m || n_a != n)
30         disp('error in the dimensions !! Phi and B should have the same dimension')
31 return;
32 end
33
34 u = exp(-B).*exp(+i.*ph);
35     
36 % propagator for the distance D
37 Pd = exp(-i*pi*lambda*D*(ftot.^2+gtot.^2));  % ifftshift
38 ud = ones(2*m, 2*n);
39 ud(1:m,1:n) = u;
40
41 ud=fft2(ud);
42
43 ud = ud.*(Pd)';
44 ud = ifft2(ud); 
45
46 ud = ud(1:m,1:n);
47 Id = abs(ud).^2;
48         
49         if oversamp==2
50                 ipf = [0.25 0.5 0.25;
51                            0.50 1.0 0.50;
52                            0.25 0.5 0.25];
53                 Idd = conv2(Id,ipf,'same')./conv2(ones(size(Id)),ipf,'same');
54                 Idd = Idd(oversamp:oversamp:end, oversamp:oversamp:end);
55                 Id=Idd;
56         elseif oversamp ==4
57    
58                 ipf = [0.25 0.5 0.5 0.5 0.25;
59                            0.50 1.0 1.0 1.0 0.50;
60                            0.50 1.0 1.0 1.0 0.50;
61                            0.50 1.0 1.0 1.0 0.50;
62                            0.25 0.5 0.5 0.5 0.25];
63                 Idd = conv2(Id,ipf,'same')./conv2(ones(size(Id)),ipf,'same');
64                 Idd = Idd(oversamp:oversamp:end, oversamp:oversamp:end);
65                 Id=Idd;
66         end % end binning detector
67          
68 endfunction