diff options
Diffstat (limited to 'misc/fresneliso.m')
-rw-r--r-- | misc/fresneliso.m | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/misc/fresneliso.m b/misc/fresneliso.m new file mode 100644 index 0000000..fd9ee02 --- /dev/null +++ b/misc/fresneliso.m @@ -0,0 +1,56 @@ +% fresneliso.m - Fresnel reflection coefficients for isotropic media with either indices _or_ lambda as vectors
+%
+% Usage: [rs,rp] = fresnel(na,nb,theta)
+%
+% na,nb = refractive indices of left and right media. May be vectors if lambda is not.
+% theta = incident angle(s) in degrees. May be a vector if na and nb are vectors.
+% rs,rp = reflection coefficients for p and s polarizations
+%
+% Modified by Andri M. Gretarsson from fresnel.m written by Orfanidi. August 2008.
+
+function [rs,rp] = fresnel(na,nb,theta)
+
+if nargin==0, help fresnel; return; end
+
+if length(na)==1
+ na=ones(size(nb))*na;
+elseif length(nb)==1
+ nb=ones(size(na));
+end
+theta = pi*theta/180;
+
+if length(nb) == 1
+ Na = 1./sqrt(cos(theta).^2/na^2 + sin(theta).^2/na^2);
+ xe = (na*sin(theta)).^2; % used for s-pol
+ xm = (Na.*sin(theta)).^2; % used for p-pol
+
+ rs = (na*cos(theta) - sqrt(nb^2 - xe)) ./ ...
+ (na*cos(theta) + sqrt(nb^2 - xe));
+
+ if na==nb,
+ rp = (na - nb) / (na + nb) * ones(1,length(theta));
+ else
+ rp = (na*na * sqrt(nb^2 - xm) - nb*nb * sqrt(na^2 - xm)) ./ ...
+ (na*na * sqrt(nb^2 - xm) + nb*nb * sqrt(na^2 - xm));
+ end
+elseif length(theta) == 1
+ Na = 1./sqrt(cos(theta)^2./na.^2 + sin(theta)^2./na.^2);
+ xe = (na*sin(theta)).^2; % used for s-pol
+ xm = (Na*sin(theta)).^2; % used for p-pol
+
+ rs = (na*cos(theta) - sqrt(nb.^2 - xe)) ./ ...
+ (na*cos(theta) + sqrt(nb.^2 - xe));
+
+ if na==nb,
+ rp = (na - nb) ./ (na + nb);
+ else
+ rp = (na.*na .* sqrt(nb.^2 - xm) - nb.*nb .* sqrt(na.^2 - xm)) ./ ...
+ (na.*na .* sqrt(nb.^2 - xm) + nb.*nb .* sqrt(na.^2 - xm));
+ end
+
+else
+ error('Either na and nb must have length 1 _or_ theta must have length 1.');
+end
+
+
+
|