-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterpSimSpec.m
More file actions
35 lines (31 loc) · 1.13 KB
/
interpSimSpec.m
File metadata and controls
35 lines (31 loc) · 1.13 KB
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
function SIM_SPEC = interpSimSpec(OUT,spectrum_axis,nBin,delta,eta)
% Identify Max and Min of Simulated energy distribution
x_max = OUT.X.AXIS(nBin);
x_min = OUT.X.AXIS(1);
% Find the Max and Min on the YAG energy axis
[~,iMax] = min(abs(x_max - spectrum_axis));
[~,iMin] = min(abs(x_min - spectrum_axis));
N = iMax - iMin + 1;
% Interpolate the simulated distribution onto the YAG axis
xx = linspace(1,nBin,N);
SX = interp1(OUT.X.HIST,xx);
sim_sum = sum(SX);
sim_cen = round(sum((1:N).*SX)/sim_sum);
% Embed onto spectrum axis
PIX = length(spectrum_axis);
SIM_SPEC = zeros(PIX,1);
bin = spectrum_axis(2) - spectrum_axis(1);
offset = round(delta*eta/bin);
max_bin = offset + PIX/2 - sim_cen + N - 1;
min_bin = offset + PIX/2 - sim_cen;
if max_bin > PIX
warning('Delta = %0.4f is too high and moves spectrum out of range.',delta);
top_bin = PIX/2 + sim_cen - offset + 1;
SIM_SPEC(min_bin:PIX) = SX(1:top_bin)/sim_sum;
elseif min_bin < 1
warning('Delta = %0.4f is too low and moves spectrum out of range.',delta);
bot_bin = 2 - min_bin;
SIM_SPEC(1:max_bin) = SX(bot_bin:N)/sim_sum;
else
SIM_SPEC(min_bin:max_bin) = SX/sim_sum;
end