-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSimWindow.m
173 lines (151 loc) · 4.2 KB
/
SimWindow.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
classdef SimWindow < matlab.mixin.Copyable
%
% Sebastian C. Robarts 2023 - sebrobarts@gmail.com
properties
ReferenceWave
NumberOfPoints
TemporalRange
TimeOffset
SpectralLimits = [300 6000] % Wavelength cutoffs [nm]
Constraint = "time";
end
properties (Dependent)
ReferenceOmega
ReferenceIndex
DeltaTime
DeltaLambda0
DeltaNu
DeltaOmega
Granularity % Colour plot sample spacing
Times
Timesfs
TimesfsPlot % Timesfs sampled according to Granularity
Frequencies
RelativeFrequencies
Omegas
RelativeOmegas
Wavelengths
Lambdanm
LambdanmPlot
IsNumIndex % Index to address the non-NAN elements of lambda
end
methods
% Constructor
function obj = SimWindow(lambda_ref,n_points,win_range,t_off,constraint)
arguments
lambda_ref
n_points
win_range = 1e-12;
t_off = 0;
constraint = "time";
end
obj.ReferenceWave = lambda_ref;
obj.NumberOfPoints = n_points;
obj.TimeOffset = t_off;
obj.Constraint = constraint;
if strcmp(constraint,"time")
obj.TemporalRange = win_range;
% obj.SpectralLimits = [min(obj.Wavelengths) max(obj.Wavelengths)].*1e9;
% if obj.SpectralLimits(1) < 0
% obj.SpectralLimits(1) = 0 + eps;
% end
else
obj.SpectralLimits = win_range;
obj.TemporalRange = range(obj.Times);
end
end
function w0 = get.ReferenceOmega(obj)
w0 = 2*pi*c/obj.ReferenceWave;
end
function t_rel = get.Times(obj)
if strcmp(obj.Constraint,"time")
np = obj.NumberOfPoints;
t_axis = obj.TemporalRange;
t_rel = (-np/2:np/2-1)/np*t_axis; % relative time array [s]
else
t_rel = fftax(obj.RelativeFrequencies); % relative time from relative frequency array [s]
end
end
function f_rel = get.RelativeFrequencies(obj)
if strcmp(obj.Constraint,"time")
f_rel = fftax(obj.Times); % relative frequency from relative time array [Hz]
else
np = obj.NumberOfPoints;
% Prevent f0 = 0;
if ~mod(obj.ReferenceWave*1e9,obj.SpectralLimits(1))
obj.SpectralLimits(1) = obj.SpectralLimits(1) - 1;
end
if ~mod(obj.SpectralLimits(2),obj.ReferenceWave*1e9)
obj.SpectralLimits(2) = obj.SpectralLimits(2) + 1;
end
f0 = c./obj.ReferenceWave;
f_max = (c ./ obj.SpectralLimits(1) ./1e-9) - f0;
f_min = (c ./ obj.SpectralLimits(2) ./1e-9) - f0;
f_axis = 2 * max(abs(f_min),abs(f_max));
% f_axis = 4 * max(abs(f_min),abs(f_max)); % avoid spectral aliasing?
f_rel = (-np/2:np/2-1)/np*f_axis; % relative frequency array [Hz]
end
end
function f = get.Frequencies(obj)
f0 = c./obj.ReferenceWave;
f_rel = obj.RelativeFrequencies;
f = f_rel + f0;
end
function w_abs = get.Omegas(obj)
f0 = c/obj.ReferenceWave;
f = obj.RelativeFrequencies;
w_abs = 2*pi*(f+(1*f0)); % absolute angular frequency
end
function w_rel = get.RelativeOmegas(obj)
w_rel = obj.Omegas - obj.ReferenceOmega; % relative angular frequency
end
function l = get.Wavelengths(obj)
l = 2*pi*c./obj.Omegas;
end
function tfs = get.Timesfs(obj)
tfs = obj.Times*1e15;
end
function tfsp = get.TimesfsPlot(obj)
cgrain = obj.Granularity;
tfsp = obj.Timesfs(1:cgrain:end);
end
function dt = get.DeltaTime(obj)
dt = obj.Times(2) - obj.Times(1);
end
function dl0 = get.DeltaLambda0(obj)
dl0 = (obj.Wavelengths(obj.ReferenceIndex-1) - obj.Wavelengths(obj.ReferenceIndex+1))/2;
end
function dw = get.DeltaOmega(obj)
dw = obj.Omegas(2) - obj.Omegas(1);
end
function dNu = get.DeltaNu(obj)
dNu = obj.RelativeFrequencies(2) - obj.RelativeFrequencies(1);
end
function cgrain = get.Granularity(obj)
n_points = obj.NumberOfPoints;
cgrain = ceil(n_points/(2^15));
end
function l = get.Lambdanm(obj)
l = obj.Wavelengths*1e9;
l(or(l<obj.SpectralLimits(1)-1, l>obj.SpectralLimits(2)+1)) = NaN;
end
function ini = get.IsNumIndex(obj)
x = obj.Lambdanm;
ini = ~isnan(x);
end
function lp = get.LambdanmPlot(obj)
x = obj.Lambdanm;
lp = x(obj.IsNumIndex);
end
function cidx = get.ReferenceIndex(obj)
cidx = floor(obj.NumberOfPoints/2) + 1;
end
function ref2max(obj)
lamlims = obj.SpectralLimits.*1e-9;
nulims = c./lamlims;
numid = mean(nulims);
lammid = c./numid;
obj.ReferenceWave = lammid;
end
end
end