-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathdemo_replay_frequencydomain.m
92 lines (86 loc) · 2.98 KB
/
demo_replay_frequencydomain.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MCXLAB - Monte Carlo eXtreme for MATLAB/Octave by Qianqian Fang
%
% In this example, we show how to compute the
% Jacobians for log-amplitude and phase shift in the
% frequency domain (FD)/radio frequency (RF) mode.
%
% NOTE: Requires (nightly-build) version from 15 May 2023 or later!
% Add the path to the MCXLAB-files.
%
% Ref.: Hirvi et al. (2023). Effects of atlas-based anatomy on modelled
% light transport in the neonatal head. Phys. Med. Biol.
% https://doi.org/10.1088/1361-6560/acd48c
%
% This file is part of Monte Carlo eXtreme (MCX) URL:http://mcx.sf.net
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FORM TARGET MODEL
% Here we consider a simple layered slab model with brain-like optical parameters.
layered_model = ones(90, 60, 60);
layered_model(:, :, 4) = 2;
layered_model(:, :, 5:8) = 3;
layered_model(:, :, 9:end) = 4;
opt_params = [0, 0, 1, 1; 0.0150, 16, 0.9, 1.4; 0.004, 1.6, 0.9, 1.4; 0.048, 5, 0.9, 1.4; 0.037, 10, 0.9, 1.4];
f_mod = 100e6; % 100 MHz RF modulation frequency
% MCXLAB SETTINGS
clear cfg;
cfg.nphoton = 3e7;
cfg.vol = uint8(layered_model);
cfg.prop = opt_params;
cfg.tstart = 0;
cfg.tend = 1 / f_mod;
cfg.tstep = cfg.tend;
cfg.isnormalized = 0;
cfg.unitinmm = 1.0;
cfg.isspecular = 0; % photons have initial weight 1
cfg.issrcfrom0 = 0; % first voxel is [1 1 1] in MATLAB
cfg.srcpos = [30, 30, 1];
cfg.srcdir = [0, 0, 1];
cfg.detpos = [45, 30, 1, 2; 60, 30, 1, 2]; % two detectors, one source
cfg.maxdetphoton = 5e7;
cfg.gpuid = 1; % cfg.gpuid='11'; % use two GPUs together
cfg.autopilot = 1;
cfg.savedetflag = 'dp';
% FORWARD SIMULATION
% Calculate the forward simulation distribution with the given config
% for one source and both detectors.
[flux, detp, vol, seeds] = mcxlab(cfg);
% RF REPLAY JACOBIANS
[rfjac_lnA, rfjac_phase] = mcxrfreplay(cfg, f_mod, detp, seeds, 1:2); % function from utils
% Separate source-detector -pairwise Jacobians as 3D matrices.
rfjac_lnA_det1 = rfjac_lnA(:, :, :, 1); % det 1
rfjac_lnA_det2 = rfjac_lnA(:, :, :, 2); % det 2
rfjac_phase_det1 = rfjac_phase(:, :, :, 1); % det 1
rfjac_phase_det2 = rfjac_phase(:, :, :, 2); % det 2
% Visualize Jacobian slices for both data types and source-detector pairs.
set(figure, 'Position', [0 0 900 400]);
tiledlayout(2, 2, 'Padding', 'compact', 'TileSpacing', 'compact');
set(gcf, 'Color', 'w');
nexttile;
imagesc(((squeeze(rfjac_lnA_det1(:, 30, 1:20)))));
view(-90, -90);
axis image;
title('d(lnA) det 1 [mm]');
set(gca, 'FontSize', 14);
colorbar;
nexttile;
imagesc(((squeeze(rfjac_lnA_det2(:, 30, 1:20)))));
view(-90, -90);
axis image;
title('d(lnA) det 2 [mm]');
set(gca, 'FontSize', 14);
colorbar;
nexttile;
imagesc(((squeeze(rfjac_phase_det1(:, 30, 1:20)))));
view(-90, -90);
axis image;
title('d(phase) det 1 [rad x mm]');
set(gca, 'FontSize', 14);
colorbar;
nexttile;
imagesc(((squeeze(rfjac_phase_det2(:, 30, 1:20)))));
view(-90, -90);
axis image;
title('d(phase) det 2 [rad x mm]');
set(gca, 'FontSize', 14);
colorbar;