aboutsummaryrefslogtreecommitdiff
path: root/gbeam_propagation_froward_only.m
blob: 93fe2c7e6623b269f7b8ba45fc11844ce55e8575 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function q = gbeam_propagation_froward_only(x_pos, q_in, x_in,  optics_elements)
% calculate the 'q' parameter of the Gaussian beam propagating through optical
% 'optics_elements' only in the positive direction  along 'x' axis at points 'x_pos'
% takes the gaussian beam with initial q_in parameter at x_in
% Note!: if optics element position coinside with a x_pos at some place
%   the reported value will be the one calculated after the element
%   so the resulting value will coinside with submitted q_in
%
% all x_pos must be to the right of x_in
% x_pos must be monotonic!
	if (any(x_pos < x_in))
		error('all beam positions must be to the right of the x_in');
	end

	optics_elements=arrange_optics_along_x(optics_elements);

	% Forward propagation to the right of x_in
	q=0*x_pos; % q vector initialization
	q_last_calc=q_in;
	x_last_calc=x_in; % the furthest calculated point
    
    
    for k = 1:length(optics_elements)
        el=optics_elements{k};
        if el.x > x_last_calc
            %Find all points to the left of the current optical element
            index = (x_last_calc <= x_pos) & (x_pos < el.x);
            if any(index)
                x=x_pos(index);
                q_tmp=q_after_free_space(q_last_calc,x-x_last_calc);
                q(index)=q_tmp;
                x_last_calc=x(end);
                q_last_calc=q_tmp(end);
            end
            %propagate beam up to the lens
            q_at_lens = q_after_free_space(q_last_calc,el.x - x_last_calc);
            %Applying lens transformation
            q_last_calc=q_after_abcd(q_at_lens,el.abcd);
            x_last_calc = el.x;
        end
    end
    
    %points to the right of the last optical element
    index = (x_last_calc <= x_pos);
    x=x_pos(index);
    q(index)= q_after_free_space(q_last_calc,x-x_last_calc);
       
	
	
end

%!test 
%! lambda= 1.064E-6 ;
%! f1=0.1526;
%! lns1.abcd=abcd_lens( f1) ;
%! lns1.x= 0.2;
%! f2=0.019;
%! lns2.abcd=abcd_lens( f2) ;
%! lns2.x= lns1.x+ f1 + f2;
%! lns3.abcd=abcd_lens( 0.0629) ;
%! lns3.x= 0.500;
%! q0=1.8098e-96 + 1.3453e+02i;
%! x0=0;
%! optics={lns1,lns2,lns3};
%! x=[0, 0.1, 0.2, 0.3, 0,4,  0.5, 0.6, 0.7];
%! q_test = [1.8098e-96 + 1.3453e+02i,  1.0000e-01 + 1.3453e+02i,  -1.5260e-01 + 1.7310e-04i, -5.2600e-02 + 1.7310e-04i,  -5.2600e-02 + 1.7310e-04i,  3.4371e+00 + 1.8961e-03i, 3.4371e+00 + 1.8961e-03i,  3.4371e+00 + 1.8961e-03i,  3.4371e+00 + 1.8961e-03i];
%! 
%! q=gbeam_propagation(x,q0,x0,optics);
%! assert(q,q_test, -1e-4)