-
Notifications
You must be signed in to change notification settings - Fork 9
/
tf_nk.m
57 lines (45 loc) · 1.64 KB
/
tf_nk.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function [nk] = tf_nk(ri, wlen);
%function [nk] = tf_nk(ri, wlen);
%
% tf_nk : calculate the complex refractive index at a set of
% wavelengths either via interpolation from a table of indices,
% or by evaluating a function describing the refractive index..
%
% Input:
% ri : EITHER a refractive index table
% ri.lambda : wavelength nodes in micrometer
% ri.nk : refractive index at wavelength nodes
% ri.name : name of material
% OR a function handle
% OR a constant refractive index
% wlen : vector with wavelengths in um at which to calculate the index
%
% Output:
% nk : vector of complex refractive indices at wavelengths wlen
%
% Initial version, Ulf Griesmann, February 2013
% check arguments
if nargin < 2
error('tf_nk : two input arguments required.');
end
if isstruct(ri)
% check if wavelength
if any(wlen < ri.lambda(1)) || any(wlen > ri.lambda(end))
if isfield(ri, 'name')
name = ri.name;
else
name = 'unknown';
end
error( sprintf('tf_nk : wavelength(s) outside range of nk(lambda) for material ''%s''.', name) );
end
nk = complex(interp1(ri.lambda, real(ri.nk), wlen, 'pchip'), ...
interp1(ri.lambda, imag(ri.nk), wlen, 'pchip'));
elseif isa(ri, 'function_handle')
nk = ri(wlen);
else
if ~isscalar(ri)
error('tf_nk: constant argument is not a scalar.');
end
nk = repmat(ri, size(wlen));
end
end