summaryrefslogtreecommitdiff
path: root/abcd.m
blob: 8404314034d99b4c8ab3453d565e6328174f9979 (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
function fs_abcd = abcd_free_space( distance)
	fs_abcd=[1, distance; 0,1];
endfunction

function lens_abcd =abcd_lens(focal_distance)
	lens_abcd = [1, 0; -1/focal_distance, 1];
endfunction

function qnew=q_afteer_element(q_old,abcd)
	qnew=(q_old*abcd(1,1)+abcd(1,2))/(q_old*abcd(2,1)+abcd(2,2));
endfunction

function q = prop(x_pos, q_in, elements)
% calculate the 'q' parameter of the Gaussian beam propagating through optical
% 'elements' array along 'x' axis at points 'x_pos'
%  takes the gaussian beam with initial q_in parameter at x_pos(1)

	Np=length(x_pos); % number of 'x' points
	Nel=length(elements); 
	q=0*x_pos; % q vector initialization
	q(1)=q_in;
	q_last_calc=q_in;
	x_last_calc=x_pos(1); % the furthest calculated point
	for i=2:Np
		x_pos_i=x_pos(i);
		for k=1:length(elements) 
			% iterates through optical elements to make sure 
			% we take them in account for the beam propagation
			el=elements{k};
			if ( (x_last_calc < el.x) && (el.x <= x_pos_i) )
				abcd=abcd_free_space(el.x-x_last_calc);
				q_last_calc=q_afteer_element(q_last_calc,abcd);
				q_last_calc=q_afteer_element(q_last_calc,el.abcd);
				x_last_calc=el.x;
			endif
		endfor
		if (x_pos_i > x_last_calc);
			abcd=abcd_free_space(x_pos_i-x_last_calc);
			q_last_calc=q_afteer_element(q_last_calc,abcd);
			x_last_calc=x_pos_i;
		endif
		q(i)=q_last_calc;
	endfor
endfunction

function waste =q2waste(q, lambda)
	for i=1:size(q,2)
		waste(i)=sqrt (-lambda/pi/imag(1/q(i)));
	endfor
endfunction

function radius =q2radius(q, lambda)
	for i=1:size(q,2)
		radius(i)=(1/real(1/q(i)));
	endfor
endfunction

function q=waste_r2q(waste,R,lambda)
	q=1/(1/R-I*lambda/pi/waste/waste);
endfunction