./PaxHeaders.21787/optics-0.1.40000644000000000000000000000013213541155434012647 xustar0030 mtime=1568987932.198839838 30 atime=1568987932.234840537 30 ctime=1568987932.234840537 optics-0.1.4/0000755000175000017500000000000013541155434012746 5ustar00olafolaf00000000000000optics-0.1.4/PaxHeaders.21787/INDEX0000644000000000000000000000013213541155434013361 xustar0030 mtime=1568987932.198839838 30 atime=1568987932.198839838 30 ctime=1568987932.234840537 optics-0.1.4/INDEX0000644000175000017500000000206113541155434013537 0ustar00olafolaf00000000000000optics >> Optics jones jones jones_cpleft jones_cpright jones_intensity jones_lindiattenuator jones_linpolarizer jones_linretarder jones_lphorizontal jones_lpminus45 jones_lpplus45 jones_lpvertical jones_mirror jones_rotate jones_rotator jones_unity jones_waveplate mueller mueller_absorber mueller_checkmueller mueller_circdiattenuator mueller_circretarder mueller_depolarizer mueller_homogeneous_elliptic_diattenuator mueller_homogeneous_elliptic_retarder mueller_ismueller mueller_lindiattenuator mueller_linpolarizer mueller_linretarder mueller_mirror mueller_rotate mueller_rotator mueller_stokes mueller_unity mueller_waveplate stokes stokes_cpleft stokes_cpright stokes_degpolarization stokes_intensity stokes_isstokes stokes_lphorizontal stokes_lpminus45 stokes_lpplus45 stokes_lpvertical stokes_unpolarized ABCD matrix analysis @abcd/abcd @abcd/trace Zernike polynomials zernike_cartesian zernike_name zernike_noll_to_mn zernike_polar zernike_R_poly zernike_osa_ansi_to_mn zernikes_and_derivatives_cartesian_OSA optics-0.1.4/PaxHeaders.21787/devel0000644000000000000000000000013213541155434013611 xustar0030 mtime=1568987932.198839838 30 atime=1568987932.234840537 30 ctime=1568987932.234840537 optics-0.1.4/devel/0000755000175000017500000000000013541155434014045 5ustar00olafolaf00000000000000optics-0.1.4/devel/PaxHeaders.21787/TODO0000644000000000000000000000013213541155434014356 xustar0030 mtime=1568987932.198839838 30 atime=1568987932.198839838 30 ctime=1568987932.234840537 optics-0.1.4/devel/TODO0000644000175000017500000000021013541155434014526 0ustar00olafolaf00000000000000* A common API (at least on the image package), is to either plot stuff or return depending on nargout (instead of using a plot_flag) optics-0.1.4/PaxHeaders.21787/inst0000644000000000000000000000013213541155434013467 xustar0030 mtime=1568987932.222840305 30 atime=1568987932.234840537 30 ctime=1568987932.234840537 optics-0.1.4/inst/0000755000175000017500000000000013541155434013723 5ustar00olafolaf00000000000000optics-0.1.4/inst/PaxHeaders.21787/jones_linpolarizer.m0000644000000000000000000000013213541155434017632 xustar0030 mtime=1568987932.202839916 30 atime=1568987932.202839916 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_linpolarizer.m0000644000175000017500000000555013541155434020016 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{JM} =} jones_linpolarizer() ## @deftypefnx {Function File} {@var{A} =} jones_linpolarizer(@var{[m, n, ...]}) ## @deftypefnx {Function File} {@var{A} =} jones_linpolarizer(@var{C}) ## Return the Jones matrix for an ideal linear polarizer. ## ## @itemize @minus ## @item @var{[m, n, ...]} defines the size of the cell array @var{A} ## and therefore the number of linear polarizer matrices returned. ## @item @var{C} is a cell array defining the size of the returned cell array ## @var{A}, @code{size(A)==size(C)}. The content of @var{C} is of not ## evaluated in this case. ## @end itemize ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{jones_lindiattenuator} ## @end deftypefn function JM = jones_linpolarizer(varargin) retcell = true; if nargin<1 sc = [1,1]; retcell = false; elseif isnumeric(varargin{1}) sc = varargin{1}; else sc = size(varargin{1}); end if prod(sc) > 1 || retcell JM = cell(sc); [JM{:}] = deal(s_linpolarizer()); else JM = s_linpolarizer(); end end % helper function function JM = s_linpolarizer() JM = [1,0;0,0]; end %!test %! % applying an ideal linear polarizer twice is identical to %! % apply it once! %! A = jones_linpolarizer(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test direct size parameter %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! rsize = size(rand(asize)); %! U = jones_linpolarizer(rsize); %! usize = size(U); %! assert(usize == rsize); %! end %! %!test %! % test indirect size parameter %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! C = cell(asize); %! csize = size(C); %! U = jones_linpolarizer(C); %! usize = size(U); %! assert(usize == csize); %! end %! optics-0.1.4/inst/PaxHeaders.21787/mueller_homogeneous_elliptic_diattenuator.m0000644000000000000000000000013213541155434024447 xustar0030 mtime=1568987932.210840071 30 atime=1568987932.210840071 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_homogeneous_elliptic_diattenuator.m0000644000175000017500000001605113541155434024631 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_homogeneous_elliptic_diattenuator() ## @deftypefnx {Function File} {@var{M} =} mueller_homogeneous_elliptic_diattenuator(@var{t0}, @var{d}, @var{azimuth}, @var{ellipticity}) ## @deftypefnx {Function File} {@var{M} =} mueller_homogeneous_elliptic_diattenuator(..., @var{azimuthmode}) ## Return the Mueller matrix for a homogeneous elliptic diattenuator (see ## references). ## ## @itemize @minus ## @item @var{t0} is the total transmission (default: 1). ## @item @var{d} is the diattenuation value (default: 0). ## @item @var{azimuth} and @var{ellipticity} (default: 0) describe the ## two orthogonal polarization eigenstates. ## @item @var{azimuthmode} is a string defining the interpretation of ## the azimuth angle: 'radiants' (default) or 'degree'. ## @end itemize ## ## Arguments @var{t0}, @var{d}, @var{azimuth}, or ## @var{ellipticity} can be passed as a scalar ## or as a matrix or as a cell array. In the two latter cases, a cell ## array @var{M} of Mueller matrices is returned. The size of @var{M} ## is given by @code{max(size(t0),size(d),size(azimuth),size(ellipticity))} ## and elements of smaller matrices of @var{t0}, @var{d}, ## @var{azimuth} or @var{ellipticity} are used in a loop-over manner. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @item Boulvert et al., "Decomposition algorithm of an experimental ## Mueller matrix", Opt.Comm. 282(2009):692-704 ## @end enumerate ## ## @seealso{mueller_homogeneous_elliptic_retarder} ## @end deftypefn function M = mueller_homogeneous_elliptic_diattenuator(varargin) % TODO: check ref [3] in [4] for decomposition in homogeneous elliptic % retarder und retarder switch(nargin) case 0 t0 = 1; d = 0; azimuth = 0; ellipticity = 0; was_cell = false; case 1 [t0, was_cell] = __c2n__(varargin{1}, 1); d = 0; azimuth = 0; ellipticity = 0; case 2 [t0, was_cell_t0] = __c2n__(varargin{1}, 1); [d, was_cell_d] = __c2n__(varargin{2}, 0); azimuth = 0; ellipticity = 0; was_cell = was_cell_t0 || was_cell_d; case 3 [t0, was_cell_t0] = __c2n__(varargin{1}, 1); [d, was_cell_d] = __c2n__(varargin{2}, 0); [azimuth, was_cell_azimuth] = __c2n__(varargin{3}, 0); ellipticity = 0; was_cell = was_cell_t0 || was_cell_d || was_cell_azimuth; otherwise [t0, was_cell_t0] = __c2n__(varargin{1}, 1); [d, was_cell_d] = __c2n__(varargin{2}, 0); [azimuth, was_cell_azimuth] = __c2n__(varargin{3}, 0); % check special case of homogeneous_elliptic_diattenuator(t0,d,a,'degree') if ischar(varargin{4}) ellipticity = 0; was_cell_ellipticity = false; else [ellipticity, was_cell_ellipticity] = __c2n__(varargin{4}, 0); end was_cell = was_cell_t0 || was_cell_d || was_cell_azimuth || was_cell_ellipticity; end % convert azimuth angle if necessary if nargin>=4 && ischar(varargin{end}) if strncmpi(varargin{end},'deg',3) azimuth = azimuth*pi()/180.0; end end % any matrix in parameters? if (any([numel(t0),numel(d),numel(azimuth),numel(ellipticity)] > 1)) ... || was_cell % adjust dimensions, i.e. fill missing dimensions with 1 st0 = size(t0); sd = size(d); sazimuth = size(azimuth); sellipticity = size(ellipticity); maxdim = max([length(st0),length(sd),length(sazimuth),length(sellipticity)]); if length(st0) < maxdim st0 = [st0, ones(1,maxdim-length(st0))]; end if length(sd) < maxdim sd = [sd, ones(1,maxdim-length(sd))]; end if length(sazimuth) < maxdim sazimuth = [sazimuth, ones(1,maxdim-length(sazimuth))]; end if length(sellipticity) < maxdim sellipticity = [sellipticity, ones(1,maxdim-length(sellipticity))]; end % generate Mueller matrices maxsize = max([st0;sd;sazimuth;sellipticity]); M = cell(maxsize); M_subs = cell(1,ndims(M)); numelM = numel(M); % flatten parameter arrays t0 = t0(:); d = d(:); azimuth = azimuth(:); ellipticity = ellipticity(:); numelt0 = numel(t0); numeld = numel(d); numelazimuth = numel(azimuth); numelellipticity = numel(ellipticity); for mi=1:numelM [M_subs{:}] = ind2sub(size(M),mi); M{M_subs{:}} = s_homogenenous_elliptic_diattenuator(t0(mod(mi-1,numelt0)+1),... d(mod(mi-1,numeld)+1),... azimuth(mod(mi-1,numelazimuth)+1), ... ellipticity(mod(mi-1,numelellipticity)+1)); end else % generate Mueller matrix M = s_homogenenous_elliptic_diattenuator(t0,d,azimuth,ellipticity); end end % helper function function M = s_homogenenous_elliptic_diattenuator(t0,d,azimuth,ellipticity) M = zeros(4,4); a = cos(2*ellipticity)*cos(2*azimuth); b = cos(2*ellipticity)*sin(2*azimuth); c = sin(2*ellipticity); M(1,1) = 1; M(1,2) = a*d; M(1,3) = b*d; M(1,4) = c*d; M(2,1) = M(1,2); M(2,2) = sqrt(1-d^2)+a^2*(1-sqrt(1-d^2)); M(2,3) = a*b*(1-sqrt(1-d^2)); M(2,4) = a*c*(1-sqrt(1-d^2)); M(3,1) = M(1,3); M(3,2) = M(2,3); M(3,3) = sqrt(1-d^2)+b^2*(1-sqrt(1-d^2)); M(3,4) = b*c*(1-sqrt(1-d^2)); M(4,1) = M(1,4); M(4,2) = M(2,4); M(4,3) = M(3,4); M(4,4) = sqrt(1-d^2)+c^2*(1-sqrt(1-d^2)); M = M*t0; end %!test %! % test default return value %! A = mueller_homogeneous_elliptic_diattenuator(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test modes %! t0 = rand(1,1); %! d = rand(1,1); %! azimuth = rand(1,1); %! ellipticity = rand(1,1); %! A1 = mueller_homogeneous_elliptic_diattenuator(t0,d,azimuth,ellipticity); %! A2 = mueller_homogeneous_elliptic_diattenuator(t0,d,azimuth*180/pi(),ellipticity,'deg'); %! R = (A2-A1); %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test correct size of return values %! t0 = rand(3,4,5); %! d = rand(4,5,6); %! azimuth = rand(5,4,3); %! ellipticity = rand(6,5,4); %! C = mueller_homogeneous_elliptic_diattenuator(t0,d,azimuth,ellipticity); %! csize = size(C); %! assert(csize == [6,5,6]); optics-0.1.4/inst/PaxHeaders.21787/jones_lpminus45.m0000644000000000000000000000013213541155434016760 xustar0030 mtime=1568987932.202839916 30 atime=1568987932.202839916 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_lpminus45.m0000644000175000017500000000556613541155434017153 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} jones_lpminus45() ## @deftypefnx {Function File} {@var{V} =} jones_lpminus45(@var{p}) ## Return the Jones vector for light with linear polarization at -45 degrees. ## ## @itemize @minus ## @item @var{p} is the amplitude of the electric field, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Jones vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{jones_lpplus45} ## @end deftypefn function V = jones_lpminus45(varargin) amplitude_defv = 1; if nargin<1 amplitude = amplitude_defv; else amplitude = varargin{1}; end [amplitude, was_cell] = __c2n__(amplitude, amplitude_defv); if (numel(amplitude) > 1) || was_cell V = cell(size(amplitude)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_lpminus45(amplitude(V_subs{:})); end else V = s_lpminus45(amplitude); end end % helper function function V = s_lpminus45(amplitude) V = [1;-1]*amplitude; end %!test %! % test default return value %! V = jones_lpminus45(); %! R = V-[1;-1]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! amplitude = rand(1, 1); %! V = jones_lpminus45(amplitude); %! R = V-[1;-1]*amplitude; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = jones_lpminus45(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/mueller_lindiattenuator.m0000644000000000000000000000013213541155434020655 xustar0030 mtime=1568987932.210840071 30 atime=1568987932.210840071 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_lindiattenuator.m0000644000175000017500000001423513541155434021041 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_lindiattenuator() ## @deftypefnx {Function File} {@var{M} =} mueller_lindiattenuator(@var{d}) ## @deftypefnx {Function File} {@var{M} =} mueller_lindiattenuator(@var{px},@var{py}) ## @deftypefnx {Function File} {@var{M} =} mueller_lindiattenuator(..., @var{mode}) ## Return the Mueller matrix for a linear diattenuator at zero ## rotation. ## ## @itemize @minus ## @item @var{d} is the diattenuation of the element, i.e. ## @code{d=(px-py)/(px+py)}. Reversibly, transmission in y direction ## is @code{(1-d)/(1+d)}, if transmission in x direction is 1. ## @item @var{px} is the transmittance in x direction. ## @item @var{py} is the transmittance in y direction. ## @item @var{mode} is a string defining the interpretation of ## transmittance values: 'intensity' (default) or 'amplitude'. ## @end itemize ## ## Arguments @var{d}, @var{px} or @var{py} can be passed as a scalar ## or as a matrix or as a cell array. In the two latter cases, a cell ## array @var{M} of Mueller matrices is returned. The size of @var{M} ## is set to the maximum of the parameters' size. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_circdiattenuator, mueller_absorber} ## @end deftypefn function M = mueller_lindiattenuator(varargin) if nargin<1 px = 1; py = 1; was_cell = false; elseif nargin==1 px = varargin{1}; [px, was_cell] = __c2n__(px, 0); py = (1-px)./(1+px); px(:) = 1; else px = varargin{1}; [px, was_cellx] = __c2n__(px, 1); py = varargin{2}; [py, was_celly] = __c2n__(py, 1); was_cell = was_cellx || was_celly; end % check mode s_function = @s_lindiattenuator_int; if nargin>=2 && ischar(varargin{end}) if strncmpi(varargin{end},'amp',3) s_function = @s_lindiattenuator_amp; end end % any matrix in parameters? if (any([numel(px),numel(py)] > 1)) || was_cell % adjust dimensions, i.e. fill missing dimensions with 1 spx = size(px); spy = size(py); maxdim = max([length(spx),length(spy)]); if length(spx) < maxdim spx = [spx, ones(1,maxdim-length(spx))]; end if length(spy) < maxdim spy = [spy, ones(1,maxdim-length(spy))]; end % generate Mueller matrices maxsize = max([spx;spy]); M = cell(maxsize); M_subs = cell(1,ndims(M)); numelM = numel(M); % flatten parameter arrays px = px(:); py = py(:); numelpx = numel(px); numelpy = numel(py); for mi=1:numelM [M_subs{:}] = ind2sub(size(M),mi); M{M_subs{:}} = s_function(px(mod(mi-1,numelpx)+1), py(mod(mi-1,numelpy)+1)); end else M = s_function(px, py); end end % helper function function M = s_lindiattenuator_amp(px_in_amplitude_domain,py_in_amplitude_domain) M = zeros(4,4); M(1,1) = (px_in_amplitude_domain^2+py_in_amplitude_domain^2)/2; M(1,2) = (px_in_amplitude_domain^2-py_in_amplitude_domain^2)/2; M(2,1) = M(1,2); M(2,2) = M(1,1); M(3,3) = px_in_amplitude_domain*py_in_amplitude_domain; M(4,4) = M(3,3); end % helper function 2 function M = s_lindiattenuator_int(kx_in_intensity_domain,ky_in_intensity_domain) M = zeros(4,4); M(1,1) = (kx_in_intensity_domain+ky_in_intensity_domain)/2; M(1,2) = (kx_in_intensity_domain-ky_in_intensity_domain)/2; M(2,1) = M(1,2); M(2,2) = M(1,1); M(3,3) = sqrt(kx_in_intensity_domain*ky_in_intensity_domain); M(4,4) = M(3,3); end %!test %! % test default return value %! A = mueller_lindiattenuator(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test equality of providing diattenuation or kx and ky %! d = rand(1, 1); %! kx = 1; %! ky = (1-d)./(1+d); %! A1 = mueller_lindiattenuator(d); %! A2 = mueller_lindiattenuator(kx, ky); %! R = A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial application of linear diattenuators %! kx = rand(1, 1); %! ky = rand(1, 1); %! A1 = mueller_lindiattenuator(kx,ky); %! A2 = mueller_lindiattenuator(kx*kx,ky*ky); %! R = A1*A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test of serial application of retarder elements %! kx1 = rand(1, 1); %! kx2 = rand(1, 1); %! ky1 = rand(1, 1); %! ky2 = rand(1, 1); %! A1 = mueller_lindiattenuator(kx1,ky1); %! A2 = mueller_lindiattenuator(kx2,ky2); %! A12 = mueller_lindiattenuator(kx1*kx2,ky1*ky2); %! R = A1*A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test mode %! kx = rand(1, 1); %! ky = rand(1, 1); %! A1 = mueller_lindiattenuator(kx,ky); %! A2 = mueller_lindiattenuator(kx,ky,'int'); %! A3 = mueller_lindiattenuator(sqrt(kx),sqrt(ky),'amp'); %! R1 = A1-A2; %! R2 = A1-A3; %! assert(norm(R1,inf)+norm(R2,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = mueller_lindiattenuator(R); %! csize = size(C); %! assert(rsize == csize); %! end %! %!test %! % another test correct size of return values %! kx = rand(3,4,5); %! ky = rand(5,4,3); %! C = mueller_lindiattenuator(kx,ky); %! csize = size(C); %! assert(csize == [5,4,5]); optics-0.1.4/inst/PaxHeaders.21787/jones_cpleft.m0000644000000000000000000000013213541155434016375 xustar0030 mtime=1568987932.202839916 30 atime=1568987932.202839916 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_cpleft.m0000644000175000017500000000551213541155434016557 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} jones_cpleft() ## @deftypefnx {Function File} {@var{V} =} jones_cpleft(@var{p}) ## Return the Jones vector for left-turn circular polarized light. ## ## @itemize @minus ## @item @var{p} is the amplitude of the electric field, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Jones vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{jones_cpright} ## @end deftypefn function V = jones_cpleft(varargin) amplitude_defv = 1; if nargin<1 amplitude = amplitude_defv; else amplitude = varargin{1}; end [amplitude, was_cell] = __c2n__(amplitude, amplitude_defv); if (numel(amplitude) > 1) || was_cell V = cell(size(amplitude)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_cpleft(amplitude(V_subs{:})); end else V = s_cpleft(amplitude); end end % helper function function V = s_cpleft(amplitude) V = amplitude*[1; -1i]; end %!test %! % test default return value %! V = jones_cpleft(); %! R = V-[1;-1i]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! amplitude = rand(1, 1); %! V = jones_cpleft(amplitude); %! R = V-[1;-1i]*amplitude; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = jones_cpleft(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/mueller_stokes.m0000644000000000000000000000013213541155434016757 xustar0030 mtime=1568987932.214840148 30 atime=1568987932.214840148 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_stokes.m0000644000175000017500000001367513541155434017152 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_stokes(@var{M}) ## @deftypefnx {Function File} {@var{A} =} mueller_stokes(@var{M,N,...}) ## Multiply Mueller matrices and Stokes vectors. ## ## @itemize @minus ## @item @var{M,N,...} define Mueller matrices or Stokes ## vectors. The function will multiply these from left to right and ## return the result. ## @end itemize ## ## @var{M,N,...} can be passed as either numeric matrices/vectors or ## cell arrays. In this case, the multiplication is carried out in a ## ".*" manner. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_checkmueller} ## @end deftypefn function A = mueller_stokes (varargin) if (nargin < 1) print_usage(); end A = varargin{1}; for vi=2:nargin A = __cellfunc__(@(M1,M2)(M1*M2), A, varargin{vi}); end end %% Test input validation %!error A = mueller_stokes(); %!test %! % test singular argument, should just be returned %! M = mueller_waveplate(rand(1,1),'wav'); %! MM = mueller_stokes(M); %! R = MM-M; %! assert(norm(R,inf), 0, 1e-9); %!test %! % send light with horizontal linear polarization through a rotating %! % 1/2-waveplate and subsequent polarizer: final intensity should %! % vary as cos(2*angle)^2. %! % This test feeds mueller_stokes() with one cell array only! %! angles = 0:360; %! wps = mueller_rotate(mueller_waveplate(0.5, 'wav'), angles, 'deg'); %! lightin = stokes_lphorizontal(); %! lightout = mueller_stokes(mueller_linpolarizer(),wps,lightin); %! ilightout = stokes_intensity(lightout); %! R = ilightout-(cosd(angles.*2).^2); %! assert(norm(R,inf), 0, 1e-9); %!test %! % this is a more thorough test: send light with horizontal linear %! % polarization through two rotating 1/2-waveplates (combining to %! % a 1/1-waveplate) and subsequent polarizer: final intensity %! % should not vary! %! % This test feeds mueller_stokes() with two cell arrays. %! angles = 0:360; %! wps1 = mueller_rotate(mueller_waveplate(0.5, 'wav'), angles, 'deg'); %! wps2 = mueller_rotate(mueller_waveplate(0.5, 'wav'), angles, 'deg'); %! lightin = stokes_lphorizontal(); %! lightout = mueller_stokes(mueller_linpolarizer(),wps2,wps1,lightin); %! ilightout = stokes_intensity(lightout); %! R = ilightout-1; %! assert(norm(R,inf), 0, 1e-9); %!demo %! angles = 0:360; %! wps = mueller_rotate(mueller_waveplate(0.5, 'wav'), angles, 'deg'); %! lightin = stokes_lphorizontal(); %! lightout = mueller_stokes(mueller_linpolarizer(),wps,lightin); %! ilightout = stokes_intensity(lightout); %! figure(); %! plot(angles, ilightout); %! title('transmitted intensity [should look like cos(2*a)^2'); %! xlabel('angle of halfwave plate axis'); %! ylabel('intensity [a.u.]'); %! legend('transmitted intensity'); %! % ----------------------------------------------------------------- %! % example 1: send light with horizontal linear polarization through %! % a rotating, perfect halfwave plate and subsequent polarizer: %! % final intensity should vary as cos(2*angle)^2. %!demo %! angles = 0:360; %! wps = mueller_rotate(mueller_waveplate(0.5, 'wav'), angles, 'deg'); %! wps2 = mueller_rotate(mueller_waveplate(0.45, 'wav'), angles, 'deg'); %! lightin = stokes_lphorizontal(); %! lightout = mueller_stokes(mueller_linpolarizer(),wps,lightin); %! ilightout = stokes_intensity(lightout); %! lightout2 = mueller_stokes(mueller_linpolarizer(),wps2,lightin); %! ilightout2 = stokes_intensity(lightout2); %! figure(); %! plot(angles, ilightout, angles, ilightout2); %! title('transmitted intensity with perfect and non-perfect halfwave plate'); %! xlabel('angle of halfwave plate axis'); %! ylabel('intensity [a.u.]'); %! legend('perfect (0.5-)plate', 'non-perfect (0.45-)plate'); %! % ----------------------------------------------------------------- %! % example 2: send light with horizontal linear polarization through %! % a rotating, non-perfect halfwave plate and subsequent polarizer: %! % final intensity should deviate from the perfect cos(2*angle)^2 %! % curve, never reaching zero transmission %!demo %! angle = 0:360; %! delay = 0:0.05:1; %! % angles are in rows, delays in columns %! angle_all = repmat(angle, [length(delay), 1]); %! delay_all = repmat(delay', [1, length(angle)]); %! wps3 = mueller_waveplate(delay_all, 'wav'); %! wps3 = mueller_rotate(wps3, angle_all, 'deg'); %! lightin = stokes_lphorizontal(); %! lightout3 = mueller_stokes(mueller_linpolarizer(),wps3,lightin); %! ilightout3 = stokes_intensity(lightout3); %! figure(); %! plot(angle, ilightout3); %! title('transmitted intensity with plates of increasing delay'); %! xlabel('angle of plate axis'); %! ylabel('intensity [a.u.]'); %! legend(cellfun(@(x)sprintf('delay=%.2f',x),num2cell(delay),'UniformOutput',false)); %! % ----------------------------------------------------------------- %! % example 3: send light with horizontal linear polarization through %! % rotating waveplates with increasing delay and subsequent polarizer optics-0.1.4/inst/PaxHeaders.21787/zernike_noll_to_mn.m0000644000000000000000000000013213541155434017611 xustar0030 mtime=1568987932.218840227 30 atime=1568987932.218840227 30 ctime=1568987932.234840537 optics-0.1.4/inst/zernike_noll_to_mn.m0000644000175000017500000000454213541155434017775 0ustar00olafolaf00000000000000## Copyright (C) 2012 Andreas Weber ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{m}, @var{n}] =} zernike_noll_to_mn (@var{j}) ## Convert Noll's index @var{j} to @var{m} (Azimuthal degree) and @var{n} (Radial degree). ## ## See sequence A176988 in OEIS (http://oeis.org/A176988) ## @seealso{zernike_cartesian, zernike_name, zernike_polar, zernike_R_poly} ## @end deftypefn function [m, n] = zernike_noll_to_mn (j) if (nargin != 1 || nargout != 2) print_usage (); elseif (any (j(:) < 1 | j(:) != fix (j(:))) || ! isvector (j)) error ("zernike_noll_to_mn: j has to be a vector with integers >=1"); endif n = fix (sqrt (2*j-1) + 0.5) - 1; s = mod (n, 2); me = 2 * fix ((2*j + 1 - n.*(n+1)) / 4); #the even ones mo = 2 * fix ((2*(j+1) - n.*(n+1)) / 4) - 1; #the odd ones m = (mo.*s + me.*(1-s)).*(1 - 2*mod(j,2)); endfunction ## see http://oeis.org/A176988 ## %!test %! [m,n]=zernike_noll_to_mn(1); %! assert([m n],[0 0]) %!test %! [m,n]=zernike_noll_to_mn(2); %! assert([m n],[1 1]) %!test %! [m,n]=zernike_noll_to_mn(3); %! assert([m n],[-1 1]) %!test %! [m,n]=zernike_noll_to_mn(4); %! assert([m n],[0 2]) %!test %! [m,n]=zernike_noll_to_mn(5); %! assert([m n],[-2 2]) ## skipp noll indices 6..19 FIXME: or should we add all to this test? %!test %! [m,n]=zernike_noll_to_mn(20); %! assert([m n],[5 5]) ## skipp noll indices 21..33 FIXME: or should we add all to this test? %!test %! [m,n]=zernike_noll_to_mn(34); %! assert([m n],[5 7]) %!test %! [m,n]=zernike_noll_to_mn(35); %! assert([m n],[-7 7]) %!test %! [m,n]=zernike_noll_to_mn(36); %! assert([m n],[7 7]) ## vector test %!test %! [m,n]=zernike_noll_to_mn([2 5 8 35]); %! assert(m,[1 -2 1 -7]) %! assert(n,[1 2 3 7]) optics-0.1.4/inst/PaxHeaders.21787/jones_lpvertical.m0000644000000000000000000000013213541155434017265 xustar0030 mtime=1568987932.206839993 30 atime=1568987932.206839993 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_lpvertical.m0000644000175000017500000000555413541155434017455 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} jones_lpvertical() ## @deftypefnx {Function File} {@var{V} =} jones_lpvertical(@var{p}) ## Return the Jones vector for vertical linearly polarized light. ## ## @itemize @minus ## @item @var{p} is the amplitude of the electric field, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Jones vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{jones_lphorizontal} ## @end deftypefn function V = jones_lpvertical(varargin) amplitude_defv = 1; if nargin<1 amplitude = amplitude_defv; else amplitude = varargin{1}; end [amplitude, was_cell] = __c2n__(amplitude, amplitude_defv); if (numel(amplitude) > 1) || was_cell V = cell(size(amplitude)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_lpvertical(amplitude(V_subs{:})); end else V = s_lpvertical(amplitude); end end % helper function function V = s_lpvertical(amplitude) V = [0; amplitude]; end %!test %! % test default return value %! V = jones_lpvertical(); %! R = V-[0;1]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! amplitude = rand(1, 1); %! V = jones_lpvertical(amplitude); %! R = V-[0;1]*amplitude; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = jones_lpvertical(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/zernike_R_poly.m0000644000000000000000000000013213541155434016715 xustar0030 mtime=1568987932.218840227 30 atime=1568987932.218840227 30 ctime=1568987932.234840537 optics-0.1.4/inst/zernike_R_poly.m0000644000175000017500000000446513541155434017105 0ustar00olafolaf00000000000000## Copyright (C) 2015 Andreas Weber ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{R} =} zernike_R_poly (@var{m}, @var{n}) ## Return the first part of the radial zernike polynom R^m_n. ## ## The polynom returned has a length of N+1. ## @seealso{zernike_cartesian, zernike_name, zernike_noll_to_nm, zernike_polar} ## @end deftypefn function ret = zernike_R_poly (m, n) if (nargin != 2) print_usage (); elseif (! isscalar (m) || m < 0 || m != fix (m) || ! isscalar (n) || n < 0 || n != fix (n)) error ("zernike_R_poly: M and N must all be non-negative integers"); endif ret = zeros (1, n+1); if (! mod (n-m, 2)) #TODO: try to omit for-loop for k = 0:(n-m)/2 ret(2*k+1) = (-1)^k * bincoeff (n-k, k) * bincoeff (n-2*k, (n-m)/2-k); endfor endif endfunction ## see http://en.wikipedia.org/wiki/Zernike_polynomials#Radial_polynomials ## added all examples up to order 6 %!assert (zernike_R_poly (0, 0), [1]) %!assert (zernike_R_poly (1, 1), [1 0]) %!assert (zernike_R_poly (0, 2), [2 0 -1]) %!assert (zernike_R_poly (2, 2), [1 0 0]) %!assert (zernike_R_poly (1, 3), [3 0 -2 0]) %!assert (zernike_R_poly (3, 3), [1 0 0 0]) %!assert (zernike_R_poly (0, 4), [6 0 -6 0 1]) %!assert (zernike_R_poly (2, 4), [4 0 -3 0 0]) %!assert (zernike_R_poly (4, 4), [1 0 0 0 0]) %!assert (zernike_R_poly (1, 5), [10 0 -12 0 3 0]) %!assert (zernike_R_poly (3, 5), [5 0 -4 0 0 0]) %!assert (zernike_R_poly (5, 5), [1 0 0 0 0 0]) %!assert (zernike_R_poly (0, 6), [20 0 -30 0 12 0 -1]) %!assert (zernike_R_poly (2, 6), [15 0 -20 0 6 0 0]) %!assert (zernike_R_poly (4, 6), [ 6 0 -5 0 0 0 0]) %!assert (zernike_R_poly (6, 6), [ 1 0 0 0 0 0 0]) optics-0.1.4/inst/PaxHeaders.21787/zernike_name.m0000644000000000000000000000013213541155434016371 xustar0030 mtime=1568987932.218840227 30 atime=1568987932.218840227 30 ctime=1568987932.234840537 optics-0.1.4/inst/zernike_name.m0000644000175000017500000000443313541155434016554 0ustar00olafolaf00000000000000## Copyright (C) 2015 Andreas Weber ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{name} =} zernike_name (@var{n}) ## Return the classic name for noll's index @var{n} or ## "-" (no name defined) without warning if @var{n} > 21. ## ## Examples: ## @example ## @group ## zernike_name(4) ## @result{} defocus ## zernike_name(21) ## @result{} vertical pentafoil ## @end group ## @end example ## ## @seealso{zernike_cartesian, zernike_noll_to_nm, zernike_polar, zernike_R_poly} ## @end deftypefn function name = zernike_name (n) ## taken from http://www.telescope-optics.net/zernike_coefficients.htm persistent classical_names = ... { "piston"; "horizontal tilt"; "vertical tilt"; "defocus"; "oblique primary astigmatism"; "vertical primary astigmatism"; "vertical coma"; "horizontal coma"; "vertical trefoil"; "oblique trefoil"; "primary spherical"; "vertical secondary astigmatism"; "oblique secondary astigmatism"; "vertical quadrafoil"; "oblique quadrafoil"; "horizontal secondary coma"; "vertical secondary coma"; "oblique secondary trefoil"; "vertical secondary trefoil"; "oblique pentafoil"; "vertical pentafoil"; }; if (nargin != 1) print_usage (); elseif (! isscalar (n) || n < 1 || n != fix (n)) error ("zernike_name: n must be a scalar integer >= 1"); endif if (n > numel (classical_names)) name = "-"; else name = classical_names{n}; endif endfunction %!assert (zernike_name (4), "defocus") %!assert (zernike_name (22), "-") %!error (zernike_name (0)) %!error (zernike_name ([1 2])) %!error (zernike_name (pi)) optics-0.1.4/inst/PaxHeaders.21787/zernikes_and_derivatives_cartesian_OSA.m0000644000000000000000000000013213541155434023536 xustar0030 mtime=1568987932.222840305 30 atime=1568987932.222840305 30 ctime=1568987932.234840537 optics-0.1.4/inst/zernikes_and_derivatives_cartesian_OSA.m0000644000175000017500000002122513541155434023717 0ustar00olafolaf00000000000000## Copyright (C) 2019 José Ramom Flores das Seixas ## ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see . ## -*- texinfo -*- ## @deftypefn {} {[@var{Z}, @var{dZx}, @var{dZy}] =} zernikes_and_derivarives_cartesian_OSA (@var{x}, @var{y}, @var{n}) ## @deftypefnx {} {[@var{Z}, @var{dZx}, @var{dZy}] =} zernikes_and_derivarives_cartesian_OSA (@var{x}, @var{y}, @var{n}, @var{nan_zero}) ## Return the cartesian Zernike's pollynomials and its partial ## derivatives up to radial degree @var{n}, i.e. until Z[@var{n},@var{n}] ## ## @var{x} is a matrix with the X coordinates of the points where the Zernike's ## polynomials and its derivatives are computed. ## @var{y} is a matrix with the Y coordinates of the same points. ## @var{n} is an integer with the maximum radial degree desired. ## @var{nan_zero} is a string that determines the values of polynomial ## and derived values outside the radio unit circle. ## ## Strictly, the polynoms are only defined for 0 <= X²+Y² <= 1. ## If variable @var{nan_zero} = 'nan', the values of the polynomials for which ## it is verified that (X²+Y²)>1 are set = NaN. ## If variable @var{nan_zero} = 'zero', the values of the polynomials for which ## it is verified that (X²+Y²)>1 are set = 0. ## ## @var{Z} is a 3D matrix. Each page contains a 2D matrix with the values of a ## Zernike's polynomial at the points defined by @var{x} and @var{y}. ## ## @var{dZx} is a 3D matrix. Each page contains the values of the ## partial derivative in x. ## ## @var{dZy} is a 3D matrix. Each page contains the values of the ## partial derivative in y. ## ## It should be noted that in standard OSA/ANSI the simple-index j starts ## at 0, but in octave the indices of the vectors and matrices start at 1. ## So that page 1 of the 3D Z, dZx and dZy matrices corresponds to the ## single-index j = 0, and therefore to the double-index m = 0 and n = 0. ## Page 2 corresponds to j = 1, page 3 --> j = 2, etc. ## ## Example ## @example ## x = linspace(-1,1,101); ## [X,Y] = meshgrid(x,x); ## [Z,dZx,dZy] = zernikes_and_derivatives_cartesian_OSA (X,Y,7,'zero'); ## Z_00 = Z(:,:,1); ## # Z_00 is a 2D matrix with the values of Zernike's polynomial ## # with simple-index j = 0, and double-index m = 0 & n = 0. ## dZx_-24 = dZx(:,:,11); ## # Z_-44 is a 2D matrix with the values of the partial ## # derivative in x of Zernike's polynomial with ## # simple-index j = 10, and double-index m = -4 & n = 4. ## @end example ## ## Run the demo to see a more complete example. ## ## ## Size of @var{x} must be equal size of @var{y}. ## ## References: ## ## @enumerate ## @item Andersen T.B., @url{https://doi.org/10.1364/OE.26.018878, "Efficient ## and robust recurrence relations for the Zernike circle polynomials and ## their derivatives in Cartesian coordinates"}. Optic Express 26(15), ## 18878-18896 (2018). ## @item Thibos, L.N, Applegate, R.A., Schwiegerling, J.T. & Webb, R., ## Standards for reporting the optical aberrations of eyes. Journal of ## refractive surgery, 18(5), S652-S660 (2002). ## @end enumerate ## ## @seealso{zernike_osa_ansi_to_nm, zernike_cartesian, zernike_name, ## zernike_polar, zernike_R_poly} ## @end deftypefn function [Z,dZx,dZy] = zernikes_and_derivatives_cartesian_OSA (x, y, N, nan_zero = 'NaN'); if (nargin < 3 || nargin > 4) print_usage (); elseif (! isscalar (N) || N < 1 || N != fix (N)) error ("zernike_and_derivatives_cartesian_OA: Maximum radial degree must be a integer >=1"); elseif (any (size (x) != size (y))) error ("zernike_and_derivatives_cartesian_OA: X and Y must have the same size"); endif r2 = x.^2 + y.^2; out_p = find(r2>1); MaxJ = N*(N+3)/2; U1 = ones(size(x)); switch(nan_zero) case "zero" x(out_p) = 0; y(out_p) = 0; U1(out_p) = 0; case "NaN" x(out_p) = NaN; y(out_p) = NaN; U1(out_p) = NaN; endswitch U = zeros ([size(x) (MaxJ+1)]); dUx = U; dUy = U; Z = U; dZx = U; dZy = U; U(:,:,1) = U1; dUx(:,:,1) = U1*0; dUy(:,:,1) = U1*0; Z(:,:,1) = U1; dZx(:,:,1) = U1*0; dZy(:,:,1) = U1*0; U(:,:,2) = y; dUx(:,:,2) = U1*0; dUy(:,:,2) = U1; Z(:,:,2) = 2*y; dZx(:,:,2) = U1*0; dZy(:,:,2) = 2*U1; U(:,:,3) = x; dUx(:,:,3) = U1; dUy(:,:,3) = U1*0; Z(:,:,3) = 2*x; dZx(:,:,3) = 2*U1; dZy(:,:,3) = U1*0; for k = 4:(MaxJ+1) [m, n] = zernike_osa_ansi_to_mn (k-1); switch(m) case -n U(:,:,k) = x.*U(:,:,(k-n))+y.*U(:,:,(k-1)); dUx(:,:,k) = n*U(:,:,(k-n)); dUy(:,:,k) = n*U(:,:,(k-1)); case n U(:,:,k) = x.*U(:,:,(k-(n+1)))-y.*U(:,:,(k-2*n)); dUx(:,:,k) = n*U(:,:,(k-(n+1))); dUy(:,:,k) = -n*U(:,:,(k-2*n)); case -1 U(:,:,k) = x.*U(:,:,(k-(n+1)))+y.*U(:,:,(k-n))-y.*U(:,:,(k-(n-1)))-... U(:,:,(k-2*n)); dUx(:,:,k) = n*U(:,:,(k-(n+1)))+dUx(:,:,(k-2*n)); dUy(:,:,k) = n*U(:,:,(k-n))-n*U(:,:,(k-(n-1)))+dUy(:,:,(k-2*n)); case 1 U(:,:,k) = x.*U(:,:,(k-n))+x.*U(:,:,(k-(n+1)))+y.*U(:,:,(k-(n+2)))-... U(:,:,(k-2*n)); dUx(:,:,k) = n*U(:,:,(k-n))+n*U(:,:,(k-(n+1)))+dUx(:,:,(k-2*n)); dUy(:,:,k) = n*U(:,:,(k-(n+2)))+dUy(:,:,(k-2*n)); case 0 U(:,:,k) = 2*x.*U(:,:,(k-n))+2*y.*U(:,:,(k-(n+1)))-U(:,:,(k-2*n)); dUx(:,:,k) = 2*n*U(:,:,(k-n))+dUx(:,:,(k-2*n)); dUy(:,:,k) = 2*n*U(:,:,(k-(n+1)))+dUy(:,:,(k-2*n)); otherwise U(:,:,k) = x.*U(:,:,(k-n))+y.*U(:,:,(k-(n+m+1)))+x.*U(:,:,(k-(n+1)))-... y.*U(:,:,(k-(n+m)))-U(:,:,(k-2*n)); dUx(:,:,k) = n*U(:,:,(k-n))+n*U(:,:,(k-(n+1)))+dUx(:,:,(k-2*n)); dUy(:,:,k) = n*U(:,:,(k-(n+m+1)))-n*U(:,:,(k-(n+m)))+dUy(:,:,(k-2*n)); endswitch Nnm = sqrt(2*(n+1)); if m == 0 Nnm = Nnm/sqrt(2); endif Z(:,:,k) = Nnm * U(:,:,k); dZx(:,:,k) = Nnm * dUx(:,:,k); dZy(:,:,k) = Nnm * dUy(:,:,k); endfor endfunction %!demo %! Nmgr = 7; # Maximum radial degree number, default = 7 %! Nmodos = ((Nmgr+3)*Nmgr/2)+1; # Mode number, default = 36 %! %! pr = 20; # Pupil radius, mm %! # Let us suppose that we obtain the heights of a biconical surface %! # for a series of points in the xy plane %! Rx = 0.002; # mm⁻¹ %! px = 0.8; %! Ry = 0.001; # mm⁻¹ %! py = 0.5; %! x = pr*(2*rand(200,1) - 1); # mm %! y = pr*(2*rand(200,1) - 1); # mm %! surface = (Rx*x.^2 + Ry*y.^2)/(1+sqrt(1-(px*(Rx*x).^2+py*(Ry*y).^2))); %! sag = max(max(surface)); %! surface = sag - surface; # surface height, mm %! %! # Coordinates normalization %! xnorm=x/pr; %! ynorm=y/pr; %! usefuldata = find(sqrt(x.^2+y.^2) ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} jones_lpplus45() ## @deftypefnx {Function File} {@var{V} =} jones_lpplus45(@var{p}) ## Return the Jones vector for light with linear polarization at +45 degrees. ## ## @itemize @minus ## @item @var{p} is the amplitude of the electric field, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Jones vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{jones_lpminus45} ## @end deftypefn function V = jones_lpplus45(varargin) amplitude_defv = 1; if nargin<1 amplitude = amplitude_defv; else amplitude = varargin{1}; end [amplitude, was_cell] = __c2n__(amplitude, amplitude_defv); if (numel(amplitude) > 1) || was_cell V = cell(size(amplitude)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_lpplus45(amplitude(V_subs{:})); end else V = s_lpplus45(amplitude); end end % helper function function V = s_lpplus45(amplitude) V = [1;1]*amplitude; end %!test %! % test default return value %! V = jones_lpplus45(); %! R = V-[1;1]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! amplitude = rand(1, 1); %! V = jones_lpplus45(amplitude); %! R = V-[1;1]*amplitude; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = jones_lpplus45(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/mueller_mirror.m0000644000000000000000000000013213541155434016761 xustar0030 mtime=1568987932.210840071 30 atime=1568987932.210840071 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_mirror.m0000644000175000017500000000553213541155434017145 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_mirror() ## @deftypefnx {Function File} {@var{A} =} mueller_mirror(@var{[m, n, ...]}) ## @deftypefnx {Function File} {@var{A} =} mueller_mirror(@var{C}) ## Return mirror Mueller matrices, representing a non-polarizing ## optical element. ## ## @itemize @minus ## @item @var{[m, n, ...]} defines the size of the cell array @var{A} ## and therefore the number of mirror matrices returned. ## @item @var{C} is a cell array defining the size of the returned cell array ## @var{A}, @code{size(A)==size(C)}. The content of @var{C} is of not ## evaluated in this case. ## @end itemize ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_unity} ## @end deftypefn function M = mueller_mirror(varargin) retcell = true; if nargin<1 sc = [1,1]; retcell = false; elseif isnumeric(varargin{1}) sc = varargin{1}; else sc = size(varargin{1}); end if prod(sc) > 1 || retcell M = cell(sc); [M{:}] = deal(s_mirror()); else M = s_mirror(); end end % helper function function M = s_mirror() M = zeros(4,4); M(1,1) = 1; M(2,2) = 1; M(3,3) = -1; M(4,4) = -1; end %!test %! % test mirror that is its own inverted element %! A = mueller_mirror(); %! R = (A-1\A); %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test direct size parameter %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! rsize = size(rand(asize)); %! U = mueller_mirror(rsize); %! usize = size(U); %! assert(usize == rsize); %! end %! %!test %! % test indirect size parameter %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! C = cell(asize); %! csize = size(C); %! U = mueller_mirror(C); %! usize = size(U); %! assert(usize == csize); %! end %! optics-0.1.4/inst/PaxHeaders.21787/mueller_rotator.m0000644000000000000000000000013213541155434017141 xustar0030 mtime=1568987932.210840071 30 atime=1568987932.210840071 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_rotator.m0000644000175000017500000000755313541155434017332 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_rotator() ## @deftypefnx {Function File} {@var{M} =} mueller_rotator(@var{p}) ## @deftypefnx {Function File} {@var{M} =} mueller_rotator(..., @var{mode}) ## Return the Mueller matrix for a system rotator. ## ## @itemize @minus ## @item @var{p} is the rotation angle, ranging from 0 to 2*pi, ## if not given or set to [] the default value 0 is used. ## @item @var{mode} is a string defining the units for the angle: ## 'radiant' (default) or 'degree' (0..360) ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{M} of ## Mueller matrices of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_rotate} ## @end deftypefn function M = mueller_rotator(varargin) angle_defv = 0; if nargin<1 angle = angle_defv; else angle = varargin{1}; end [angle, was_cell] = __c2n__(angle, angle_defv); if nargin>=2 && ischar(varargin{end}) if strncmpi(varargin{end},'deg',3) angle = angle*pi()/180.0; end end if (numel(angle) > 1) || was_cell M = cell(size(angle)); M_subs = cell(1,ndims(M)); for mi=1:numel(M) [M_subs{:}] = ind2sub(size(M),mi); M{M_subs{:}} = s_rotator(angle(M_subs{:})); end else M = s_rotator(angle); end end % helper function function M = s_rotator(angle_in_radiants) M = zeros(4,4); % short cut to avoid "*2" in each line angle_in_radiants = angle_in_radiants*2; M(1,1) = 1; M(2,2) = cos(angle_in_radiants); M(2,3) = sin(angle_in_radiants); M(3,2) = -sin(angle_in_radiants); M(3,3) = cos(angle_in_radiants); M(4,4) = 1; end %!test %! % test default return value %! A = mueller_rotator(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial application of rotator %! angle = rand(1, 1); %! A1 = mueller_rotator(angle); %! A2 = mueller_rotator(angle*2); %! R = A1*A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test of serial application of rotator %! angle1 = rand(1, 1); %! angle2 = rand(1, 1); %! A1 = mueller_rotator(angle1); %! A2 = mueller_rotator(angle2); %! A12 = mueller_rotator(angle1+angle2); %! R = A1*A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test different angle value interpretations %! angle = rand(1, 1); %! A1 = mueller_rotator(angle); %! A2 = mueller_rotator(-angle*180/pi(), 'deg'); %! R = A2*A1-mueller_unity(); %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = mueller_rotator(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/jones_unity.m0000644000000000000000000000013213541155434016270 xustar0030 mtime=1568987932.206839993 30 atime=1568987932.206839993 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_unity.m0000644000175000017500000000521613541155434016453 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{JM} =} jones_unity() ## @deftypefnx {Function File} {@var{JA} =} jones_unity(@var{[m, n, ...]}) ## @deftypefnx {Function File} {@var{JA} =} jones_unity(@var{C}) ## Return unity Jones matrices, representing a non-polarizing ## optical element. ## ## @itemize @minus ## @item @var{[m, n, ...]} defines the size of the cell array @var{JA} ## and therefore the number of unity matrices returned. ## @item @var{C} is a cell array defining the size of the returned cell array ## @var{JA}, @code{size(JA)==size(C)}. The content of @var{C} is of not ## evaluated in this case. ## @end itemize ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{jones_mirror} ## @end deftypefn function JM = jones_unity(varargin) retcell = true; if nargin<1 sc = [1,1]; retcell = false; elseif isnumeric(varargin{1}) sc = varargin{1}; else sc = size(varargin{1}); end if prod(sc) > 1 || retcell JM = cell(sc); [JM{:}] = deal(s_unity()); else JM = s_unity(); end end % helper function function JM = s_unity() JM = eye(2); end %!test %! A = jones_unity(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! C = cell(asize); %! csize = size(C); %! U = jones_unity(C); %! usize = size(U); %! assert(usize == csize); %! end %! %!test %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! rsize = size(rand(asize)); %! U = jones_unity(rsize); %! usize = size(U); %! assert(usize == rsize); %! end optics-0.1.4/inst/PaxHeaders.21787/jones.m0000644000000000000000000000013213541155434015040 xustar0030 mtime=1568987932.202839916 30 atime=1568987932.202839916 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones.m0000644000175000017500000001335313541155434015224 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} jones(@var{M}) ## @deftypefnx {Function File} {@var{A} =} jones(@var{M,N,...}) ## Multiply Jones matrices and vectors. ## ## @itemize @minus ## @item @var{M,N,...} define Jones matrices or ## vectors. The function will multiply these from left to right and ## return the result. ## @end itemize ## ## @var{M,N,...} can be passed as either numeric matrices/vectors or ## cell arrays. In this case, the multiplication is carried out in a ## ".*" manner. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{} ## @end deftypefn function A = jones (varargin) if (nargin < 1) print_usage(); end A = varargin{1}; for vi = 2:nargin A = __cellfunc__ (@(M1,M2)(M1*M2), A, varargin{vi}); end end %% Test input validation %!error A = jones(); %!test %! % test singular argument, should just be returned %! M = jones_waveplate(rand(1,1),'wav'); %! MM = jones(M); %! R = MM-M; %! assert(norm(R,inf), 0, 1e-9); %!test %! % send light with horizontal linear polarization through a rotating %! % 1/2-waveplate and subsequent polarizer: final intensity should %! % vary as cos(2*angle)^2. %! % This test feeds jones() with one cell array only! %! angles = 0:360; %! wps = jones_rotate(jones_waveplate(0.5, 'wav'), angles, 'deg'); %! lightin = jones_lphorizontal(); %! lightout = jones(jones_linpolarizer(),wps,lightin); %! ilightout = jones_intensity(lightout); %! R = ilightout-(cosd(angles.*2).^2); %! assert(norm(R,inf), 0, 1e-9); %!test %! % this is a more thorough test: send light with horizontal linear %! % polarization through two rotating 1/2-waveplates (combining to %! % a 1/1-waveplate) and subsequent polarizer: final intensity %! % should not vary! %! % This test feeds jones() with two cell arrays. %! angles = 0:360; %! wps1 = jones_rotate(jones_waveplate(0.5, 'wav'), angles, 'deg'); %! wps2 = jones_rotate(jones_waveplate(0.5, 'wav'), angles, 'deg'); %! lightin = jones_lphorizontal(); %! lightout = jones(jones_linpolarizer(),wps2,wps1,lightin); %! ilightout = jones_intensity(lightout); %! R = ilightout-1; %! assert(norm(R,inf), 0, 1e-9); %!demo %! angles = 0:360; %! wps = jones_rotate(jones_waveplate(0.5, 'wav'), angles, 'deg'); %! lightin = jones_lphorizontal(); %! lightout = jones(jones_linpolarizer(),wps,lightin); %! ilightout = jones_intensity(lightout); %! figure(); %! plot(angles, ilightout); %! title('transmitted intensity [should look like cos(2*a)^2'); %! xlabel('angle of halfwave plate axis'); %! ylabel('intensity [a.u.]'); %! legend('transmitted intensity'); %! % ----------------------------------------------------------------- %! % example 1: send light with horizontal linear polarization through %! % a rotating, perfect halfwave plate and subsequent polarizer: %! % final intensity should vary as cos(2*angle)^2. %!demo %! angles = 0:360; %! wps = jones_rotate(jones_waveplate(0.5, 'wav'), angles, 'deg'); %! wps2 = jones_rotate(jones_waveplate(0.45, 'wav'), angles, 'deg'); %! lightin = jones_lphorizontal(); %! lightout = jones(jones_linpolarizer(),wps,lightin); %! ilightout = jones_intensity(lightout); %! lightout2 = jones(jones_linpolarizer(),wps2,lightin); %! ilightout2 = jones_intensity(lightout2); %! figure(); %! plot(angles, ilightout, angles, ilightout2); %! title('transmitted intensity with perfect and non-perfect halfwave plate'); %! xlabel('angle of halfwave plate axis'); %! ylabel('intensity [a.u.]'); %! legend('perfect (0.5-)plate', 'non-perfect (0.45-)plate'); %! % ----------------------------------------------------------------- %! % example 2: send light with horizontal linear polarization through %! % a rotating, non-perfect halfwave plate and subsequent polarizer: %! % final intensity should deviate from the perfect cos(2*angle)^2 %! % curve, never reaching zero transmission %!demo %! angle = 0:360; %! delay = 0:0.05:1; %! % angles are in rows, delays in columns %! angle_all = repmat(angle, [length(delay), 1]); %! delay_all = repmat(delay', [1, length(angle)]); %! wps3 = jones_waveplate(delay_all, 'wav'); %! wps3 = jones_rotate(wps3, angle_all, 'deg'); %! lightin = jones_lphorizontal(); %! lightout3 = jones(jones_linpolarizer(),wps3,lightin); %! ilightout3 = jones_intensity(lightout3); %! figure(); %! plot(angle, ilightout3); %! title('transmitted intensity with plates of increasing delay'); %! xlabel('angle of plate axis'); %! ylabel('intensity [a.u.]'); %! legend(cellfun(@(x)sprintf('delay=%.2f',x),num2cell(delay),'UniformOutput',false)); %! % ----------------------------------------------------------------- %! % example 3: send light with horizontal linear polarization through %! % rotating waveplates with increasing delay and subsequent polarizer optics-0.1.4/inst/PaxHeaders.21787/mueller_rotate.m0000644000000000000000000000013213541155434016745 xustar0030 mtime=1568987932.210840071 30 atime=1568987932.210840071 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_rotate.m0000644000175000017500000001345313541155434017132 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_rotate() ## @deftypefnx {Function File} {@var{M} =} mueller_rotate(@var{M}, @var{p}) ## @deftypefnx {Function File} {@var{M} =} mueller_rotate(..., @var{mode}) ## Return the Mueller matrix for rotated Mueller elements. ## ## @itemize @minus ## @item @var{M} is the Mueller matrix for the unrotated elements. ## Default value is the Mueller unity matrix. ## @item @var{p} is the rotation angle, default value is 0. ## @item @var{mode} is a string defining the interpretation of the ## angle value: 'radiants' (default) or 'degree'. ## @end itemize ## ## Argument @var{M} can be passed as numeric matrix or as a cell ## array. Argument @var{p} can be passed as a numeric scalar or as a ## cell array. In the case of at least one cell array provided, ## a cell array @var{M} of Mueller matrices is returned. The size of ## @var{M} in each dimension is set to the maximum of the size of ## the passed cell arrays. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_rotator} ## @end deftypefn function M = mueller_rotate(varargin) angle_defv = 0; if nargin<1 M = mueller_unity(); return; elseif nargin<2 M = varargin{1}; return; else C = varargin{1}; angle = varargin{2}; end [angle, angle_was_cell] = __c2n__(angle, angle_defv); if nargin>=3 && ischar(varargin{end}) if strncmpi(varargin{end},'deg',3) angle = angle*pi()/180.0; end end if iscell(C) || (numel(angle) > 1) || angle_was_cell if ~iscell(C) C = {C}; end % adjust dimensions, i.e. fill missing dimensions with 1 sizeC = size(C); sizeangle = size(angle); maxdim = max(length(sizeC),length(sizeangle)); if length(sizeC) < maxdim sizeC = [sizeC, ones(1,maxdim-length(sizeC))]; end if length(sizeangle) < maxdim sizeangle = [sizeangle, ones(1,maxdim-length(sizeangle))]; end % generate Mueller matrices maxsize = max([sizeC;sizeangle]); M = cell(maxsize); M_subs = cell(1,ndims(M)); numelM = numel(M); % flatten C and angle arrays C = C(:); angle = angle(:); numelC = numel(C); numelangle = numel(angle); for mi=1:numelM [M_subs{:}] = ind2sub(size(M),mi); M{M_subs{:}} = s_rotate(C{mod(mi-1,numelC)+1}, angle(mod(mi-1,numelangle)+1)); end else M = s_rotate(C, angle(1)); end end % helper function function M = s_rotate(M, angle_in_radiants) M = s_rotator(-angle_in_radiants)*M*s_rotator(angle_in_radiants); end % helper function function M = s_rotator(angle_in_radiants) M = zeros(4,4); % short cut to avoid "*2" in each line angle_in_radiants = angle_in_radiants*2; M(1,1) = 1; M(2,2) = cos(angle_in_radiants); M(2,3) = sin(angle_in_radiants); M(3,2) = -sin(angle_in_radiants); M(3,3) = cos(angle_in_radiants); M(4,4) = 1; end %!test %! % default return value: unity matrix %! A = mueller_rotate(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % rotation by 0 should do nothing %! delay = rand(1,1); %! M = mueller_linretarder(delay); %! A = mueller_rotate(M, 0); %! R = M-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % undo rotation by 2nd opposite rotation %! delay = rand(1,1); %! angle = rand(1, 1); %! M = mueller_linretarder(delay); %! A1 = mueller_rotate(M, angle); %! A2 = mueller_rotate(A1, -angle); %! R = A2-M; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial application of rotation %! delay = rand(1,1); %! angle1 = rand(1, 1); %! angle2 = rand(1, 1); %! M = mueller_linretarder(delay); %! A1 = mueller_rotate(M, angle1); %! A2 = mueller_rotate(A1, angle2); %! A12 = mueller_rotate(M, angle1+angle2); %! R = A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % testing MODE parameter %! angle = rand(1, 1); %! A1 = mueller_rotate(mueller_waveplate(0.5), angle, 'rad'); %! A2 = mueller_rotate(mueller_waveplate(0.5), angle*180/pi(), 'deg'); %! R = A2-A1; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % size of return value determined by 1st argument %! angle = rand(1,1); %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! rsize = size(rand(asize)); %! C = mueller_rotate(mueller_unity(rsize), angle); %! csize = size(C); %! assert(rsize == csize); %! end %! %!test %! % size if return value determined by 2nd argument %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = mueller_rotate(mueller_unity(), R); %! csize = size(C); %! assert(rsize == csize); %! end %! %!test %! % size if return value determined by both argument %! M = mueller_unity([4,3,2]); %! angle = rand(2,3,4); %! C = mueller_rotate(M, angle); %! csize = size(C); %! assert(csize == [4,3,4]); %! optics-0.1.4/inst/PaxHeaders.21787/stokes_cpleft.m0000644000000000000000000000013213541155434016567 xustar0030 mtime=1568987932.214840148 30 atime=1568987932.214840148 30 ctime=1568987932.234840537 optics-0.1.4/inst/stokes_cpleft.m0000644000175000017500000000553413541155434016755 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} stokes_cpleft() ## @deftypefnx {Function File} {@var{V} =} stokes_cpleft(@var{p}) ## Return the Stokes vector for left-turn circular polarized light. ## ## @itemize @minus ## @item @var{p} is the intensity of the light, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Stokes vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Stokes_parameters, "Stokes parameters"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{stokes_cpright} ## @end deftypefn function V = stokes_cpleft(varargin) intensity_defv = 1; if nargin<1 intensity = intensity_defv; else intensity = varargin{1}; end [intensity, was_cell] = __c2n__(intensity, intensity_defv); if (numel(intensity) > 1) || was_cell V = cell(size(intensity)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_cpleft(intensity(V_subs{:})); end else V = s_cpleft(intensity); end end % helper function function V = s_cpleft(intensity) V = [intensity;0;0;-intensity]; end %!test %! % test default return value %! V = stokes_cpleft(); %! R = V-[1;0;0;-1]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! intensity = rand(1, 1); %! V = stokes_cpleft(intensity); %! R = V-[1;0;0;-1]*intensity; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = stokes_cpleft(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/jones_rotator.m0000644000000000000000000000013213541155434016612 xustar0030 mtime=1568987932.206839993 30 atime=1568987932.206839993 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_rotator.m0000644000175000017500000000735113541155434016777 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{JM} =} jones_rotator() ## @deftypefnx {Function File} {@var{JM} =} jones_rotator(@var{p}) ## @deftypefnx {Function File} {@var{JM} =} jones_rotator(..., @var{mode}) ## Return the Jones matrix for a system rotator. ## ## @itemize @minus ## @item @var{p} is the rotation angle, ranging from 0 to 2*pi, ## if not given or set to [] the default value 0 is used. ## @item @var{mode} is a string defining the units for the angle: ## 'radiant' (default) or 'degree' (0..360) ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{JM} of ## Jones matrices of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{jones_rotate} ## @end deftypefn function JM = jones_rotator(varargin) angle_defv = 0; if nargin<1 angle = angle_defv; else angle = varargin{1}; end [angle, was_cell] = __c2n__(angle, angle_defv); if nargin>=2 && ischar(varargin{end}) if strncmpi(varargin{end},'deg',3) angle = angle*pi()/180.0; end end if (numel(angle) > 1) || was_cell JM = cell(size(angle)); JM_subs = cell(1,ndims(JM)); for jmi=1:numel(JM) [JM_subs{:}] = ind2sub(size(JM),jmi); JM{JM_subs{:}} = s_rotator(angle(JM_subs{:})); end else JM = s_rotator(angle); end end % helper function function JM = s_rotator(angle_in_radiants) JM = zeros(2,2); JM(1,1) = cos(angle_in_radiants); JM(1,2) = sin(angle_in_radiants); JM(2,1) = -sin(angle_in_radiants); JM(2,2) = cos(angle_in_radiants); end %!test %! % test default return value %! A = jones_rotator(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial application of rotator %! angle = rand(1, 1); %! A1 = jones_rotator(angle); %! A2 = jones_rotator(angle*2); %! R = A1*A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test of serial application of rotator %! angle1 = rand(1, 1); %! angle2 = rand(1, 1); %! A1 = jones_rotator(angle1); %! A2 = jones_rotator(angle2); %! A12 = jones_rotator(angle1+angle2); %! R = A1*A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test different angle value interpretations %! angle = rand(1, 1); %! A1 = jones_rotator(angle); %! A2 = jones_rotator(-angle*180/pi(), 'deg'); %! R = A2*A1-jones_unity(); %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = jones_rotator(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/mueller_linretarder.m0000644000000000000000000000013213541155434017762 xustar0030 mtime=1568987932.210840071 30 atime=1568987932.210840071 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_linretarder.m0000644000175000017500000001010613541155434020137 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_linretarder() ## @deftypefnx {Function File} {@var{M} =} mueller_linretarder(@var{p}) ## @deftypefnx {Function File} {@var{M} =} mueller_linretarder(..., @var{mode}) ## Return the Mueller matrix for a linear retarder with long axis ## rotation of 0 degrees. ## ## @itemize @minus ## @item @var{p} is the phase delay in radiant units, i.e. @var{p} is ## ranging between 0 and 2*pi(). If not given or set to [] the default ## value 0 is used. ## @item @var{mode} is a string defining the units for the phase ## delay: 'radiant' (default), 'degree' (0..360) or 'wavelength' ## (0..1). ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{M} of ## Mueller matrices of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_waveplate, mueller_circretarder} ## @end deftypefn function M = mueller_linretarder(varargin) phase_defv = 0; if nargin<1 phase = phase_defv; else phase = varargin{1}; end [phase, was_cell] = __c2n__(phase, phase_defv); if nargin>=2 && ischar(varargin{end}) if strncmpi(varargin{end},'deg',3) phase = phase*pi()/180.0; elseif strncmpi(varargin{end},'wav',3) phase = phase*2*pi(); end end if (numel(phase) > 1) || was_cell M = cell(size(phase)); M_subs = cell(1,ndims(M)); for mi=1:numel(M) [M_subs{:}] = ind2sub(size(M),mi); M{M_subs{:}} = s_linretarder(phase(M_subs{:})); end else M = s_linretarder(phase); end end % helper function function M = s_linretarder(phase_in_pi_units) M = zeros(4,4); M(1,1) = 1; M(2,2) = 1; M(3,3) = cos(phase_in_pi_units); M(3,4) = -sin(phase_in_pi_units); M(4,3) = -M(3,4); M(4,4) = M(3,3); end %!test %! % test default return value %! A = mueller_linretarder(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial application of linear retarder elements %! phase = rand(1, 1); %! A1 = mueller_linretarder(phase); %! A2 = mueller_linretarder(phase*2); %! R = A1*A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test of serial application of retarder elements %! phase1 = rand(1, 1); %! phase2 = rand(1, 1); %! A1 = mueller_linretarder(phase1); %! A2 = mueller_linretarder(phase2); %! A12 = mueller_linretarder(phase1+phase2); %! R = A1*A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test mode %! phase = rand(1, 1); %! A1 = mueller_linretarder(phase); %! A2 = mueller_linretarder(phase*180/pi(), 'deg'); %! A3 = mueller_linretarder(phase/(2*pi()), 'wav'); %! R1 = A1-A2; %! R2 = A1-A3; %! assert(norm(R1,inf)+norm(R2,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = mueller_linretarder(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/jones_waveplate.m0000644000000000000000000000013213541155434017110 xustar0030 mtime=1568987932.206839993 30 atime=1568987932.206839993 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_waveplate.m0000644000175000017500000000664713541155434017304 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{JM} = } jones_waveplate () ## @deftypefnx {Function File} {@var{JM} = } jones_waveplate (@var{p}) ## Return the Jones matrix for a linear wave plate with a phase ## delay given in wavelength units and long axis rotation of 0 degrees. ## ## @itemize @minus ## @item @var{p} is the phase delay in wavelength units, ranging from ## 0 to 1; if not given or set to [] the default value 0 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{JM} of ## Jones matrices of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 14, 2013. ## @end enumerate ## ## @seealso{jones_linretarder} ## @end deftypefn function JM = jones_waveplate(varargin) pilu_defv = 0; if nargin<1 phase_in_lambda_units = pilu_defv; else phase_in_lambda_units = varargin{1}; end [phase_in_lambda_units, was_cell] = __c2n__(phase_in_lambda_units, pilu_defv); if (numel(phase_in_lambda_units) > 1 || was_cell) JM = cell(size(phase_in_lambda_units)); JM_subs = cell(1,ndims(JM)); for jmi=1:numel(JM) [JM_subs{:}] = ind2sub(size(JM),jmi); JM{JM_subs{:}} = s_waveplate(phase_in_lambda_units(JM_subs{:})); end else JM = s_waveplate(phase_in_lambda_units); end end % helper function function JM = s_waveplate(phase_in_lambda_units) JM = zeros(2,2); JM(1,1) = 1; JM(2,2) = exp(-1i*phase_in_lambda_units*2*pi()); end %!test %! % test default return value %! A = jones_waveplate(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %!test %! % test serial application of absorptive elements %! delay = rand(1, 1); %! A1 = jones_waveplate(delay); %! A2 = jones_waveplate(delay*2); %! R = A1*A1-A2; %! assert(norm(R,inf), 0, 1e-9); %!test %! % another test of serial application of absorptive elements %! delay1 = rand(1, 1); %! delay2 = rand(1, 1); %! A1 = jones_waveplate(delay1); %! A2 = jones_waveplate(delay2); %! A12 = jones_waveplate(delay1+delay2); %! R = A1*A2-A12; %! assert(norm(R,inf), 0, 1e-9); %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = jones_waveplate(R); %! csize = size(C); %! assert(csize, rsize); %! end optics-0.1.4/inst/PaxHeaders.21787/mueller_linpolarizer.m0000644000000000000000000000013213541155434020161 xustar0030 mtime=1568987932.210840071 30 atime=1568987932.210840071 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_linpolarizer.m0000644000175000017500000000565313541155434020351 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_linpolarizer() ## @deftypefnx {Function File} {@var{A} =} mueller_linpolarizer(@var{[m, n, ...]}) ## @deftypefnx {Function File} {@var{A} =} mueller_linpolarizer(@var{C}) ## Return the Mueller matrix for an ideal linear polarizer. ## ## @itemize @minus ## @item @var{[m, n, ...]} defines the size of the cell array @var{A} ## and therefore the number of linear polarizer matrices returned. ## @item @var{C} is a cell array defining the size of the returned cell array ## @var{A}, @code{size(A)==size(C)}. The content of @var{C} is of not ## evaluated in this case. ## @end itemize ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_depolarizer} ## @end deftypefn function M = mueller_linpolarizer(varargin) retcell = true; if nargin<1 sc = [1,1]; retcell = false; elseif isnumeric(varargin{1}) sc = varargin{1}; else sc = size(varargin{1}); end if prod(sc) > 1 || retcell M = cell(sc); [M{:}] = deal(s_linpolarizer()); else M = s_linpolarizer(); end end % helper function function M = s_linpolarizer() M = zeros(4,4); M(1,1) = 0.5; M(1,2) = 0.5; M(2,1) = 0.5; M(2,2) = 0.5; end %!test %! % applying a linear polarizer twice is identical to %! % apply it once! %! A = mueller_linpolarizer(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test direct size parameter %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! rsize = size(rand(asize)); %! U = mueller_linpolarizer(rsize); %! usize = size(U); %! assert(usize == rsize); %! end %! %!test %! % test indirect size parameter %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! C = cell(asize); %! csize = size(C); %! U = mueller_linpolarizer(C); %! usize = size(U); %! assert(usize == csize); %! end %! optics-0.1.4/inst/PaxHeaders.21787/stokes_cpright.m0000644000000000000000000000013213541155434016752 xustar0030 mtime=1568987932.214840148 30 atime=1568987932.214840148 30 ctime=1568987932.234840537 optics-0.1.4/inst/stokes_cpright.m0000644000175000017500000000554213541155434017137 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} stokes_cpright() ## @deftypefnx {Function File} {@var{V} =} stokes_cpright(@var{p}) ## Return the Stokes vector for right-turn circular polarized light. ## ## @itemize @minus ## @item @var{p} is the intensity of the light, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Stokes vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Stokes_parameters, "Stokes parameters"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{stokes_cpleft} ## @end deftypefn function V = stokes_cpright(varargin) intensity_defv = 1; if nargin<1 intensity = intensity_defv; else intensity = varargin{1}; end [intensity, was_cell] = __c2n__(intensity, intensity_defv); if (numel(intensity) > 1) || was_cell V = cell(size(intensity)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_cpright(intensity(V_subs{:})); end else V = s_cpright(intensity); end end % helper function function V = s_cpright(intensity) V = [intensity;0;0;intensity]; end %!test %! % test default return value %! V = stokes_cpright(); %! R = V-[1;0;0;1]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! intensity = rand(1, 1); %! V = stokes_cpright(intensity); %! R = V-[1;0;0;1]*intensity; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = stokes_cpright(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/@abcd0000644000000000000000000000013213541155434014460 xustar0030 mtime=1568987932.198839838 30 atime=1568987932.234840537 30 ctime=1568987932.234840537 optics-0.1.4/inst/@abcd/0000755000175000017500000000000013541155434014714 5ustar00olafolaf00000000000000optics-0.1.4/inst/@abcd/PaxHeaders.21787/trace.m0000644000000000000000000000013213541155434016011 xustar0030 mtime=1568987932.198839838 30 atime=1568987932.198839838 30 ctime=1568987932.234840537 optics-0.1.4/inst/@abcd/trace.m0000644000175000017500000001133713541155434016175 0ustar00olafolaf00000000000000## Copyright (C) 2015 Andreas Weber ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{rout} = } trace(@var{abcd}, @var{rin}, @var{do_plot}) ## Trace the rays @var{rin} through @var{abcd}. ## If @var{do_plot} is true, create also a plot with the trace. ## @end deftypefn function rout = trace (abcd, rin, do_plot = false) rout = rin; e = abcd.elements; x_tmp = 0; x_dir = 1; len = (numel (e) / 2) + 1; x = y = zeros (len, columns (rin)); y(1, :) = rin (1, :); k = 1; while (numel(e) > 0) k += 1; switch (e{1}) case {"propagation"} d = e{2}; tmp = [1, d; 0 1]; x_tmp += d * x_dir; case {"thin-lens"} f = e{2}; tmp = [1, 0; -1/f, 1]; plot_elements(end + 1).x = x_tmp; plot_elements(end).text = sprintf ("thin lens\nf = %.2f", f); case {"flat-refraction"} n1 = e{2}(1); n2 = e{2}(2); tmp = [1, 0; 0, n1/n2]; plot_elements(end + 1).x = x_tmp; plot_elements(end).text = sprintf ("flat refraction\nn1 = %.2f\nn2 = %.2f", n1, n2); case {"curved-refraction"} n1 = e{2}(1); n2 = e{2}(2); R = e{2}(3); tmp = [1, 0; (n1-n2)/(R*n2), n1/n2]; plot_elements(end + 1).x = x_tmp; plot_elements(end).text = sprintf ("curved refraction\nn1 = %.2f\nn2 = %.2f\nR = %.2f", n1, n2, R); case {"flat-mirror"} tmp = eye (2); x_dir *= -1; plot_elements(end + 1).x = x_tmp; plot_elements(end).text = sprintf ("flat mirror"); case {"curved-mirror"} R = e{2}(1) x_dir *= -1; tmp = [1, 0; 2/R, 1]; plot_elements(end + 1).x = x_tmp; plot_elements(end).text = sprintf ("curved mirror\nR = %.2f", R); case {"thick-lens"} n1 = e{2}(1); n2 = e{2}(2); R1 = e{2}(3); R2 = e{2}(4); t = e{2}(5); ### tmp = [1, 0; (n1-n2)/(R1*n2), n1/n2]; plot_elements(end + 1).x = x_tmp; plot_elements(end).text = sprintf ("thick lens\nfirst surface\nn1 = %.2f\nn2 = %.2f\nR1 = %.2f", n1, n2, R1); rout = tmp * rout; x(k, :) = x_tmp * ones (1, columns (rin)); y(k, :) = rout (1, :); k += 1; ### x_tmp += t * x_dir; rout = [1, t; 0, 1] * rout; x(k, :) = x_tmp * ones (1, columns (rin)); y(k, :) = rout (1, :); k += 1; ### tmp = [1, 0; (n2-n1)/(R2*n1), n2/n1]; plot_elements(end + 1).x = x_tmp; plot_elements(end).text = sprintf ("thick lens\nsecond surface\nn1 = %.2f\nn2 = %.2f\nR2 = %.2f", n1, n2, R2); otherwise error ("Unknown element \"%s\"", e{1}); endswitch e(1:2) = []; rout = tmp * rout; x(k, :) = x_tmp * ones (1, columns (rin)); y(k, :) = rout (1, :); endwhile if (do_plot) plot (x, y); hold on tmp_y = max (abs (y(:))); for k = 1: numel (plot_elements) plot ([plot_elements(k).x, plot_elements(k).x], [tmp_y, -tmp_y]); text (plot_elements(k).x, tmp_y, plot_elements(k).text, "verticalalignment", "bottom", "horizontalalignment", "center"); endfor hold off endif endfunction %!demo %! s = abcd ("propagation", 10, %! "thin-lens", 5, %! "propagation", 12, %! "thin-lens", 10, %! "propagation", 15); %! %! rin = [1 0.5 0 -0.5 -1; 0 0 0 0 0]; %! rout = trace(s, rin, true) %!demo %! s = abcd ("propagation", 8, %! "thin-lens", 8, %! "propagation", 3, %! "flat-mirror", [], %! "propagation", 15); %! %! rin = [1 0.5 0 -0.5 -1; 0 0 0 0 0]; %! rout = trace(s, rin, true) %~ %!demo %! s = abcd ("propagation", 2, %! "flat-refraction", [1, 1.4], %! "propagation", 1, %! "flat-refraction", [1.4, 1], %! "propagation", 2); %! %! rin = [-1 -1 -1 -1 -1; 0.0 0.1 0.2 0.3 0.4]; %! rout = trace(s, rin, true) %!demo %! s = abcd ("propagation", 6, %! "thick-lens", [1, 1.4, 5, -4, 2], %! "propagation", 4); %! %! rin = [0 0 0 0 0; 0.0 0.1 0.2 0.3 0.4]; %! rout = trace(s, rin, true) %! axis([0 12 -2 4]) optics-0.1.4/inst/@abcd/PaxHeaders.21787/abcd.m0000644000000000000000000000013213541155434015604 xustar0030 mtime=1568987932.198839838 30 atime=1568987932.198839838 30 ctime=1568987932.234840537 optics-0.1.4/inst/@abcd/abcd.m0000644000175000017500000000314613541155434015767 0ustar00olafolaf00000000000000## Copyright (C) 2015 Andreas Weber ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software ## Foundation; either version 3 of the License, or (at your option) any later ## version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ## details. ## ## You should have received a copy of the GNU General Public License along with ## this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{S} = } abcd(@var{element}, @var{value}, @dots{}) ## Create an abcd matrix chain from element/value pairs. ## ## https://en.wikipedia.org/wiki/Ray_transfer_matrix_analysis ## ## Valid elements are: ## @table @samp ## ## @item propagation ## value: [distance] ## ## @item thin-lens ## value: [focal_length] ## ## @item flat-refraction ## value: [n1, n2] ## ## @item curved-refraction ## value: [n1, n2, R] ## ## @item flat-mirror ## value: [] ## ## @item curved-mirror ## value: [R] ## ## @item thick-lens ## value: [n1, n2, R1, R2, t] ## ## @end table ## ## See @code{demo @@abcd/trace} for examples. ## ## @seealso{trace} ## @end deftypefn function ret = abcd (varargin) if (mod (nargin, 2) != 0) error ("Input has to be element, value pairs.") endif s.elements = varargin; ret = class (s, "abcd"); ## check inputs rout = trace (ret, [1; 1]); endfunction optics-0.1.4/inst/PaxHeaders.21787/mueller_ismueller.m0000644000000000000000000000013213541155434017450 xustar0030 mtime=1568987932.210840071 30 atime=1568987932.210840071 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_ismueller.m0000644000175000017500000000665513541155434017643 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{t} =} mueller_ismueller(@var{M}) ## @deftypefnx {Function File} {@var{[t,u,...]} =} mueller_ismueller(@var{M,N,...}) ## Check computational validity of Mueller matrix or matrices. ## ## @itemize @minus ## @item @var{M,N,...} define potential (arrays of) Mueller matrices. ## After checking the parameters for validity, the function returns ## boolean arrays @var{t,u,...} of corresponding size. ## @end itemize ## ## @var{M,N,...} can be passed as either numeric matrices or cell arrays ## of potential Mueller matrices. ## ## Note that this function does not check the physical integrity of ## the given matrices; to check that use mueller_checkmueller() instead. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_checkmueller} ## @end deftypefn function varargout = mueller_ismueller(varargin) if nargin==0 print_usage(); return; end % loop over parameters for vi=1:nargin M = varargin{vi}; if iscell(M) ismueller = false(size(M)); M_subs = cell(1,ndims(M)); for mi=1:numel(M) [M_subs{:}] = ind2sub(size(M),mi); ismueller(M_subs{:}) = s_ismueller(M{M_subs{:}}); end else ismueller = s_ismueller(M); end varargout{vi} = ismueller; end end % helper function function isMueller = s_ismueller(M) if ~isnumeric(M) isMueller = false; elseif ~all(size(M)==[4,4]) isMueller = false; else isMueller = true; end end %!test %! % test type check %! A1 = mueller_unity(); %! A2 = char(A1); %! t1 = mueller_ismueller(A1); %! t2 = mueller_ismueller(A2); %! assert(t1 && ~t2); %! %!test %! % test size check %! A1 = mueller_unity(); %! A2 = A1; %! A2(5,5) = 1; %! t1 = mueller_ismueller(A1); %! t2 = mueller_ismueller(A2); %! assert(t1 && ~t2); %! %!test %! % test size of return value %! A1 = mueller_mirror([2,3,4]); %! A1{2,2,2} = 0; %! A2 = mueller_mirror([4,3,2]); %! A2{1,1,1} = 0; %! t1 = mueller_ismueller(A1); %! t2 = mueller_ismueller(A2); %! assert((size(A1)==size(t1)) && (size(A2)==size(t2))); %! %!test %! % test indivial elements of return value %! A1 = mueller_mirror([2,3,4]); %! A1{2,2,2} = 0; %! A2 = mueller_mirror([4,3,2]); %! A2{1,1,1} = 0; %! t1 = mueller_ismueller(A1); %! t2 = mueller_ismueller(A2); %! assert(t1(1,1,1) && ~t1(2,2,2) && ~t2(1,1,1) && t2(2,2,2)); optics-0.1.4/inst/PaxHeaders.21787/mueller_circretarder.m0000644000000000000000000000013213541155434020120 xustar0030 mtime=1568987932.206839993 30 atime=1568987932.206839993 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_circretarder.m0000644000175000017500000001007213541155434020277 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_circretarder() ## @deftypefnx {Function File} {@var{M} =} mueller_circretarder(@var{p}) ## @deftypefnx {Function File} {@var{M} =} mueller_circretarder(..., @var{mode}) ## Return the Mueller matrix for a circular retarder element. ## ## @itemize @minus ## @item @var{p} is the phase delay in radiant units, i.e. @var{p} is ## ranging between 0 and 2*pi(). If not given or set to [] the default ## value 0 is used. ## @item @var{mode} is a string defining the units for the phase ## delay: 'radiant' (default), 'degree' (0..360) or 'wavelength' ## (0..1). ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{M} of ## Mueller matrices of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_waveplate, mueller_linretarder} ## @end deftypefn function M = mueller_circretarder(varargin) phase_defv = 0; if nargin<1 phase = phase_defv; else phase = varargin{1}; end [phase, was_cell] = __c2n__(phase, phase_defv); if nargin>=2 && ischar(varargin{end}) if strncmpi(varargin{end},'deg',3) phase = phase*pi()/180.0; elseif strncmpi(varargin{end},'wav',3) phase = phase*2*pi(); end end if (numel(phase) > 1) || was_cell M = cell(size(phase)); M_subs = cell(1,ndims(M)); for mi=1:numel(M) [M_subs{:}] = ind2sub(size(M),mi); M{M_subs{:}} = s_circretarder(phase(M_subs{:})); end else M = s_circretarder(phase); end end % helper function function M = s_circretarder(phase_in_pi_units) M = zeros(4,4); M(1,1) = 1; M(2,2) = cos(phase_in_pi_units); M(2,3) = -sin(phase_in_pi_units); M(3,2) = -M(2,3); M(3,3) = M(2,2); M(4,4) = 1; end %!test %! % test default return value %! A = mueller_circretarder(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial application of circular retarder elements %! phase = rand(1, 1); %! A1 = mueller_circretarder(phase); %! A2 = mueller_circretarder(phase*2); %! R = A1*A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test of serial application of retarder elements %! phase1 = rand(1, 1); %! phase2 = rand(1, 1); %! A1 = mueller_circretarder(phase1); %! A2 = mueller_circretarder(phase2); %! A12 = mueller_circretarder(phase1+phase2); %! R = A1*A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test mode %! phase = rand(1, 1); %! A1 = mueller_circretarder(phase); %! A2 = mueller_circretarder(phase*180/pi(), 'deg'); %! A3 = mueller_circretarder(phase/(2*pi()), 'wav'); %! R1 = A1-A2; %! R2 = A1-A3; %! assert(norm(R1,inf)+norm(R2,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = mueller_circretarder(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/stokes_isstokes.m0000644000000000000000000000013213541155434017156 xustar0030 mtime=1568987932.214840148 30 atime=1568987932.214840148 30 ctime=1568987932.234840537 optics-0.1.4/inst/stokes_isstokes.m0000644000175000017500000000676313541155434017351 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{t} =} stokes_isstokes(@var{V}) ## @deftypefnx {Function File} {@var{[t,u,...]} =} stokes_isstokes(@var{V,W,...}) ## Check validity of Stokes vector or vectors. ## ## @itemize @minus ## @item @var{V,W,...} define potential (arrays of) Stokes vectors. ## After checking the parameters for validity, the function returns ## boolean arrays @var{t,u,...} of corresponding size. ## @end itemize ## ## @var{V,W,...} can be passed as either numeric vectors or cell arrays ## of potential Stokes vectors. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Stokes_parameters, "Stokes parameters"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{stokes_intensity, stokes_degpolarization} ## @end deftypefn function varargout = stokes_isstokes(varargin) if nargin==0 print_usage(); return; end % loop over parameters for ni=1:nargin V = varargin{ni}; if iscell(V) isstokes = false(size(V)); V_subs = cell(1,ndims(V)); for vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),vi); isstokes(V_subs{:}) = s_isstokes(V{V_subs{:}}); end else isstokes = s_isstokes(V); end varargout{ni} = isstokes; end end % helper function function isstokes = s_isstokes(V) if ~isnumeric(V) isstokes = false; elseif ~all(size(V)==[4,1]) isstokes = false; else isstokes = true; end end %!test %! % test type check %! V1 = stokes_unpolarized(); %! V2 = char(V1); %! t1 = stokes_isstokes(V1); %! t2 = stokes_isstokes(V2); %! assert(t1 && ~t2); %! %!test %! % test size check %! V1 = stokes_unpolarized(); %! V2 = V1; %! V2(5,1) = 1; %! t1 = stokes_isstokes(V1); %! t2 = stokes_isstokes(V2); %! assert(t1 && ~t2); %! %!test %! % test size of return value %! V1 = stokes_unpolarized(ones(2,3,4)); %! V1{2,2,2} = 0; %! V2 = stokes_unpolarized(ones(4,3,2)); %! V2{1,1,1} = 0; %! t1 = stokes_isstokes(V1); %! t2 = stokes_isstokes(V2); %! assert((size(t1)==size(V1)) && (size(t2)==size(V2))); %! %!test %! % test size of return value %! V1 = stokes_unpolarized(ones(2,3,4)); %! V2 = stokes_unpolarized(1); %! [t1,t2] = stokes_isstokes(V1,V2); %! assert((size(t1)==size(V1)) && (size(t2)==[1,1])); %! %!test %! % test indivial elements of return value %! V1 = stokes_unpolarized(ones(2,3,4)); %! V1{2,2,2} = 0; %! V2 = stokes_unpolarized(ones(4,3,2)); %! V2{1,1,1} = 0; %! t1 = stokes_isstokes(V1); %! t2 = stokes_isstokes(V2); %! assert(t1(1,1,1) && ~t1(2,2,2) && ~t2(1,1,1) && t2(2,2,2)); optics-0.1.4/inst/PaxHeaders.21787/stokes_lpplus45.m0000644000000000000000000000013213541155434017002 xustar0030 mtime=1568987932.218840227 30 atime=1568987932.218840227 30 ctime=1568987932.234840537 optics-0.1.4/inst/stokes_lpplus45.m0000644000175000017500000000557013541155434017170 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} stokes_lpplus45() ## @deftypefnx {Function File} {@var{V} =} stokes_lpplus45(@var{p}) ## Return the Stokes vector for light with linear polarization at +45 degrees. ## ## @itemize @minus ## @item @var{p} is the intensity of the light, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Stokes vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Stokes_parameters, "Stokes parameters"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{stokes_lpminus45} ## @end deftypefn function V = stokes_lpplus45(varargin) intensity_defv = 1; if nargin<1 intensity = intensity_defv; else intensity = varargin{1}; end [intensity, was_cell] = __c2n__(intensity, intensity_defv); if (numel(intensity) > 1) || was_cell V = cell(size(intensity)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_lpplus45(intensity(V_subs{:})); end else V = s_lpplus45(intensity); end end % helper function function V = s_lpplus45(intensity) V = [intensity;0;intensity;0]; end %!test %! % test default return value %! V = stokes_lpplus45(); %! R = V-[1;0;1;0]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! intensity = rand(1, 1); %! V = stokes_lpplus45(intensity); %! R = V-[1;0;1;0]*intensity; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = stokes_lpplus45(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/zernike_osa_ansi_to_mn.m0000644000000000000000000000013213541155434020441 xustar0030 mtime=1568987932.218840227 30 atime=1568987932.218840227 30 ctime=1568987932.234840537 optics-0.1.4/inst/zernike_osa_ansi_to_mn.m0000644000175000017500000001033213541155434020617 0ustar00olafolaf00000000000000## Copyright (C) 2019 José Ramom Flores das Seixas ## ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see . ## -*- texinfo -*- ## @deftypefn {} {[@var{m}, @var{n}] =} zernike_osa_ansi_to_mn (@var{j}) ## Convert OSA/ANSI single-index @var{j} to double index @var{m} (Azimuthal ## degree) and @var{n} (Radial degree). ## ## Example ## @example ## [m,n] = zernike_osa_ansi_to_mn(4) ## @result{} [0, 2] ## @end example ## ## References: ## ## @enumerate ## @item Thibos, L.N, Applegate, R.A., Schwiegerling, J.T. & Webb, R., ## Standards for reporting the optical aberrations of eyes. Journal of ## refractive surgery , 18 (5), S652-S660 (2002). ## @item @url{https://en.wikipedia.org/wiki/Zernike_polynomials#OSA/ANSI_standard_indices, ## OSA/ANSI standard indices of Zernike polynomials}, last retrieved on ## July 2109. ## @end enumerate ## ## @seealso{zernike_noll_to_mn, zernikes_and_derivatives_cartesian_OSA, zernike_cartesian, zernike_name, zernike_polar, zernike_R_poly} ## ## @end deftypefn function [m, n] = zernike_osa_ansi_to_mn (j) if (nargin != 1 || nargout != 2) print_usage (); elseif (any (j(:) < 0 | j(:) != fix (j(:))) || ! isvector (j)) error ("zernike_osa_ansi_to_mn: j has to be a vector with integers >=0"); endif n = ceil((-3+sqrt(9+8*j))/2); m = 2*j - n .* (n+2); endfunction %!test %! [m,n]=zernike_osa_ansi_to_mn(0); %! assert([m n],[0 0]) %! [m,n]=zernike_osa_ansi_to_mn(1); %! assert([m n],[-1 1]) %! [m,n]=zernike_osa_ansi_to_mn(2); %! assert([m n],[1 1]) %! [m,n]=zernike_osa_ansi_to_mn(3); %! assert([m n],[-2 2]) %! [m,n]=zernike_osa_ansi_to_mn(4); %! assert([m n],[0 2]) %! [m,n]=zernike_osa_ansi_to_mn(5); %! assert([m n],[2 2]) %! [m,n]=zernike_osa_ansi_to_mn(6); %! assert([m n],[-3 3]) %! [m,n]=zernike_osa_ansi_to_mn(7); %! assert([m n],[-1 3]) %! [m,n]=zernike_osa_ansi_to_mn(8); %! assert([m n],[1 3]) %! [m,n]=zernike_osa_ansi_to_mn(9); %! assert([m n],[3 3]) %! [m,n]=zernike_osa_ansi_to_mn(10); %! assert([m n],[-4 4]) %! [m,n]=zernike_osa_ansi_to_mn(11); %! assert([m n],[-2 4]) %! [m,n]=zernike_osa_ansi_to_mn(12); %! assert([m n],[0 4]) %! [m,n]=zernike_osa_ansi_to_mn(13); %! assert([m n],[2 4]) %! [m,n]=zernike_osa_ansi_to_mn(14); %! assert([m n],[4 4]) %! [m,n]=zernike_osa_ansi_to_mn(15); %! assert([m n],[-5 5]) %! [m,n]=zernike_osa_ansi_to_mn(16); %! assert([m n],[-3 5]) %! [m,n]=zernike_osa_ansi_to_mn(17); %! assert([m n],[-1 5]) %! [m,n]=zernike_osa_ansi_to_mn(18); %! assert([m n],[1 5]) %! [m,n]=zernike_osa_ansi_to_mn(19); %! assert([m n],[3 5]) %! [m,n]=zernike_osa_ansi_to_mn(20); %! assert([m n],[5 5]) %! [m,n]=zernike_osa_ansi_to_mn(21); %! assert([m n],[-6 6]) %! [m,n]=zernike_osa_ansi_to_mn(22); %! assert([m n],[-4 6]) %! [m,n]=zernike_osa_ansi_to_mn(23); %! assert([m n],[-2 6]) %! [m,n]=zernike_osa_ansi_to_mn(24); %! assert([m n],[0 6]) %! [m,n]=zernike_osa_ansi_to_mn(25); %! assert([m n],[2 6]) %! [m,n]=zernike_osa_ansi_to_mn(26); %! assert([m n],[4 6]) %! [m,n]=zernike_osa_ansi_to_mn(27); %! assert([m n],[6 6]) %! [m,n]=zernike_osa_ansi_to_mn(28); %! assert([m n],[-7 7]) %! [m,n]=zernike_osa_ansi_to_mn(29); %! assert([m n],[-5 7]) %! [m,n]=zernike_osa_ansi_to_mn(30); %! assert([m n],[-3 7]) %! [m,n]=zernike_osa_ansi_to_mn(31); %! assert([m n],[-1 7]) %! [m,n]=zernike_osa_ansi_to_mn(32); %! assert([m n],[1 7]) %! [m,n]=zernike_osa_ansi_to_mn(33); %! assert([m n],[3 7]) %! [m,n]=zernike_osa_ansi_to_mn(34); %! assert([m n],[5 7]) %! [m,n]=zernike_osa_ansi_to_mn(35); %! assert([m n],[7 7]) ## vector test %!test %! [m,n]=zernike_osa_ansi_to_mn([2 7 15 35]); %! assert(m,[1 -1 -5 7]) %! assert(n,[1 3 5 7]) optics-0.1.4/inst/PaxHeaders.21787/stokes_unpolarized.m0000644000000000000000000000013213541155434017646 xustar0030 mtime=1568987932.218840227 30 atime=1568987932.218840227 30 ctime=1568987932.234840537 optics-0.1.4/inst/stokes_unpolarized.m0000644000175000017500000000561213541155434020031 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} stokes_unpolarized() ## @deftypefnx {Function File} {@var{V} =} stokes_unpolarized(@var{p}) ## Return the Stokes vector for unpolarized light. ## ## @itemize @minus ## @item @var{p} is the intensity of the light, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Stokes vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Stokes_parameters, "Stokes parameters"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{stokes_lphorizontal, stokes_degpolarization} ## @end deftypefn function V = stokes_unpolarized(varargin) intensity_defv = 1; if nargin<1 intensity = intensity_defv; else intensity = varargin{1}; end [intensity, was_cell] = __c2n__(intensity, intensity_defv); if (numel(intensity) > 1) || was_cell V = cell(size(intensity)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_unpolarized(intensity(V_subs{:})); end else V = s_unpolarized(intensity); end end % helper function function V = s_unpolarized(intensity) V = [intensity;0;0;0]; end %!test %! % test default return value %! V = stokes_unpolarized(); %! R = V-[1;0;0;0]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! intensity = rand(1, 1); %! V = stokes_unpolarized(intensity); %! R = V-[1;0;0;0]*intensity; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = stokes_unpolarized(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/mueller_waveplate.m0000644000000000000000000000013213541155434017437 xustar0030 mtime=1568987932.214840148 30 atime=1568987932.214840148 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_waveplate.m0000644000175000017500000000705413541155434017624 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_waveplate() ## @deftypefnx {Function File} {@var{M} =} mueller_waveplate(@var{p}) ## Return the Mueller matrix for a linear wave plate with a phase ## delay given in wavelength units and long axis rotation of 0 degrees. ## ## @itemize @minus ## @item @var{p} is the phase delay in wavelength units, ranging from ## 0 to 1; if not given or set to [] the default value 0 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{M} of ## Mueller matrices of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_linretarder, mueller_circretarder} ## @end deftypefn function M = mueller_waveplate(varargin) pilu_defv = 0; if nargin<1 phase_in_lambda_units = pilu_defv; else phase_in_lambda_units = varargin{1}; end [phase_in_lambda_units, was_cell] = __c2n__(phase_in_lambda_units, pilu_defv); if (numel(phase_in_lambda_units) > 1) || was_cell M = cell(size(phase_in_lambda_units)); M_subs = cell(1,ndims(M)); for mi=1:numel(M) [M_subs{:}] = ind2sub(size(M),mi); M{M_subs{:}} = s_waveplate(phase_in_lambda_units(M_subs{:})); end else M = s_waveplate(phase_in_lambda_units); end end % helper function function M = s_waveplate(phase_in_lambda_units) M = zeros(4,4); M(1,1) = 1; M(2,2) = 1; M(3,3) = cos(phase_in_lambda_units*2*pi()); M(3,4) = -sin(phase_in_lambda_units*2*pi()); M(4,3) = -M(3,4); M(4,4) = M(3,3); end %!test %! % test default return value %! A = mueller_waveplate(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial application of absorptive elements %! delay = rand(1, 1); %! A1 = mueller_waveplate(delay); %! A2 = mueller_waveplate(delay*2); %! R = A1*A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test of serial application of absorptive elements %! delay1 = rand(1, 1); %! delay2 = rand(1, 1); %! A1 = mueller_waveplate(delay1); %! A2 = mueller_waveplate(delay2); %! A12 = mueller_waveplate(delay1+delay2); %! R = A1*A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = mueller_waveplate(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/mueller_absorber.m0000644000000000000000000000013213541155434017246 xustar0030 mtime=1568987932.206839993 30 atime=1568987932.206839993 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_absorber.m0000644000175000017500000000643513541155434017435 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_absorber() ## @deftypefnx {Function File} {@var{M} =} mueller_absorber(@var{p}) ## Return Mueller matrices for a (partial) absorber. ## ## @itemize @minus ## @item @var{p} is the relative absorbance, ranging from 0 to 1, ## if not given or set to [] the default value 0 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{M} of ## Mueller matrices of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_lindiattenuator, mueller_circdiattenuator} ## @end deftypefn function M = mueller_absorber(varargin) absorption_defv = 0; if nargin<1 absorption = absorption_defv; else absorption = varargin{1}; end [absorption, was_cell] = __c2n__(absorption, absorption_defv); if (numel(absorption) > 1) || was_cell M = cell(size(absorption)); M_subs = cell(1,ndims(M)); for mi=1:numel(M) [M_subs{:}] = ind2sub(size(M),mi); M{M_subs{:}} = s_absorber(absorption(M_subs{:})); end else M = s_absorber(absorption); end end % helper function function M = s_absorber(absorption) M = eye(4)*(1-absorption); end %!test %! % test default return value %! A = mueller_absorber(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial appliation of absorptive elements %! absorption = rand(1, 1); %! A1 = mueller_absorber(absorption); %! A2 = mueller_absorber(1-(1-absorption)^2); %! R = A1*A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test of serial appliation of absorptive elements %! absorption1 = rand(1, 1); %! absorption2 = rand(1, 1); %! A1 = mueller_absorber(absorption1); %! A2 = mueller_absorber(absorption2); %! A12 = mueller_absorber(1-((1-absorption1)*(1-absorption2))); %! R = A1*A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = mueller_absorber(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/jones_lindiattenuator.m0000644000000000000000000000013213541155434020326 xustar0030 mtime=1568987932.202839916 30 atime=1568987932.202839916 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_lindiattenuator.m0000644000175000017500000001343113541155434020507 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} jones_lindiattenuator() ## @deftypefnx {Function File} {@var{M} =} jones_lindiattenuator(@var{d}) ## @deftypefnx {Function File} {@var{M} =} jones_lindiattenuator(@var{px},@var{py}) ## @deftypefnx {Function File} {@var{M} =} jones_lindiattenuator(..., @var{mode}) ## Return the Jones matrix for a linear diattenuator at zero ## rotation. ## ## @itemize @minus ## @item @var{d} is the diattenuation of the element, i.e. ## @code{d=(px-py)/(px+py)}. Reversibly, transmission in y direction ## is @code{(1-d)/(1+d)}, if transmission in x direction is 1. ## @item @var{px} is the transmittance in x direction. ## @item @var{py} is the transmittance in y direction. ## @item @var{mode} is a string defining the interpretation of ## transmittance values: 'intensity' (default) or 'amplitude'. ## @end itemize ## ## Arguments @var{d}, @var{px} or @var{py} can be passed as a scalar ## or as a matrix or as a cell array. In the two latter cases, a cell ## array @var{M} of Jones matrices is returned. The size of @var{M} ## is set to the maximum of the parameters' size. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{jones_linpolarizer} ## @end deftypefn function JM = jones_lindiattenuator(varargin) if nargin<1 px = 1; py = 1; was_cell = false; elseif nargin==1 px = varargin{1}; [px, was_cell] = __c2n__(px, 0); py = (1-px)./(1+px); px(:) = 1; else px = varargin{1}; [px, was_cellx] = __c2n__(px, 1); py = varargin{2}; [py, was_celly] = __c2n__(py, 1); was_cell = was_cellx || was_celly; end % check mode s_function = @s_lindiattenuator_int; if nargin>=2 && ischar(varargin{end}) if strncmpi(varargin{end},'amp',3) s_function = @s_lindiattenuator_amp; end end % any matrix in parameters? if (any([numel(px),numel(py)] > 1)) || was_cell % adjust dimensions, i.e. fill missing dimensions with 1 spx = size(px); spy = size(py); maxdim = max([length(spx),length(spy)]); if length(spx) < maxdim spx = [spx, ones(1,maxdim-length(spx))]; end if length(spy) < maxdim spy = [spy, ones(1,maxdim-length(spy))]; end % generate Jones matrices maxsize = max([spx;spy]); JM = cell(maxsize); JM_subs = cell(1,ndims(JM)); numelJM = numel(JM); % flatten parameter arrays px = px(:); py = py(:); numelpx = numel(px); numelpy = numel(py); for jmi=1:numelJM [JM_subs{:}] = ind2sub(size(JM),jmi); JM{JM_subs{:}} = s_function(px(mod(jmi-1,numelpx)+1), py(mod(jmi-1,numelpy)+1)); end else JM = s_function(px, py); end end % helper function function JM = s_lindiattenuator_amp(px_in_amplitude_domain,py_in_amplitude_domain) JM = zeros(2,2); JM(1,1) = px_in_amplitude_domain; JM(2,2) = py_in_amplitude_domain; end % helper function 2 function JM = s_lindiattenuator_int(kx_in_intensity_domain,ky_in_intensity_domain) JM = zeros(2,2); JM(1,1) = sqrt(kx_in_intensity_domain); JM(2,2) = sqrt(ky_in_intensity_domain); end %!test %! % test default return value %! A = jones_lindiattenuator(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test equality of providing diattenuation or kx and ky %! d = rand(1, 1); %! kx = 1; %! ky = (1-d)./(1+d); %! A1 = jones_lindiattenuator(d); %! A2 = jones_lindiattenuator(kx, ky); %! R = A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial application of linear diattenuators %! kx = rand(1, 1); %! ky = rand(1, 1); %! A1 = jones_lindiattenuator(kx,ky); %! A2 = jones_lindiattenuator(kx*kx,ky*ky); %! R = A1*A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test of serial application of retarder elements %! kx1 = rand(1, 1); %! kx2 = rand(1, 1); %! ky1 = rand(1, 1); %! ky2 = rand(1, 1); %! A1 = jones_lindiattenuator(kx1,ky1); %! A2 = jones_lindiattenuator(kx2,ky2); %! A12 = jones_lindiattenuator(kx1*kx2,ky1*ky2); %! R = A1*A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test mode %! kx = rand(1, 1); %! ky = rand(1, 1); %! A1 = jones_lindiattenuator(kx,ky); %! A2 = jones_lindiattenuator(kx,ky,'int'); %! A3 = jones_lindiattenuator(sqrt(kx),sqrt(ky),'amp'); %! R1 = A1-A2; %! R2 = A1-A3; %! assert(norm(R1,inf)+norm(R2,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = jones_lindiattenuator(R); %! csize = size(C); %! assert(rsize == csize); %! end %! %!test %! % another test correct size of return values %! kx = rand(3,4,5); %! ky = rand(5,4,3); %! C = jones_lindiattenuator(kx,ky); %! csize = size(C); %! assert(csize == [5,4,5]); optics-0.1.4/inst/PaxHeaders.21787/jones_mirror.m0000644000000000000000000000013213541155434016432 xustar0030 mtime=1568987932.206839993 30 atime=1568987932.206839993 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_mirror.m0000644000175000017500000000546113541155434016617 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{JM} =} jones_mirror() ## @deftypefnx {Function File} {@var{JA} =} jones_mirror(@var{[m, n, ...]}) ## @deftypefnx {Function File} {@var{JA} =} jones_mirror(@var{C}) ## Return Jones matrices, representing a non-polarizing ## optical element. ## ## @itemize @minus ## @item @var{[m, n, ...]} defines the size of the cell array @var{JA} ## and therefore the number of mirror matrices returned. ## @item @var{C} is a cell array defining the size of the returned cell array ## @var{JA}, @code{size(JA)==size(C)}. The content of @var{C} is of not ## evaluated in this case. ## @end itemize ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{jones_unity} ## @end deftypefn function JM = jones_mirror(varargin) retcell = true; if nargin<1 sc = [1,1]; retcell = false; elseif isnumeric(varargin{1}) sc = varargin{1}; else sc = size(varargin{1}); end if prod(sc) > 1 || retcell JM = cell(sc); [JM{:}] = deal(s_mirror()); else JM = s_mirror(); end end % helper function function JM = s_mirror() JM = zeros(2,2); JM(1,1) = -1; JM(2,2) = -1; end %!test %! % test mirror that is its own inverted element %! A = jones_mirror(); %! R = (A-1\A); %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test direct size parameter %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! rsize = size(rand(asize)); %! U = jones_mirror(rsize); %! usize = size(U); %! assert(usize == rsize); %! end %! %!test %! % test indirect size parameter %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! C = cell(asize); %! csize = size(C); %! U = jones_mirror(C); %! usize = size(U); %! assert(usize == csize); %! end %! optics-0.1.4/inst/PaxHeaders.21787/stokes_lphorizontal.m0000644000000000000000000000013213541155434020037 xustar0030 mtime=1568987932.218840227 30 atime=1568987932.218840227 30 ctime=1568987932.234840537 optics-0.1.4/inst/stokes_lphorizontal.m0000644000175000017500000000562413541155434020225 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} stokes_lphorizontal() ## @deftypefnx {Function File} {@var{V} =} stokes_lphorizontal(@var{p}) ## Return the Stokes vector for horizontal linearly polarized light. ## ## @itemize @minus ## @item @var{p} is the intensity of the light, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Stokes vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Stokes_parameters, "Stokes parameters"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{stokes_lpvertical} ## @end deftypefn function V = stokes_lphorizontal(varargin) intensity_defv = 1; if nargin<1 intensity = intensity_defv; else intensity = varargin{1}; end [intensity, was_cell] = __c2n__(intensity, intensity_defv); if (numel(intensity) > 1) || was_cell V = cell(size(intensity)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_lphorizontal(intensity(V_subs{:})); end else V = s_lphorizontal(intensity); end end % helper function function V = s_lphorizontal(intensity) V = [intensity;intensity;0;0]; end %!test %! % test default return value %! V = stokes_lphorizontal(); %! R = V-[1;1;0;0]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! intensity = rand(1, 1); %! V = stokes_lphorizontal(intensity); %! R = V-[1;1;0;0]*intensity; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = stokes_lphorizontal(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/stokes_intensity.m0000644000000000000000000000013213541155434017340 xustar0030 mtime=1568987932.214840148 30 atime=1568987932.214840148 30 ctime=1568987932.234840537 optics-0.1.4/inst/stokes_intensity.m0000644000175000017500000000542513541155434017525 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{P} =} stokes_intensity(@var{V}) ## @deftypefnx {Function File} {@var{[P,Q,...]} =} stokes_intensity(@var{V,W,...}) ## Return intensity of light described by Stokes vectors. ## ## @itemize @minus ## @item @var{V,W,...} define (arrays of) Stokes vectors. ## The function returns their intensity values as numeric arrays ## @var{P,Q,...} of corresponding size. ## @end itemize ## ## @var{V,W,...} can be passed as either numeric vectors or cell arrays ## of Stokes vectors. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Stokes_parameters, "Stokes parameters"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{stokes_isstokes, stokes_degpolarization} ## @end deftypefn function varargout = stokes_intensity(varargin) if nargin==0 print_usage(); return; end % loop over parameters for ni=1:nargin V = varargin{ni}; if iscell(V) intensity = zeros(size(V)); V_subs = cell(1,ndims(V)); for vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),vi); intensity(V_subs{:}) = s_intensity(V{V_subs{:}}); end else intensity = s_intensity(V); end varargout{ni} = intensity; end end % helper function function intensity = s_intensity(V) intensity = V(1); end %!test %! % test size and value of return values %! r1 = rand(2,3,4); %! V1 = stokes_unpolarized(r1); %! r2 = rand(4,3,2); %! V2 = stokes_unpolarized(r2); %! i1 = stokes_intensity(V1); %! i2 = stokes_intensity(V2); %! assert(all(i1==r1) && all(i2==r2)); %! %!test %! % test size and value of return values %! r1 = rand(2,3,4); %! V1 = stokes_unpolarized(r1); %! r2 = rand(1,1); %! V2 = stokes_unpolarized(r2); %! [i1,i2] = stokes_intensity(V1,V2); %! assert(all(i1==r1) && all(i2==r2)); optics-0.1.4/inst/PaxHeaders.21787/jones_linretarder.m0000644000000000000000000000013213541155434017433 xustar0030 mtime=1568987932.202839916 30 atime=1568987932.202839916 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_linretarder.m0000644000175000017500000000771113541155434017620 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{JM} =} jones_linretarder() ## @deftypefnx {Function File} {@var{JM} =} jones_linretarder(@var{p}) ## @deftypefnx {Function File} {@var{JM} =} jones_linretarder(..., @var{mode}) ## Return the Jones matrix for a linear retarder with long axis ## rotation of 0 degrees. ## ## @itemize @minus ## @item @var{p} is the phase delay in radiant units, i.e. @var{p} is ## ranging between 0 and 2*pi(). If not given or set to [] the default ## value 0 is used. ## @item @var{mode} is a string defining the units for the phase ## delay: 'radiant' (default), 'degree' (0..360) or 'wavelength' ## (0..1). ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{JM} of ## Jones matrices of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{Jones_waveplate} ## @end deftypefn function JM = jones_linretarder(varargin) phase_defv = 0; if nargin<1 phase = phase_defv; else phase = varargin{1}; end [phase, was_cell] = __c2n__(phase, phase_defv); if nargin>=2 && ischar(varargin{end}) if strncmpi(varargin{end},'deg',3) phase = phase*pi()/180.0; elseif strncmpi(varargin{end},'wav',3) phase = phase*2*pi(); end end if (numel(phase) > 1) || was_cell JM = cell(size(phase)); JM_subs = cell(1,ndims(JM)); for jmi=1:numel(JM) [JM_subs{:}] = ind2sub(size(JM),jmi); JM{JM_subs{:}} = s_linretarder(phase(JM_subs{:})); end else JM = s_linretarder(phase); end end % helper function function JM = s_linretarder(phase_in_pi_units) JM = zeros(2,2); JM(1,1) = 1; JM(2,2) = exp(-1i*phase_in_pi_units); end %!test %! % test default return value %! A = jones_linretarder(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial application of linear retarder elements %! phase = rand(1, 1); %! A1 = jones_linretarder(phase); %! A2 = jones_linretarder(phase*2); %! R = A1*A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test of serial application of retarder elements %! phase1 = rand(1, 1); %! phase2 = rand(1, 1); %! A1 = jones_linretarder(phase1); %! A2 = jones_linretarder(phase2); %! A12 = jones_linretarder(phase1+phase2); %! R = A1*A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test mode %! phase = rand(1, 1); %! A1 = jones_linretarder(phase); %! A2 = jones_linretarder(phase*180/pi(), 'deg'); %! A3 = jones_linretarder(phase/(2*pi()), 'wav'); %! R1 = A1-A2; %! R2 = A1-A3; %! assert(norm(R1,inf)+norm(R2,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = jones_linretarder(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/private0000644000000000000000000000013213541155434015141 xustar0030 mtime=1568987932.214840148 30 atime=1568987932.234840537 30 ctime=1568987932.234840537 optics-0.1.4/inst/private/0000755000175000017500000000000013541155434015375 5ustar00olafolaf00000000000000optics-0.1.4/inst/private/PaxHeaders.21787/__cellfunc__.m0000644000000000000000000000013213541155434017763 xustar0030 mtime=1568987932.214840148 30 atime=1568987932.214840148 30 ctime=1568987932.234840537 optics-0.1.4/inst/private/__cellfunc__.m0000644000175000017500000000427713541155434020154 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . function A = __cellfunc__(varargin) % TODO: add some documentation for this internal function if nargin == 0 A = []; return; end fh = varargin{1}; if ~isa(fh, 'function_handle') A = fh; return; end % are there additional parameters? if nargin == 1 A = fh(); return; end % collect all parameters in cell array M fhparameter_offset = 1; margin = nargin-fhparameter_offset; returncellarray = false; Msizes = zeros(1,0); M = cell(1,margin); numelM = zeros(1,margin); for mi=1:margin mai = varargin{mi+fhparameter_offset}; if iscell(mai) returncellarray = true; else % convert numeric array to cell(1,1) arrays to ease handling below mai = {mai}; end % adjust dimensions, i.e. fill missing dimensions with 1 sizemai = size(mai); lengthmai = length(sizemai); if lengthmai > size(Msizes,2) Msizes(:,end+1:lengthmai) = 1; end Msizes(end+1,:) = sizemai; % flatten arrays M{mi} = mai(:); numelM(mi) = numel(M{mi}); end % generate output array A Asize = max(Msizes); A = cell(Asize); A_subs = cell(1,ndims(A)); numelA = numel(A); for ai=1:numelA % collect specific parameters for current output cell b = cell(1, margin); for mi=1:margin m = M{mi}; % we are using parameters in a looped manner b{mi} = m{mod(ai-1,numelM(mi))+1}; end [A_subs{:}] = ind2sub(Asize,ai); A{A_subs{:}} = fh(b{:}); end if ~returncellarray A = A{1}; end end optics-0.1.4/inst/private/PaxHeaders.21787/__c2n__.m0000644000000000000000000000013213541155434016652 xustar0030 mtime=1568987932.214840148 30 atime=1568987932.214840148 30 ctime=1568987932.234840537 optics-0.1.4/inst/private/__c2n__.m0000644000175000017500000000241313541155434017031 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . function [array, was_cell] = __c2n__ (array, defaultvalue) % if possible, convert cell array to numeric array, else return an % array of default values of same size was_cell = false; if ~isnumeric (array) if iscell (array) was_cell = true; array2 = cell2mat (array); if (ndims (array2) == ndims (array)) && ... all (size (array2) == size (array)) && ... isnumeric (array2) array = array2; else array = ones (size (array)) * defaultvalue; end else array(:) = defaultvalue; end end end optics-0.1.4/inst/PaxHeaders.21787/zernike_polar.m0000644000000000000000000000013213541155434016566 xustar0030 mtime=1568987932.218840227 30 atime=1568987932.218840227 30 ctime=1568987932.234840537 optics-0.1.4/inst/zernike_polar.m0000644000175000017500000000501113541155434016742 0ustar00olafolaf00000000000000## Copyright (C) 2015 Andreas Weber ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{Z} =} zernike_polar (@var{r}, @var{phi}, @var{n}) ## @deftypefnx {Function File} {@var{Z} =} zernike_polar (@var{r}, @var{phi}, @var{n}, @var{limit_r}) ## Return the polar zernikes up to order n (as noll's index). ## ## If @var{limit_r} is false (default true), the polynoms for r>1 are @emph{not} set to NaN ## because strictly, the polynoms are only defined for 0 <= r <= 1. ## ## The first argument @var{r} is a matrix containing the radial distance, ## the second argument @var{phi} a matrix with the angles. ## ## Size of @var{r} must be equal size of @var{phi}. ## ## This file hasn't a demo yet but have a look on "demo zernike_cartesian" ## @seealso{zernike_cartesian, zernike_name, zernike_noll_to_nm, zernike_R_poly} ## @end deftypefn function Z = zernike_polar (r, phi, n, limit_r = true) if (nargin < 3 || nargin > 4) print_usage (); elseif (! isscalar (n) || n < 1 || n != fix (n)) error ("zernike_polar: n must be a integer >=1"); elseif (any (size (r) != size (phi))) error ("zernike_polar: R and PHI must have the same size") endif Z = zeros (numel (r), n); for k = 1:n [m, n] = zernike_noll_to_mn (k); P = zernike_R_poly (abs (m), n); r_eval = polyval (P, r(:)); if (m < 0) r_eval = r_eval .* sin (abs (m) * phi(:)); else r_eval = r_eval .* cos (m * phi(:)); endif Z(:, k) = r_eval; endfor if (limit_r) Z(r(:) > 1, :) = NaN; endif endfunction %!test %! r = 0.2; %! phi = 1.23; %! n = 4; %! ret = zernike_polar (r, phi, n); %! assert (ret, [1 r*cos(phi) r*sin(phi) 2*r^2-1], 5*eps) %!test %! r = [0.5 0.8]; %! phi = [pi/4 pi/4]; %! n = 4; %! ret = zernike_polar (r, phi, n); %! assert (ret, [1 r(1)*cos(phi(1)) r(1)*sin(phi(1)) 2*r(1)^2-1; 1 r(2)*cos(phi(2)) r(2)*sin(phi(2)) 2*r(2)^2-1], 5*eps) optics-0.1.4/inst/PaxHeaders.21787/jones_lphorizontal.m0000644000000000000000000000013213541155434017645 xustar0030 mtime=1568987932.202839916 30 atime=1568987932.202839916 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_lphorizontal.m0000644000175000017500000000557613541155434020041 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} jones_lphorizontal() ## @deftypefnx {Function File} {@var{V} =} jones_lphorizontal(@var{p}) ## Return the Jones vector for horizontal linearly polarized light. ## ## @itemize @minus ## @item @var{p} is the amplitude of the electric field, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Jones vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{jones_lpvertical} ## @end deftypefn function V = jones_lphorizontal(varargin) amplitude_defv = 1; if nargin<1 amplitude = amplitude_defv; else amplitude = varargin{1}; end [amplitude, was_cell] = __c2n__(amplitude, amplitude_defv); if (numel(amplitude) > 1) || was_cell V = cell(size(amplitude)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_lphorizontal(amplitude(V_subs{:})); end else V = s_lphorizontal(amplitude); end end % helper function function V = s_lphorizontal(amplitude) V = [amplitude; 0]; end %!test %! % test default return value %! V = jones_lphorizontal(); %! R = V-[1;0]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! amplitude = rand(1, 1); %! V = jones_lphorizontal(amplitude); %! R = V-[1;0]*amplitude; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = jones_lphorizontal(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/mueller_circdiattenuator.m0000644000000000000000000000013213541155434021013 xustar0030 mtime=1568987932.206839993 30 atime=1568987932.206839993 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_circdiattenuator.m0000644000175000017500000001426113541155434021176 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_circdiattenuator() ## @deftypefnx {Function File} {@var{M} =} mueller_circdiattenuator(@var{d}) ## @deftypefnx {Function File} {@var{M} =} mueller_circdiattenuator(@var{pl},@var{pr}) ## @deftypefnx {Function File} {@var{M} =} mueller_circdiattenuator(..., @var{mode}) ## Return the Mueller matrix for a linear diattenuator at zero ## rotation. ## ## @itemize @minus ## @item @var{d} is the diattenuation of the element, i.e. ## @code{d=(px-py)/(px+py)}. Reversibly, transmission in y direction ## is @code{(1-d)/(1+d)}, if transmission in x direction is 1. ## @item @var{pl} is the transmittance in x direction. ## @item @var{pr} is the transmittance in y direction. ## @item @var{mode} is a string defining the interpretation of ## transmittance values: 'intensity' (default) or 'amplitude'. ## @end itemize ## ## Arguments @var{d}, @var{pl} or @var{pr} can be passed as a scalar ## or as a matrix or as a cell array. In the two latter cases, a cell ## array @var{M} of Mueller matrices is returned. The size of @var{M} ## is set to the maximum of the parameters' size. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_lindiattenuator, mueller_absorber} ## @end deftypefn function M = mueller_circdiattenuator(varargin) if nargin<1 pr = 1; pl = 1; was_cell = false; elseif nargin==1 pr = varargin{1}; [pr, was_cell] = __c2n__(pr, 0); pl = (1-pr)./(1+pr); pr(:) = 1; else pr = varargin{1}; [pr, was_cellr] = __c2n__(pr, 1); pl = varargin{2}; [pl, was_celll] = __c2n__(pl, 1); was_cell = was_cellr || was_celll; end % check mode s_function = @s_circdiattenuator_int; if nargin>=2 && ischar(varargin{end}) if strncmpi(varargin{end},'amp',3) s_function = @s_circdiattenuator_amp; end end % any matrix in parameters? if (any([numel(pr),numel(pl)] > 1)) || was_cell % adjust dimensions, i.e. fill missing dimensions with 1 spr = size(pr); spl = size(pl); maxdim = max([length(spr),length(spl)]); if length(spr) < maxdim spr = [spr, ones(1,maxdim-length(spr))]; end if length(spl) < maxdim spl = [spl, ones(1,maxdim-length(spl))]; end % generate Mueller matrices maxsize = max([spr;spl]); M = cell(maxsize); M_subs = cell(1,ndims(M)); numelM = numel(M); % flatten parameter arrays pr = pr(:); pl = pl(:); numelpr = numel(pr); numelpl = numel(pl); for mi=1:numelM [M_subs{:}] = ind2sub(size(M),mi); M{M_subs{:}} = s_function(pr(mod(mi-1,numelpr)+1), pl(mod(mi-1,numelpl)+1)); end else M = s_function(pr, pl); end end % helper function function M = s_circdiattenuator_amp(pr_in_amplitude_domain,pl_in_amplitude_domain) M = zeros(4,4); M(1,1) = (pr_in_amplitude_domain^2+pl_in_amplitude_domain^2)/2; M(1,4) = (pr_in_amplitude_domain^2-pl_in_amplitude_domain^2)/2; M(2,2) = pr_in_amplitude_domain*pl_in_amplitude_domain; M(3,3) = M(2,2); M(4,1) = M(1,4); M(4,4) = M(1,1); end % helper function 2 function M = s_circdiattenuator_int(kr_in_intensity_domain,kl_in_intensity_domain) M = zeros(4,4); M(1,1) = (kr_in_intensity_domain+kl_in_intensity_domain)/2; M(1,4) = (kr_in_intensity_domain-kl_in_intensity_domain)/2; M(2,2) = sqrt(kr_in_intensity_domain*kl_in_intensity_domain); M(3,3) = M(2,2); M(4,1) = M(1,4); M(4,4) = M(1,1); end %!test %! % test default return value %! A = mueller_circdiattenuator(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test equality of providing diattenuation or kx and ky %! d = rand(1, 1); %! kr = 1; %! kl = (1-d)./(1+d); %! A1 = mueller_circdiattenuator(d); %! A2 = mueller_circdiattenuator(kr, kl); %! R = A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial application of circular diattenuators %! kr = rand(1, 1); %! kl = rand(1, 1); %! A1 = mueller_circdiattenuator(kr,kl); %! A2 = mueller_circdiattenuator(kr*kr,kl*kl); %! R = A1*A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test of serial application of retarder elements %! kr1 = rand(1, 1); %! kr2 = rand(1, 1); %! kl1 = rand(1, 1); %! kl2 = rand(1, 1); %! A1 = mueller_circdiattenuator(kr1,kl1); %! A2 = mueller_circdiattenuator(kr2,kl2); %! A12 = mueller_circdiattenuator(kr1*kr2,kl1*kl2); %! R = A1*A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test mode %! kr = rand(1, 1); %! kl = rand(1, 1); %! A1 = mueller_circdiattenuator(kr,kl); %! A2 = mueller_circdiattenuator(kr,kl,'int'); %! A3 = mueller_circdiattenuator(sqrt(kr),sqrt(kl),'amp'); %! R1 = A1-A2; %! R2 = A1-A3; %! assert(norm(R1,inf)+norm(R2,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = mueller_circdiattenuator(R); %! csize = size(C); %! assert(rsize == csize); %! end %! %!test %! % another test correct size of return values %! kr = rand(3,4,5); %! kl = rand(5,4,3); %! C = mueller_circdiattenuator(kr,kl); %! csize = size(C); %! assert(csize == [5,4,5]); optics-0.1.4/inst/PaxHeaders.21787/mueller_checkmueller.m0000644000000000000000000000013213541155434020112 xustar0030 mtime=1568987932.206839993 30 atime=1568987932.206839993 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_checkmueller.m0000644000175000017500000000710013541155434020267 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{t} =} mueller_checkmueller(@var{M}) ## @deftypefnx {Function File} {@var{[t,u,...]} =} mueller_checkmueller(@var{M,N,...}) ## Check physical validity of Mueller matrix or matrices. ## ## @itemize @minus ## @item @var{M,N,...} define potential (arrays of) Mueller matrices. ## After checking the parameters for validity, the function returns ## boolean arrays @var{t,u,...} of corresponding size. ## @end itemize ## ## @var{M,N,...} can be passed as either numeric matrices or cell arrays ## of potential Mueller matrices. ## ## Note that this function checks the physical integrity of ## the given matrices; to check the computational form only, ## use mueller_ismueller() instead. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_ismueller} ## @end deftypefn function varargout = mueller_checkmueller(varargin) if nargin==0 print_usage(); return; end % loop over parameters for vi=1:nargin M = varargin{vi}; if iscell(M) checkmueller = false(size(M)); M_subs = cell(1,ndims(M)); for mi=1:numel(M) [M_subs{:}] = ind2sub(size(M),mi); checkmueller(M_subs{:}) = s_checkmueller(M{M_subs{:}}); end else checkmueller = s_checkmueller(M); end varargout{vi} = checkmueller; end end % helper function function checkMueller = s_checkmueller(M) if ~isnumeric(M) checkMueller = false; elseif ~all(size(M)==[4,4]) checkMueller = false; elseif det(M) ~= 1 checkMueller = false; else checkMueller = true; end end %!test %! % test type check %! A1 = mueller_unity(); %! A2 = char(A1); %! t1 = mueller_checkmueller(A1); %! t2 = mueller_checkmueller(A2); %! assert(t1 && ~t2); %! %!test %! % test size check %! A1 = mueller_unity(); %! A2 = A1; %! A2(5,5) = 1; %! t1 = mueller_checkmueller(A1); %! t2 = mueller_checkmueller(A2); %! assert(t1 && ~t2); %! %!test %! % test size of return value %! A1 = mueller_mirror([2,3,4]); %! A1{2,2,2} = 0; %! A2 = mueller_mirror([4,3,2]); %! A2{1,1,1} = 0; %! t1 = mueller_checkmueller(A1); %! t2 = mueller_checkmueller(A2); %! assert((size(A1)==size(t1)) && (size(A2)==size(t2))); %! %!test %! % test indivial elements of return value %! A1 = mueller_mirror([2,3,4]); %! A1{2,2,2} = ones(4,4)*0.99; %! A2 = mueller_mirror([4,3,2]); %! A2{1,1,1} = ones(4,4)*1.01; %! t1 = mueller_checkmueller(A1); %! t2 = mueller_checkmueller(A2); %! assert(t1(1,1,1) && ~t1(2,2,2) && ~t2(1,1,1) && t2(2,2,2)); optics-0.1.4/inst/PaxHeaders.21787/zernike_cartesian.m0000644000000000000000000000013213541155434017422 xustar0030 mtime=1568987932.218840227 30 atime=1568987932.218840227 30 ctime=1568987932.234840537 optics-0.1.4/inst/zernike_cartesian.m0000644000175000017500000000576513541155434017616 0ustar00olafolaf00000000000000## Copyright (C) 2015 Andreas Weber ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, see . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{Z} =} zernike_cartesian (@var{x}, @var{y}, @var{n}) ## @deftypefnx {Function File} {@var{Z} =} zernike_cartesian (@var{x}, @var{y}, @var{n}, @var{limit_r}) ## Return the cartesian zernikes up to order n (as noll's index). ## ## If @var{limit_r} is false (default true), the polynoms for r>1 are @emph{not} set to NaN ## because strictly, the polynoms are only defined for 0 <= r <= 1. ## ## Size of @var{x} must be equal size of @var{y}. ## ## Demo: type "demo zernike_cartesian" ## ## @seealso{zernike_name, zernike_noll_to_nm, zernike_polar, zernike_R_poly} ## @end deftypefn ## TODO: The cartesian zernikes can be calculated quicker for example using a method ## described in "Hedser van Brug: Efficient Cartesian representation of Zernike polynomials." ## Until then the cartesians get mapped to the polar ones. function Z = zernike_cartesian (x, y, n, limit_r = true) if (nargin < 3 || nargin > 4) print_usage (); elseif (! isscalar (n) || n < 1 || n != fix (n)) error ("zernike_cartesian: N must be a integer >=1"); elseif (ndims (x) != ndims (y) || any (size (x) != size (y))) error ("zernike_cartesian: X and Y must have the same size") endif r = sqrt (x.*x + y.*y); phi = atan2 (y, x); Z = zernike_polar (r, phi, n, limit_r); endfunction %!demo %! t = linspace (-1, 1, 80); %! [x, y] = meshgrid (t, t); %! max_order = 16; %! Z = zernike_cartesian (x, y, max_order); %! for k = 1:max_order %! subplot (4, 4, k) %! factors = zeros (max_order, 1); %! factors(k) = 1; %! z = reshape (Z*factors, size (x)); %! imagesc (z) %! axis ("off", "equal") %! zname = strrep (zernike_name (k), " ", "\n"); %! title (zname) %! endfor %!demo %! n=30; %! [x,y,z] = sombrero (n); %! z += 0.05 * peaks (x./4, y./4); %! z += 0.02 * x; %! figure %! surf (x, y, z) %! title ("Original sombrero + peaks + tilt"); %! %! ## approximate sombrero+peaks %! d = 10; %! x /= d; %! y /= d; %! max_order = 50; %! Z = zernike_cartesian (x, y, max_order, false); %! f = Z\z(:); %! ## create approximated plot %! z_approx = reshape (Z * f, n, n); %! figure %! surf (10 * x, 10 * y, z_approx) %! title ("approximated"); %!assert (zernike_cartesian (0, 0, 1), 1) %!error (zernike_cartesian (0, 0, 0)) %!error (zernike_cartesian (0, 0, pi)) %!error (zernike_cartesian ()) optics-0.1.4/inst/PaxHeaders.21787/jones_intensity.m0000644000000000000000000000013213541155434017146 xustar0030 mtime=1568987932.202839916 30 atime=1568987932.202839916 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_intensity.m0000644000175000017500000000547013541155434017333 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{P} =} jones_intensity(@var{V}) ## @deftypefnx {Function File} {@var{[P,Q,...]} =} jones_intensity(@var{V,W,...}) ## Return intensity of light described by Jones vectors. ## ## @itemize @minus ## @item @var{V,W,...} define (arrays of) Jones vectors. ## The function returns their intensity values as numeric arrays ## @var{P,Q,...} of corresponding size. ## @end itemize ## ## @var{V,W,...} can be passed as either numeric vectors or cell arrays ## of Jones vectors. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{} ## @end deftypefn function varargout = jones_intensity(varargin) if nargin==0 print_usage(); return; end % loop over parameters for ni=1:nargin V = varargin{ni}; if iscell(V) intensity = zeros(size(V)); V_subs = cell(1,ndims(V)); for vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),vi); intensity(V_subs{:}) = s_intensity(V{V_subs{:}}); end else intensity = s_intensity(V); end varargout{ni} = intensity; end end % helper function function intensity = s_intensity(V) intensity = V'*V; end %!test %! % test size and value of return values %! r1 = rand(2,3,4); %! V1 = jones_lphorizontal(sqrt(r1)); %! r2 = rand(4,3,2); %! V2 = jones_lpvertical(sqrt(r2)); %! i1 = jones_intensity(V1); %! i2 = jones_intensity(V2); %! d1 = i1-r1; %! d2 = i2-r2; %! assert(max(d1(:))+max(d2(:)), 0, 1e-9); %! %!test %! % test size and value of return values %! r1 = rand(2,3,4); %! V1 = jones_lphorizontal(sqrt(r1)); %! r2 = rand(1,1); %! V2 = jones_lpvertical(sqrt(r2)); %! [i1,i2] = jones_intensity(V1,V2); %! d1 = i1-r1; %! d2 = i2-r2; %! assert(max(d1(:))+max(d2(:)), 0, 1e-9); optics-0.1.4/inst/PaxHeaders.21787/jones_cpright.m0000644000000000000000000000013213541155434016560 xustar0030 mtime=1568987932.202839916 30 atime=1568987932.202839916 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_cpright.m0000644000175000017500000000552013541155434016741 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} jones_cpright() ## @deftypefnx {Function File} {@var{V} =} jones_cpright(@var{p}) ## Return the Jones vector for right-turn circular polarized light. ## ## @itemize @minus ## @item @var{p} is the amplitude of the electric field, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Jones vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{jones_cpleft} ## @end deftypefn function V = jones_cpright(varargin) amplitude_defv = 1; if nargin<1 amplitude = amplitude_defv; else amplitude = varargin{1}; end [amplitude, was_cell] = __c2n__(amplitude, amplitude_defv); if (numel(amplitude) > 1) || was_cell V = cell(size(amplitude)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_cpright(amplitude(V_subs{:})); end else V = s_cpright(amplitude); end end % helper function function V = s_cpright(amplitude) V = amplitude*[1; 1i]; end %!test %! % test default return value %! V = jones_cpright(); %! R = V-[1;1i]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! amplitude = rand(1, 1); %! V = jones_cpright(amplitude); %! R = V-[1;1i]*amplitude; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = jones_cpright(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/mueller_unity.m0000644000000000000000000000013213541155434016617 xustar0030 mtime=1568987932.214840148 30 atime=1568987932.214840148 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_unity.m0000644000175000017500000000523013541155434016776 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_unity() ## @deftypefnx {Function File} {@var{A} =} mueller_unity(@var{[m, n, ...]}) ## @deftypefnx {Function File} {@var{A} =} mueller_unity(@var{C}) ## Return unity Mueller matrices, representing a non-polarizing ## optical element. ## ## @itemize @minus ## @item @var{[m, n, ...]} defines the size of the cell array @var{A} ## and therefore the number of unity matrices returned. ## @item @var{C} is a cell array defining the size of the returned cell array ## @var{A}, @code{size(A)==size(C)}. The content of @var{C} is of not ## evaluated in this case. ## @end itemize ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_mirror} ## @end deftypefn function M = mueller_unity(varargin) retcell = true; if nargin<1 sc = [1,1]; retcell = false; elseif isnumeric(varargin{1}) sc = varargin{1}; else sc = size(varargin{1}); end if prod(sc) > 1 || retcell M = cell(sc); [M{:}] = deal(s_unity()); else M = s_unity(); end end % helper function function M = s_unity() M = eye(4); end %!test %! A = mueller_unity(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! C = cell(asize); %! csize = size(C); %! U = mueller_unity(C); %! usize = size(U); %! assert(usize == csize); %! end %! %!test %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! rsize = size(rand(asize)); %! U = mueller_unity(rsize); %! usize = size(U); %! assert(usize == rsize); %! end optics-0.1.4/inst/PaxHeaders.21787/stokes_lpminus45.m0000644000000000000000000000013213541155434017152 xustar0030 mtime=1568987932.218840227 30 atime=1568987932.218840227 30 ctime=1568987932.234840537 optics-0.1.4/inst/stokes_lpminus45.m0000644000175000017500000000560313541155434017335 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} stokes_lpminus45() ## @deftypefnx {Function File} {@var{V} =} stokes_lpminus45(@var{p}) ## Return the Stokes vector for light with linear polarization at -45 degrees. ## ## @itemize @minus ## @item @var{p} is the intensity of the light, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Stokes vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Stokes_parameters, "Stokes parameters"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{stokes_lpplus45} ## @end deftypefn function V = stokes_lpminus45(varargin) intensity_defv = 1; if nargin<1 intensity = intensity_defv; else intensity = varargin{1}; end [intensity, was_cell] = __c2n__(intensity, intensity_defv); if (numel(intensity) > 1) || was_cell V = cell(size(intensity)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_lpminus45(intensity(V_subs{:})); end else V = s_lpminus45(intensity); end end % helper function function V = s_lpminus45(intensity) V = [intensity;0;-intensity;0]; end %!test %! % test default return value %! V = stokes_lpminus45(); %! R = V-[1;0;-1;0]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! intensity = rand(1, 1); %! V = stokes_lpminus45(intensity); %! R = V-[1;0;-1;0]*intensity; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = stokes_lpminus45(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/stokes_lpvertical.m0000644000000000000000000000013213541155434017457 xustar0030 mtime=1568987932.218840227 30 atime=1568987932.218840227 30 ctime=1568987932.234840537 optics-0.1.4/inst/stokes_lpvertical.m0000644000175000017500000000560413541155434017643 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} stokes_lpvertical() ## @deftypefnx {Function File} {@var{V} =} stokes_lpvertical(@var{p}) ## Return the Stokes vector for vertical linearly polarized light. ## ## @itemize @minus ## @item @var{p} is the intensity of the light, ## if not given or set to [] the default value 1 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{V} of ## Stokes vectors of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Stokes_parameters, "Stokes parameters"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{stokes_lphorizontal} ## @end deftypefn function V = stokes_lpvertical(varargin) intensity_defv = 1; if nargin<1 intensity = intensity_defv; else intensity = varargin{1}; end [intensity, was_cell] = __c2n__(intensity, intensity_defv); if (numel(intensity) > 1) || was_cell V = cell(size(intensity)); V_subs = cell(1,ndims(V)); for Vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),Vi); V{V_subs{:}} = s_lpvertical(intensity(V_subs{:})); end else V = s_lpvertical(intensity); end end % helper function function V = s_lpvertical(intensity) V = [intensity;-intensity;0;0]; end %!test %! % test default return value %! V = stokes_lpvertical(); %! R = V-[1;-1;0;0]; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test return value %! intensity = rand(1, 1); %! V = stokes_lpvertical(intensity); %! R = V-[1;-1;0;0]*intensity; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test correct size of return values %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = stokes_lpvertical(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/jones_rotate.m0000644000000000000000000000013213541155434016416 xustar0030 mtime=1568987932.206839993 30 atime=1568987932.206839993 30 ctime=1568987932.234840537 optics-0.1.4/inst/jones_rotate.m0000644000175000017500000001324013541155434016575 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{JM} =} jones_rotate() ## @deftypefnx {Function File} {@var{JM} =} jones_rotate(@var{M}, @var{p}) ## @deftypefnx {Function File} {@var{JM} =} jones_rotate(..., @var{mode}) ## Return the Jones matrix for rotated Jones elements. ## ## @itemize @minus ## @item @var{M} is the Jones matrix for the unrotated elements. ## Default value is the Jones unity matrix. ## @item @var{p} is the rotation angle, default value is 0. ## @item @var{mode} is a string defining the interpretation of the ## angle value: 'radiants' (default) or 'degree'. ## @end itemize ## ## Argument @var{M} can be passed as numeric matrix or as a cell ## array. Argument @var{p} can be passed as a numeric scalar or as a ## cell array. In the case of at least one cell array provided, ## a cell array @var{M} of Jones matrices is returned. The size of ## @var{M} in each dimension is set to the maximum of the size of ## the passed cell arrays. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Jones_calculus, "Jones calculus"}, ## last retrieved on Jan 13, 2014. ## @end enumerate ## ## @seealso{jones_rotator} ## @end deftypefn function JM = jones_rotate(varargin) angle_defv = 0; if nargin<1 JM = jones_unity(); return; elseif nargin<2 JM = varargin{1}; return; else C = varargin{1}; angle = varargin{2}; end [angle, angle_was_cell] = __c2n__(angle, angle_defv); if nargin>=3 && ischar(varargin{end}) if strncmpi(varargin{end},'deg',3) angle = angle*pi()/180.0; end end if iscell(C) || (numel(angle) > 1) || angle_was_cell if ~iscell(C) C = {C}; end % adjust dimensions, i.e. fill missing dimensions with 1 sizeC = size(C); sizeangle = size(angle); maxdim = max(length(sizeC),length(sizeangle)); if length(sizeC) < maxdim sizeC = [sizeC, ones(1,maxdim-length(sizeC))]; end if length(sizeangle) < maxdim sizeangle = [sizeangle, ones(1,maxdim-length(sizeangle))]; end % generate Jones matrices maxsize = max([sizeC;sizeangle]); JM = cell(maxsize); JM_subs = cell(1,ndims(JM)); numelJM = numel(JM); % flatten C and angle arrays C = C(:); angle = angle(:); numelC = numel(C); numelangle = numel(angle); for jmi=1:numelJM [JM_subs{:}] = ind2sub(size(JM),jmi); JM{JM_subs{:}} = s_rotate(C{mod(jmi-1,numelC)+1}, angle(mod(jmi-1,numelangle)+1)); end else JM = s_rotate(C, angle(1)); end end % helper function function JM = s_rotate(JM, angle_in_radiants) JM = s_rotator(-angle_in_radiants)*JM*s_rotator(angle_in_radiants); end % helper function function JM = s_rotator(angle_in_radiants) JM = zeros(2,2); JM(1,1) = cos(angle_in_radiants); JM(1,2) = sin(angle_in_radiants); JM(2,1) = -sin(angle_in_radiants); JM(2,2) = cos(angle_in_radiants); end %!test %! % default return value: unity matrix %! A = jones_rotate(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % rotation by 0 should do nothing %! delay = rand(1,1); %! JM = jones_linretarder(delay); %! A = jones_rotate(JM, 0); %! R = JM-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % undo rotation by 2nd opposite rotation %! delay = rand(1,1); %! angle = rand(1, 1); %! JM = jones_linretarder(delay); %! A1 = jones_rotate(JM, angle); %! A2 = jones_rotate(A1, -angle); %! R = A2-JM; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial application of rotation %! delay = rand(1,1); %! angle1 = rand(1, 1); %! angle2 = rand(1, 1); %! JM = jones_linretarder(delay); %! A1 = jones_rotate(JM, angle1); %! A2 = jones_rotate(A1, angle2); %! A12 = jones_rotate(JM, angle1+angle2); %! R = A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % testing MODE parameter %! angle = rand(1, 1); %! A1 = jones_rotate(jones_waveplate(0.5), angle, 'rad'); %! A2 = jones_rotate(jones_waveplate(0.5), angle*180/pi(), 'deg'); %! R = A2-A1; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % size of return value determined by 1st argument %! angle = rand(1,1); %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! rsize = size(rand(asize)); %! C = jones_rotate(jones_unity(rsize), angle); %! csize = size(C); %! assert(rsize == csize); %! end %! %!test %! % size if return value determined by 2nd argument %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = jones_rotate(jones_unity(), R); %! csize = size(C); %! assert(rsize == csize); %! end %! %!test %! % size if return value determined by both argument %! JM = jones_unity([4,3,2]); %! angle = rand(2,3,4); %! C = jones_rotate(JM, angle); %! csize = size(C); %! assert(csize == [4,3,4]); %! optics-0.1.4/inst/PaxHeaders.21787/mueller_depolarizer.m0000644000000000000000000000013213541155434017767 xustar0030 mtime=1568987932.210840071 30 atime=1568987932.210840071 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_depolarizer.m0000644000175000017500000000662013541155434020152 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_depolarizer() ## @deftypefnx {Function File} {@var{M} =} mueller_depolarizer(@var{p}) ## Return Mueller matrices for a (partial) depolarizer. ## ## @itemize @minus ## @item @var{p} is the depolarization, ranging from 0 to 1, ## if not given or set to [] the default value 0 is used. ## @end itemize ## ## Argument @var{p} can be passed as a scalar or as a matrix or as a ## cell array. In the two latter cases, a cell array @var{M} of ## Mueller matrices of the same size is returned. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{mueller_linpolarizer} ## @end deftypefn function M = mueller_depolarizer(varargin) depolarization_defv = 0; if nargin<1 depolarization = depolarization_defv; else depolarization = varargin{1}; end [depolarization, was_cell] = __c2n__(depolarization, depolarization_defv); if (numel(depolarization) > 1) || was_cell M = cell(size(depolarization)); M_subs = cell(1,ndims(M)); for mi=1:numel(M) [M_subs{:}] = ind2sub(size(M),mi); M{M_subs{:}} = s_depolarizer(depolarization(M_subs{:})); end else M = s_depolarizer(depolarization); end end % helper function function M = s_depolarizer(depolarization) M = zeros(4,4); M(1,1) = 1; M(2,2) = depolarization; M(3,3) = depolarization; M(4,4) = depolarization; end %!test %! % test default return value %! A = mueller_depolarizer(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test serial application of matrix %! depolarization = rand(1, 1); %! A1 = mueller_depolarizer(depolarization); %! A2 = mueller_depolarizer(depolarization^2); %! R = A1*A1-A2; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test of serial application %! depolarization1 = rand(1, 1); %! depolarization2 = rand(1, 1); %! A1 = mueller_depolarizer(depolarization1); %! A2 = mueller_depolarizer(depolarization2); %! A12 = mueller_depolarizer(depolarization1*depolarization2); %! R = A1*A2-A12; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test size of return value %! for dim = 1:5 %! asize = randi([1 4], 1, dim); %! R = rand(asize); %! if numel(R) == 1 %! R = {R}; %! end %! rsize = size(R); %! C = mueller_depolarizer(R); %! csize = size(C); %! assert(rsize == csize); %! end optics-0.1.4/inst/PaxHeaders.21787/mueller_homogeneous_elliptic_retarder.m0000644000000000000000000000013213541155434023554 xustar0030 mtime=1568987932.210840071 30 atime=1568987932.210840071 30 ctime=1568987932.234840537 optics-0.1.4/inst/mueller_homogeneous_elliptic_retarder.m0000644000175000017500000002012413541155434023732 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{M} =} mueller_homogeneous_elliptic_retarder() ## @deftypefnx {Function File} {@var{M} =} mueller_homogeneous_elliptic_retarder(@var{t0}, @var{delay}, @var{azimuth}, @var{ellipticity}) ## @deftypefnx {Function File} {@var{M} =} mueller_homogeneous_elliptic_retarder(..., @var{delaymode}) ## @deftypefnx {Function File} {@var{M} =} mueller_homogeneous_elliptic_retarder(..., @var{delaymode}, @var{azimuthmode}) ## Return the Mueller matrix for a homogeneous elliptic retarder (see ## references). ## ## @itemize @minus ## @item @var{t0} is the total transmission (default: 1). ## @item @var{delay} is the retardation delay (default: 0). ## @item @var{azimuth} and @var{ellipticity} (default: 0) describe the ## two orthogonal polarization eigenstates. ## @item @var{delaymode} is a string defining the interpretation of ## the retardation delay: 'radiants' (default) or 'degree' or ## 'wavelength'. ## @item @var{azimuthmode} is a string defining the interpretation of ## the azimuth angle: 'radiants' (default) or 'degree'. ## @end itemize ## ## Arguments @var{t0}, @var{delay}, @var{azimuth}, or ## @var{ellipticity} can be passed as a scalar ## or as a matrix or as a cell array. In the two latter cases, a cell ## array @var{M} of Mueller matrices is returned. The size of @var{M} ## is given by @code{max(size(t0),size(delay),size(azimuth),size(ellipticity))} ## and elements of smaller matrices of @var{t0}, @var{delay}, ## @var{azimuth} or @var{ellipticity} are used in a loop-over manner. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Mueller_calculus, "Mueller calculus"}, ## last retrieved on Dec 17, 2013. ## @item Boulvert et al., "Decomposition algorithm of an experimental ## Mueller matrix", Opt.Comm. 282(2009):692-704 ## @end enumerate ## ## @seealso{mueller_homogeneous_elliptic_diattenuator} ## @end deftypefn function M = mueller_homogeneous_elliptic_retarder(varargin) % TODO: check ref[2] in [3] for decomposition in homogeneous elliptic % retarder und retarder switch(nargin) case 0 t0 = 1; delay = 0; azimuth = 0; ellipticity = 0; was_cell = false; case 1 [t0, was_cell] = __c2n__(varargin{1}, 1); delay = 0; azimuth = 0; ellipticity = 0; case 2 [t0, was_cell_t0] = __c2n__(varargin{1}, 1); [delay, was_cell_delay] = __c2n__(varargin{2}, 0); azimuth = 0; ellipticity = 0; was_cell = was_cell_t0 || was_cell_delay; case 3 [t0, was_cell_t0] = __c2n__(varargin{1}, 1); [delay, was_cell_delay] = __c2n__(varargin{2}, 0); % check special case of homogeneous_elliptic_retarder(t0,d,'degree') if ischar(varargin{3}) azimuth = 0; was_cell_azimuth = false; else [azimuth, was_cell_azimuth] = __c2n__(varargin{3}, 0); end ellipticity = 0; was_cell = was_cell_t0 || was_cell_delay || was_cell_azimuth; otherwise [t0, was_cell_t0] = __c2n__(varargin{1}, 1); [delay, was_cell_delay] = __c2n__(varargin{2}, 0); [azimuth, was_cell_azimuth] = __c2n__(varargin{3}, 0); % check special case of homogeneous_elliptic_retarder(t0,d,a,'degree') if ischar(varargin{4}) ellipticity = 0; was_cell_ellipticity = false; else [ellipticity, was_cell_ellipticity] = __c2n__(varargin{4}, 0); end was_cell = was_cell_t0 || was_cell_delay || ... was_cell_azimuth || was_cell_ellipticity; end % convert delay and azimuth angle if necessary delaycvt = []; azimuthcvt = []; if nargin>=3 if ischar(varargin{end}) if ischar(varargin{end-1}) delaycvt = nargin-1; azimuthcvt = nargin; else delaycvt = nargin; end end end if ~isempty(delaycvt) if strncmpi(varargin{delaycvt},'deg',3) delay = delay*pi()/180.0; elseif strncmpi(varargin{delaycvt},'wav',3) delay = delay*2*pi(); end end if ~isempty(azimuthcvt) if strncmpi(varargin{azimuthcvt},'deg',3) azimuth = azimuth*pi()/180.0; end end % any matrix in parameters? if (any([numel(t0),numel(delay),numel(azimuth),numel(ellipticity)] > 1)) || ... was_cell % adjust dimensions, i.e. fill missing dimensions with 1 st0 = size(t0); sdelay = size(delay); sazimuth = size(azimuth); sellipticity = size(ellipticity); maxdim = max([length(st0),length(sdelay),length(sazimuth),length(sellipticity)]); if length(st0) < maxdim st0 = [st0, ones(1,maxdim-length(st0))]; end if length(sdelay) < maxdim sdelay = [sdelay, ones(1,maxdim-length(sdelay))]; end if length(sazimuth) < maxdim sazimuth = [sazimuth, ones(1,maxdim-length(sazimuth))]; end if length(sellipticity) < maxdim sellipticity = [sellipticity, ones(1,maxdim-length(sellipticity))]; end % generate Mueller matrices maxsize = max([st0;sdelay;sazimuth;sellipticity]); M = cell(maxsize); M_subs = cell(1,ndims(M)); % flatten parameter arrays t0 = t0(:); delay = delay(:); azimuth = azimuth(:); ellipticity = ellipticity(:); numelt0 = numel(t0); numeldelay = numel(delay); numelazimuth = numel(azimuth); numelellipticity = numel(ellipticity); for mi=1:numel(M) [M_subs{:}] = ind2sub(size(M),mi); M{M_subs{:}} = s_homogenenous_elliptic_retarder(t0(mod(mi-1,numelt0)+1),... delay(mod(mi-1,numeldelay)+1),... azimuth(mod(mi-1,numelazimuth)+1), ... ellipticity(mod(mi-1,numelellipticity)+1)); end else % generate Mueller matrix M = s_homogenenous_elliptic_retarder(t0,delay,azimuth,ellipticity); end end % helper function function M = s_homogenenous_elliptic_retarder(t0,delay,azimuth,ellipticity) M = zeros(4,4); d = cos(2*ellipticity)*cos(2*azimuth)*sin(delay/2); e = cos(2*ellipticity)*sin(2*azimuth)*sin(delay/2); f = sin(2*ellipticity)*sin(delay/2); g = cos(delay/2); M(1,1) = 1; M(2,2) = d^2-e^2-f^2+g^2; M(2,3) = 2*(d*e+f*g); M(2,4) = 2*(d*f-e*g); M(3,2) = M(2,3); M(3,3) = -d^2+e^2-f^2+g^2; M(3,4) = 2*(e*f-d*g); M(4,2) = M(2,4); M(4,3) = M(3,4); M(4,4) = -d^2-e^2+f^2+g^2; M = M*t0; end %!test %! % test default return value %! A = mueller_homogeneous_elliptic_retarder(); %! R = A*A-A; %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % test modes %! t0 = rand(1,1); %! delay = rand(1,1); %! azimuth = rand(1,1); %! ellipticity = rand(1,1); %! A1 = mueller_homogeneous_elliptic_retarder(t0,delay,azimuth,ellipticity); %! A2 = mueller_homogeneous_elliptic_retarder(t0,delay*180/pi(),azimuth,ellipticity,'deg'); %! A3 = mueller_homogeneous_elliptic_retarder(t0,delay/(2*pi()),azimuth,ellipticity,'wav'); %! A4 = mueller_homogeneous_elliptic_retarder(t0,delay,azimuth*180/pi(),ellipticity,'rad','deg'); %! R = (A2-A1)+(A3-A1)+(A4-A1); %! assert(norm(R,inf), 0, 1e-9); %! %!test %! % another test correct size of return values %! t0 = rand(3,4,5); %! delay = rand(4,5,6); %! azimuth = rand(5,4,3); %! ellipticity = rand(6,5,4); %! C = mueller_homogeneous_elliptic_retarder(t0,delay,azimuth,ellipticity); %! csize = size(C); %! assert(csize == [6,5,6]); optics-0.1.4/inst/PaxHeaders.21787/stokes_degpolarization.m0000644000000000000000000000013213541155434020505 xustar0030 mtime=1568987932.214840148 30 atime=1568987932.214840148 30 ctime=1568987932.234840537 optics-0.1.4/inst/stokes_degpolarization.m0000644000175000017500000000574513541155434020677 0ustar00olafolaf00000000000000## Copyright (C) 2013 Martin Vogel ## ## This program is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by the ## Free Software Foundation; either version 3 of the License, or (at your ## option) any later version. ## ## This program is distributed in the hope that it will be useful, but WITHOUT ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{P} =} stokes_degpolarization(@var{V}) ## @deftypefnx {Function File} {@var{[P,Q,...]} =} stokes_degpolarization(@var{V,W,...}) ## Return degree of polarization of light described by Stokes vectors. ## ## @itemize @minus ## @item @var{V,W,...} define (arrays of) Stokes vectors. ## The function returns their degrees of polarization as numeric arrays ## @var{P,Q,...} of corresponding size. ## @end itemize ## ## @var{V,W,...} can be passed as either numeric vectors or cell arrays ## of potential Stokes vectors. ## ## References: ## ## @enumerate ## @item E. Collett, Field Guide to Polarization, ## SPIE Field Guides vol. FG05, SPIE (2005). ISBN 0-8194-5868-6. ## @item R. A. Chipman, "Polarimetry," chapter 22 in Handbook of Optics II, ## 2nd Ed, M. Bass, editor in chief (McGraw-Hill, New York, 1995) ## @item @url{http://en.wikipedia.org/wiki/Stokes_parameters, "Stokes parameters"}, ## last retrieved on Dec 17, 2013. ## @end enumerate ## ## @seealso{stokes_isstokes, stokes_intensity} ## @end deftypefn function varargout = stokes_degpolarization(varargin) if nargin==0 print_usage(); return; end % loop over parameters for ni=1:nargin V = varargin{ni}; if iscell(V) degpolarization = zeros(size(V)); V_subs = cell(1,ndims(V)); for vi=1:numel(V) [V_subs{:}] = ind2sub(size(V),vi); degpolarization(V_subs{:}) = s_degpolarization(V{V_subs{:}}); end else degpolarization = s_degpolarization(V); end varargout{ni} = degpolarization; end end % helper function function degpolarization = s_degpolarization(V) S13 = V(2:4); degpolarization = sqrt(S13'*S13)/V(1); end % t = stokes.degpolarization(stokes.unpolarized()+stokes.cpleft()) % t = 0.5 %!test %! % test size of return values %! r1 = rand(2,3,4); %! V1 = stokes_unpolarized(r1); %! r2 = rand(4,3,2); %! V2 = stokes_unpolarized(r2); %! [d1,d2] = stokes_degpolarization(V1,V2); %! assert((size(d1)==size(r1)) && size(size(d2)==size(r2))); %! %!test %! % test return values %! r1 = rand(1,1); %! V1 = stokes_cpleft(r1)+stokes_unpolarized(1-r1); %! r2 = rand(1,1); %! V2 = stokes_unpolarized(r2); %! [d1,d2] = stokes_degpolarization(V1,V2); %! assert((d1==r1) && (d2==0)); optics-0.1.4/PaxHeaders.21787/DESCRIPTION0000644000000000000000000000013213541155434014275 xustar0030 mtime=1568987932.198839838 30 atime=1568987932.198839838 30 ctime=1568987932.234840537 optics-0.1.4/DESCRIPTION0000644000175000017500000000062713541155434014461 0ustar00olafolaf00000000000000Name: optics Version: 0.1.4 Date: 2019-09-12 Author: Martin Vogel , Ramom Flores , Andreas Weber Maintainer: Andreas Weber Title: Optics Description: Functions covering various aspects of optics Categories: physics Problems: none Url: http://octave.sf.net Depends: octave (>= 3.2) License: GPLv3+ optics-0.1.4/PaxHeaders.21787/COPYING0000644000000000000000000000013213541155434013622 xustar0030 mtime=1568987932.198839838 30 atime=1568987932.198839838 30 ctime=1568987932.234840537 optics-0.1.4/COPYING0000644000175000017500000010451413541155434014006 0ustar00olafolaf00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . optics-0.1.4/PaxHeaders.21787/NEWS0000644000000000000000000000013213541155434013266 xustar0030 mtime=1568987932.198839838 30 atime=1568987932.198839838 30 ctime=1568987932.234840537 optics-0.1.4/NEWS0000644000175000017500000000226713541155434013454 0ustar00olafolaf00000000000000 Summary of important user-visible changes for optics 0.1.4 (2019/09/12): ------------------------------------------------------------------------- ** Two new zernike functions zernike_osa_ansi_to_mn zernikes_and_derivatives_cartesian_OSA Summary of important user-visible changes for optics 0.1.3 (2015/05/06): ------------------------------------------------------------------------- ** A group of functions to deal with Zernike polynomials have been implemented. These are a sequence of polynomials orthogonal on the unit disk. They are used, for example, to characterize distortions in optical systems. zernike_cartesian zernike_name zernike_noll_to_mn zernike_polar zernike_R_poly ** Initial abcd matrix raytracing. https://en.wikipedia.org/wiki/Ray_transfer_matrix_analysis @abcd/abcd @abcd/trace Summary of important user-visible changes for optics 0.1.1 (2014/12/02): ------------------------------------------------------------------------- ** Fix permissions of package Summary of important changes for optics 0.1.0 (2014/06/09): ------------------------------------------------------------------------ ** Initial release. optics-0.1.4/PaxHeaders.21787/doc0000644000000000000000000000013213541155434013257 xustar0030 mtime=1568987932.198839838 30 atime=1568987932.234840537 30 ctime=1568987932.234840537 optics-0.1.4/doc/0000755000175000017500000000000013541155434013513 5ustar00olafolaf00000000000000optics-0.1.4/doc/PaxHeaders.21787/zernikes_and_derivatives_cartesian_OSA.tex0000644000000000000000000000013213541155434023672 xustar0030 mtime=1568987932.198839838 30 atime=1568987932.198839838 30 ctime=1568987932.234840537 optics-0.1.4/doc/zernikes_and_derivatives_cartesian_OSA.tex0000644000175000017500000003714113541155434024057 0ustar00olafolaf00000000000000%% LyX 2.3.3 created this file. For more info, see http://www.lyx.org/. %% Do not edit unless you really know what you are doing. \documentclass[english]{article} \usepackage[T1]{fontenc} \usepackage[latin9]{inputenc} \usepackage[a4paper]{geometry} \geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm} \usepackage{color} \usepackage{babel} \usepackage{array} \usepackage{amsmath} \usepackage[unicode=true,pdfusetitle, bookmarks=true,bookmarksnumbered=false,bookmarksopen=false, breaklinks=false,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=true] {hyperref} \makeatletter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands. %% Because html converters don't know tabularnewline \providecommand{\tabularnewline}{\\} \makeatother \begin{document} \title{Calculation of the Zernike polynomials and their partial derivatives in Cartesian coordinates using the standard indexes OSA/ANSI.} \author{Jos Ramom Flores das Seixas} \date{August 4, 2019} \maketitle \tableofcontents{} \section{Introduction} The \texttt{zernikes\_and\_derivatives\_cartesian\_OSA} function calculates the Zernike polynomials and their partial derivatives in Cartesian coordinates. For this purpose, it uses the algorithm described in reference \cite{Andersen_2018}. However, it should be noted that in the cited article the author use unit-normalized Zernike polynomials arranged according to the azimuthal scheme set forth by Rimmer and Wyant \cite{Rimmer=000026Wyant_1975}, while to implement the function has been used the OSA/ANSI standard notation described in references \cite{Thibos_et_al_2002,ANSI-2017}. This means the index scheme is different and, moreover, the polynomials are not unit-normalized but normalized to $\pi$. \section{Notation} Zernike's polynomials are usually ordered by a double-index, $Z_{n}^{m}$, being $n$ the radial order and $m$ the angular frequency, both integers. Although in programming it is usually utilized a single index, $Z_{j}$. The scheme used in reference \cite{Andersen_2018}, consider a double-index with $n\geq0$ and $0\leq m\leq n$. However, the standard OSA/ANSI\footnote{In fact, this double index schema is the most usual, and is employed by other notations than the standard OSA/ANSI.} uses a double-index with $n\geq0$ and $-n\leq m\leq n$, as shown in the following table: \noindent \begin{center} \begin{tabular}{|c|c|c|c|>{\centering}p{3cm}|} \multicolumn{2}{|c|}{Rimmer\&Wyant schema} & & \multicolumn{2}{c|}{~~~~OSA standard~~~~}\tabularnewline \cline{1-2} \cline{2-2} \cline{4-5} \cline{5-5} $\tilde{n}$ & $\tilde{m}$ & & $n$ & $m$\tabularnewline \cline{1-2} \cline{2-2} \cline{4-5} \cline{5-5} 0 & 0 & & 0 & 0\tabularnewline \cline{1-2} \cline{2-2} \cline{4-5} \cline{5-5} 1 & 0, 1 & & 1 & -1, 1\tabularnewline \cline{1-2} \cline{2-2} \cline{4-5} \cline{5-5} 2 & 0, 1, 2 & & 2 & -2, 0, 2\tabularnewline \cline{1-2} \cline{2-2} \cline{4-5} \cline{5-5} 3 & 0, 1, 2, 3 & & 3 & -3, -1, 1, 3\tabularnewline \cline{1-2} \cline{2-2} \cline{4-5} \cline{5-5} 4 & 0, 1, 2, 3, 4 & & 4 & -4, -2, 0, 2, 4\tabularnewline \cline{1-2} \cline{2-2} \cline{4-5} \cline{5-5} $\vdots$ & $\vdots$ & & $\vdots$ & $\vdots$\tabularnewline \cline{1-2} \cline{2-2} \cline{4-5} \cline{5-5} \end{tabular} \par\end{center} Therefore, by the way of example, the following polynomials --using the two schemes seen-- are equivalent: \noindent \begin{center} \begin{tabular}{ccc} Rimmer\&Wyant schema & & ~~~~OSA standard~~~~\tabularnewline \cline{1-1} \cline{3-3} $Z_{1}^{0}\left(x,y\right)$ & ~~~~ & $Z_{1}^{-1}\left(x,y\right)$\tabularnewline $Z_{3}^{0}\left(x,y\right)$ & & $Z_{3}^{-3}\left(x,y\right)$\tabularnewline $Z_{3}^{1}\left(x,y\right)$ & & $Z_{3}^{-1}\left(x,y\right)$\tabularnewline $Z_{4}^{4}\left(x,y\right)$ & & $Z_{4}^{4}\left(x,y\right)$\tabularnewline $Z_{8}^{6}\left(x,y\right)$ & & $Z_{8}^{4}\left(x,y\right)$\tabularnewline \end{tabular} \par\end{center} Using $\left(\tilde{n},\tilde{m}\right)$ to denote the R\&W indices, and $\left(n,m\right)$ those of the OSA scheme, both pairs of indices are related as follow: \begin{equation} n=\tilde{n}\qquad m=2\cdot\tilde{m}-\tilde{n}\label{eq:R=000026W_to_OSA} \end{equation} \subsection{Single index} As said before, it is more convenient to use a simple index to program. In the OSA standard, the conversion of indices is \href{https://en.wikipedia.org/wiki/Zernike_polynomials\#OSA/ANSI_standard_indices}{as follows}: \[ j=\frac{n\left(n+2\right)+m}{2}\qquad\begin{array}{l} n=roundup\left[\dfrac{-3+\sqrt{9+8\,j}}{2}\right]\\ \\ m=2\,j-n\left(n+2\right) \end{array} \] \subsection{U-polynomials} Employing the notation used in reference \cite{Andersen_2018}, the unit-normalized Zernike's polynomials are called $U_{nm}$, and are related to the $\pi$-normalized ones as follows: \[ Z_{n}^{m}\left(x,y\right)=N_{nm}\cdot U_{nm}\left(x,y\right) \] with \[ N_{nm}=\sqrt{\frac{2\left(n+1\right)}{1+\delta_{m0}}}\qquad\textrm{being}\quad\delta_{m0}=\left\{ \begin{array}{ll} 1 & m=0\\ 0 & m\neq0 \end{array}\right. \] \section{Algorithm} It is well known that for high-order Zernike's polynomials, computing the values using explicit expressions is not the best strategy, since it is inefficient and suffers form large cancellation errors. So, several schemes using recurrence relations have been devised. Reference \cite{Andersen_2018} presents one recurrence relation with coefficients that do not depend on radial or azimuthal orders and which contains no singularities. In addition, it also presents a recurrence relation to compute the partial derivatives in Cartesian coordinates. \subsection{Recurrence relations in Cartesian coordinates for Zernike U-polynomials} The general recurrence relation is \[ U_{\tilde{n},\tilde{m}}=xU_{\tilde{n}-1,\tilde{m}}+yU_{\tilde{n}-1,\tilde{n}-1-\tilde{m}}+xU_{\tilde{n}-1,\tilde{m}-1}-yU_{\tilde{n}-1,\tilde{n}-\tilde{m}}-U_{\tilde{n}-2,\tilde{m}-1} \] But there are several exceptions: \begin{itemize} \item for $\tilde{m}=0$$\qquad U_{\tilde{n},0}=xU_{\tilde{n}-1,0}+yU_{\tilde{n}-1,\tilde{n}-1}$ \item for $\tilde{m}=\tilde{n}$$\qquad U_{\tilde{n},\tilde{n}}=xU_{\tilde{n}-1,\tilde{n}-1}-yU_{\tilde{n}-1,0}$ \item for $\tilde{n}$ odd and $\tilde{m}=\dfrac{\tilde{n}-1}{2}$ \[ U_{\tilde{n},\tilde{m}}=yU_{\tilde{n}-1,\tilde{n}-1-\tilde{m}}+xU_{\tilde{n}-1,\tilde{m}-1}-yU_{\tilde{n}-1,\tilde{n}-\tilde{m}}-U_{\tilde{n}-2,\tilde{m}-1} \] \item for $\tilde{n}$ odd and $\tilde{m}=\dfrac{\tilde{n}-1}{2}+1$ \[ U_{\tilde{n},\tilde{m}}=xU_{\tilde{n}-1,\tilde{m}}+yU_{\tilde{n}-1,\tilde{n}-1-\tilde{m}}+yU_{\tilde{n}-1,\tilde{m}-1}-U_{\tilde{n}-2,\tilde{m}-1} \] \item for $\tilde{n}$ even and $\tilde{m}=\dfrac{\tilde{n}}{2}$ \[ U_{\tilde{n},\tilde{m}}=2xU_{\tilde{n}-1,\tilde{m}}+2yU_{\tilde{n}-1,\tilde{m}-1}-U_{\tilde{n}-2,\tilde{m}-1} \] \end{itemize} The starting polynomials being \[ U_{0,0}=1,\quad U_{1,0}=y,\quad U_{1,1}=x\quad. \] \subsection{Recurrence relations for the OSA/ANSI scheme} If we now ``translate'' the previous equations into the OSA scheme, we obtain that the general recurrence relation is \[ U_{n.m}=xU_{n-1,m+1}+yU_{n-1,-\left(m+1\right)}+xU_{n-1,m-1}-yU_{n-1,1-m}-U_{n-2,m} \] the exceptions are given by \begin{itemize} \item for $m=-n$$\qquad U_{n,-n}=xU_{n-1,1-n}+yU_{n-1,n-1}$ \item for $m=n$$\qquad U_{n,n}=xU_{n-1,n-1}-yU_{n-1,1-n}$ \item for $m=-1$$\qquad U_{n,-1}=yU_{n-1,0}+xU_{n-1,-2}-yU_{n-1,2}-U_{n-2,-1}$ \item for $m=1$$\qquad U_{n,1}=xU_{n-1,2}+yU_{n-1,-2}+xU_{n-1,0}-U_{n-2,1}$ \item for $m=0$$\qquad U_{n,0}=2xU_{n-1,1}+2yU_{n-1,-1}-U_{n-2,0}$ \end{itemize} and the starting polynomials are \[ U_{0,0}=1,\quad U_{1,-1}=y\quad U_{1,1}=x\quad. \] Note that using the OSA scheme the conditions of the exceptions have been simplified, which makes it easier to compute. \subsubsection{Recurrence relations with a single index} As mentioned earlier, when programming it is more convenient to use a simple index. In this case, recurrence relations are given as follows. Let us start now with the exceptions: \begin{itemize} \item for $m=-n\quad\Rightarrow\quad j=\dfrac{\left(n+1\right)n}{n}$ \[ U_{j}=xU_{j-n}+yU_{j-1} \] \item for $m=n\quad\Rightarrow\quad j=\dfrac{n\left(n+3\right)}{2}$ \[ U_{j}=xU_{j-\left(n+1\right)}-yU_{j-2n} \] \item for $m=-1\quad\Rightarrow\quad j=\dfrac{n\left(n+2\right)-1}{2}$ \[ U_{j}=xU_{j-\left(n+1\right)}+yU_{j-n}-yU_{j-\left(n-1\right)}-U_{j-2n} \] \item for $m=1\quad\Rightarrow\quad j=\dfrac{n\left(n+2\right)+1}{2}$ \[ U_{j}=xU_{j-n}+xU_{j-\left(n+1\right)}+yU_{j-\left(n+2\right)}-U_{j-2n} \] \item for $m=0\quad\Rightarrow\quad j=\dfrac{n\left(n+2\right)}{2}$ \[ U_{j}=2xU_{j-n}+2yU_{j-\left(n+1\right)}-U_{j-2n}\,. \] \end{itemize} The general case is \[ U_{j}=xU_{j-n}+yU_{j-\left(n+m+1\right)}+xU_{j-\left(n+1\right)}-yU_{j-\left(m+m\right)}-U_{j-2n} \] and the starting polynomials are \[ U_{0}=1,\quad U_{1}=y,\quad U_{2}=x\quad. \] \subsection{Recurrence relations for Cartesian derivatives for Zernike U-polynomials} The general recursive relations for partial derivatives are: \[ \frac{\partial U_{\tilde{n},\tilde{m}}}{\partial x}=\tilde{n}U_{\tilde{n}-1,\tilde{m}}+\tilde{n}U_{\tilde{n}-1,\tilde{m}-1}+\frac{\partial U_{\tilde{n}-2,\tilde{m}-1}}{\partial x} \] and \[ \frac{\partial U_{\tilde{n},\tilde{m}}}{\partial y}=\tilde{n}U_{\tilde{n}-1}-\tilde{n}U_{\tilde{n}-1,\tilde{n}-\tilde{m}}+\frac{\partial U_{\tilde{n}-2,\tilde{m}-1}}{\partial y} \] But, as before, there are several exceptions: \begin{itemize} \item for $\tilde{m}=0$ \[ \frac{\partial U_{\tilde{n},0}}{\partial x}=\tilde{n}U_{\tilde{n}-1,0}\qquad\frac{\partial U_{\tilde{n},0}}{\partial y}=\tilde{n}U_{\tilde{n}-1,\tilde{n}-1} \] \item for $\tilde{m}=\tilde{n}$ \[ \frac{\partial U_{\tilde{n},\tilde{n}}}{\partial x}=-\tilde{n}U_{\tilde{n}-1,\tilde{n}-1}\qquad\frac{\partial U_{\tilde{n},\tilde{n}}}{\partial y}=-\tilde{n}U_{\tilde{n}-1,0} \] \item for $\tilde{n}$ odd and $\tilde{m}=\dfrac{\tilde{n}-1}{2}$ \[ \frac{\partial U_{\tilde{n},\tilde{m}}}{\partial x}=\tilde{n}U_{\tilde{n}-1,\tilde{m}-1}+\frac{\partial U_{\tilde{n}-2,\tilde{m}-1}}{\partial x}\qquad\frac{\partial U_{\tilde{n},\tilde{m}}}{\partial y}=\tilde{n}U_{\tilde{n}-1,\tilde{n}-\tilde{m}-1}-\tilde{n}U_{\tilde{n}-1,\tilde{n}-\tilde{m}}+\frac{\partial U_{\tilde{n}-2,\tilde{m}-1}}{\partial y} \] \item for $\tilde{n}$ odd and $\tilde{m}=\dfrac{\tilde{n}-1}{2}+1$ \[ \frac{\partial U_{\tilde{n},\tilde{m}}}{\partial x}=\tilde{n}U_{\tilde{n}-1,\tilde{m}}+\tilde{n}U_{\tilde{n}-1,\tilde{m}-1}+\frac{\partial U_{\tilde{n}-2,\tilde{m}-1}}{\partial x}\qquad\frac{\partial U_{\tilde{n},\tilde{m}}}{\partial y}=\tilde{n}U_{\tilde{n}-1,\tilde{n}-\tilde{m}-1}+\frac{\partial U_{\tilde{n}-2,\tilde{m}-1}}{\partial y} \] \item for $\tilde{n}$ even and $\tilde{m}=\dfrac{\tilde{n}}{2}$ \[ \frac{\partial U_{\tilde{n},\tilde{m}}}{\partial x}=2\tilde{n}U_{\tilde{n}-1,\tilde{m}}+\frac{\partial U_{\tilde{n}-2,\tilde{m}-1}}{\partial x}\qquad\frac{\partial U_{\tilde{n},\tilde{m}}}{\partial y}=2\tilde{n}U_{\tilde{n}-1,\tilde{n}-\tilde{m}-1}+\frac{\partial U_{\tilde{n}-2,\tilde{m}-1}}{\partial y} \] \end{itemize} The starting expressions for the Cartesian derivatives being: \[ \frac{\partial U_{0,0}}{\partial x}=\frac{\partial U_{0,0}}{\partial y}=0,\quad\frac{\partial U_{1,0}}{\partial x}=\frac{\partial U_{1,1}}{\partial y}=0,\quad\frac{\partial U_{1,1}}{\partial x}=\frac{\partial U_{1,0}}{\partial y}=1 \] \subsubsection{Recurrence relations for the OSA/ANSI scheme} If we now ``translate'' the previous equations into the OSA scheme, we obtain that the general recurrence relations for partial derivativess are \[ \frac{\partial U_{n,m}}{\partial x}=nU_{n-1,m+1}+nU_{n-1,m-1}+\frac{\partial U_{n-2,m}}{\partial x} \] and \[ \frac{\partial U_{n,m}}{\partial y}=nU_{n-1,-\left(m+1\right)}-nU_{n-1,1-m}+\frac{\partial U_{n-2,m}}{\partial y} \] the exceptions are give by \begin{itemize} \item for $m=-n$$\qquad\dfrac{\partial U_{n,-n}}{\partial x}=nU_{n-1,1-n}\qquad\dfrac{\partial U_{n,-n}}{\partial y}=nU_{n-1,n-1}$ \item for $m=n$$\qquad\dfrac{\partial U_{n,-n}}{\partial x}=nU_{n-1,n-1}\qquad\dfrac{\partial U_{n,-n}}{\partial y}=-nU_{n-1,1-n}$ \item for $m=-1$ \[ \dfrac{\partial U_{n,-1}}{\partial x}=nU_{n-1,-2}+\dfrac{\partial U_{n-2,-1}}{\partial x}\qquad\dfrac{\partial U_{n,-1}}{\partial y}=nU_{n-1,0}-nU_{n-1,2}+\dfrac{\partial U_{n-2,-1}}{\partial y} \] \item for $m=1$ \[ \dfrac{\partial U_{n,1}}{\partial x}=nU_{n-1,2}+nU_{n-1,0}+\dfrac{\partial U_{n-2,1}}{\partial x}\qquad\dfrac{\partial U_{n,1}}{\partial y}=nU_{n-1,-2}+\dfrac{\partial U_{n-2,1}}{\partial y} \] \item for $m=0$ \[ \dfrac{\partial U_{n,0}}{\partial x}=2nU_{n-1,1}+\dfrac{\partial U_{n-2,0}}{\partial x}\qquad\dfrac{\partial U_{n,0}}{\partial y}=2nU_{n-1,-1}+\dfrac{\partial U_{n-2,0}}{\partial y} \] \end{itemize} and the starting derivatives are \[ \frac{\partial U_{0,0}}{\partial x}=\frac{\partial U_{0,0}}{\partial y}=0,\quad\frac{\partial U_{1,-1}}{\partial x}=\frac{\partial U_{1,1}}{\partial y}=0,\quad\frac{\partial U_{1,1}}{\partial x}=\frac{\partial U_{1,-1}}{\partial y}=1 \] \subsubsection{Recurrence relations with a single index} Let us start now with the exceptions: \begin{itemize} \item for $m=-n\quad\Rightarrow\quad j=\dfrac{\left(n+1\right)n}{n}$ \[ \frac{\partial U_{j}}{\partial x}=nU_{j-n}\qquad\frac{\partial U_{j}}{\partial y}=nU_{j-1} \] \item for $m=n\quad\Rightarrow\quad j=\dfrac{n\left(n+3\right)}{2}$ \[ \frac{\partial U_{j}}{\partial x}=nU_{j-\left(n+1\right)}\qquad\frac{\partial U_{j}}{\partial y}=-nU_{j-2n} \] \item for $m=-1\quad\Rightarrow\quad j=\dfrac{n\left(n+2\right)-1}{2}$ \[ \frac{\partial U_{j}}{\partial x}=nU_{j-\left(n+1\right)}+\frac{\partial U_{j-2n}}{\partial x}\qquad\frac{\partial U_{j}}{\partial y}=nU_{j-n}-nU_{j-\left(n-1\right)}+\frac{\partial U_{j-2n}}{\partial y} \] \item for $m=1\quad\Rightarrow\quad j=\dfrac{n\left(n+2\right)+1}{2}$ \[ \frac{\partial U_{j}}{\partial x}=nU_{j-n}+nU_{j-\left(n+1\right)}+\frac{\partial U_{j-2n}}{\partial x}\qquad\frac{\partial U_{j}}{\partial y}=nU_{j-\left(n+2\right)}+\frac{\partial U_{j-2n}}{\partial y} \] \item for $m=0\quad\Rightarrow\quad j=\dfrac{n\left(n+2\right)}{2}$ \[ \frac{\partial U_{j}}{\partial x}=2nU_{j-n}+\frac{\partial U_{j-2n}}{\partial x}\qquad\frac{\partial U_{j}}{\partial y}=2nU_{j-\left(n+1\right)}+\frac{\partial U_{j-2n}}{\partial y} \] \end{itemize} The general case is \[ \frac{\partial U_{j}}{\partial x}=nU_{j-n}+nU_{j-\left(n+1\right)}+\frac{\partial U_{j-2n}}{\partial x}\qquad\frac{\partial U_{j}}{\partial y}=nU_{j-\left(n+m+1\right)}-nU_{j-\left(n+m\right)}+\frac{\partial U_{j-2n}}{\partial y} \] and the starting derivatives are \[ \frac{\partial U_{0}}{\partial x}=\frac{\partial U_{0}}{\partial y}=0,\quad\frac{\partial U_{1}}{\partial x}=\frac{\partial U_{2}}{\partial y}=0,\quad\frac{\partial U_{2}}{\partial x}=\frac{\partial U_{1}}{\partial y}=1 \] \begin{thebibliography}{1} \bibitem{Andersen_2018}Andersen T.B., \href{https://doi.org/10.1364/OE.26.018878}{Efficient and robust recurrence relations for the Zernike circle polynomials and their derivatives in Cartesian coordinates}. \emph{Optic Express 26}(15), 18878-18896 (2018). \bibitem{Rimmer=000026Wyant_1975}Rimmer M.P. \& Wyant J.C., \href{https://wp.optics.arizona.edu/jcwyant/wp-content/uploads/sites/13/2016/08/LSI-Analysis.pdf}{Evaluation of large aberrations using a lateral-shear interferometer having variable shear}. \emph{Appl. Opt. 14}(1), 142--150 (1975). \bibitem{Thibos_et_al_2002}Thibos, L.N, Applegate, R.A., Schwiegerling, J.T. \& Webb, R., \href{https://pdfs.semanticscholar.org/6e71/c63afa9960dc6e452f3ae2c8b20e2185ba88.pdf}{Standards for reporting the optical aberrations of eyes}. \emph{Journal of refractive surgery}, \emph{18}(5), S652-S660 (2002). \bibitem{ANSI-2017}ANSI Z80.28--2017. American National Standards of Ophthalmics:methods for reporting optical aberrations of eyes. \end{thebibliography} \end{document}