From 1de42f53fd7eae56442d96b98861f252ae01b5a0 Mon Sep 17 00:00:00 2001
From: Charlotte Bond <czb@star.sr.bham.ac.uk>
Date: Tue, 19 Nov 2013 17:52:11 +0000
Subject: [PATCH] adding function which uses the FT_LG_clipping_loss analytic
 function for clipping of an LG mode to find the radius of a circular aperture
 which causes a given amount of clipping

---
 src/new/FT_find_radius_for_clipping_loss.m | 63 ++++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 src/new/FT_find_radius_for_clipping_loss.m

diff --git a/src/new/FT_find_radius_for_clipping_loss.m b/src/new/FT_find_radius_for_clipping_loss.m
new file mode 100644
index 0000000..acbaec8
--- /dev/null
+++ b/src/new/FT_find_radius_for_clipping_loss.m
@@ -0,0 +1,63 @@
+%
+%--------------------------------------------------------------------------
+% function [R_out,cl_out] = FT_find_radius_for_clipping_loss(cl_in,p,l,w,R_in)
+%
+% A function for Matlab which attempts to find the required radius of a 
+% mirror to give a specified clipping loss for a particular LG beam.  The
+% function uses a fitting function, fminsearch, to try and minimise the 
+% difference between the actual and required clipping.
+%
+%  cl_in:	required clipping loss
+%  p,l:			indices of the LG beam
+%  w:			beam radius at the mirror
+%  R_in:		initial guess for the radius of the mirror.  Care
+%			should be taken when choosing this.  If the 
+%			resulting clipping doesn't match the requirements 
+% 			well repeat the function using the outputted 
+%			radius, R_out.
+%
+%  R_out:		radius required for given clipping, output of the 
+%			fitting routine.
+%  cl_out:	clipping loss given by R_out.
+% 
+%  Charlotte Bond 	18.12.2010
+%--------------------------------------------------------------------------
+
+function [R_out,cl_out] = FT_radius_for_clipping_loss(cl_in,p,l,w,R_in)
+    
+    
+  params=[R_in];
+
+
+  % set options for fminsearch ('help optimset' gives the list of options)
+  options=optimset('Display','off', 'TolX', 1e-08, 'TolFun',1e-10, 'MaxIter', 10000);
+  
+  % create link to test function below
+  f=@testfunc;
+  
+  % run the fitting algorithm
+  params=fminsearch(f,params,options,cl_in,p,l,w);
+  
+  % assign new radius of mirror
+  R_out=params(1);
+  
+  cl_out=FT_LG_clipping_loss(p,l,w,R_out);
+  
+end
+
+  
+  
+% test function for fminsearch
+function [y]=testfunc(params,cl_in,p,l,w) 
+  
+  R=params(1);
+  
+  % Use clipping loss function
+  cl=FT_LG_clipping_loss(p,l,w,R);
+  
+  y=abs(cl-cl_in);
+
+end 
+    
+    
+    
\ No newline at end of file
-- 
GitLab