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