-
Notifications
You must be signed in to change notification settings - Fork 17
/
test2_multicomponent_CPMG.m
235 lines (185 loc) · 5.91 KB
/
test2_multicomponent_CPMG.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
%%% Test 2: Multiecho CPMG
addpath(genpath('lib'));
addpath(genpath('EPGX-src'));
%%% Water excahnge model. For interpretation, compartment A is the larger
%%% (slow relaxing) and B is the small, fast relaxing compartment (myelin
%%% water?)
f = 0.20; %<--- pool b fraction (this is fast relaxing pool) i.e. myelin water fraction
fka = 2e-2; % This is ka->b (i.e. Ksf in mcdespot; fb*kb = fa*ka, so kb = (1-fb)*ka/fb -- this is 1/tau
T1 = [1000 500];
T2 = [100 20];
%%% Pulse sequence parameters
ESP=5;
a0 = d2r([90 180*ones(1,50)]);
Npulse = length(a0);
Necho = Npulse-1;
%%% Analyse the echoes using NNLS (Whittall KP, MacKay AL. Quantitative
%%% interpretation of NMR relaxation data. J. Magn. Reson. 1989;84:134?152.)
nt2 = 2001;
t2s = linspace(10,120,nt2);
r2s = 1./t2s;
tt = ESP*(1:Necho);
S =exp(-r2s(:)*tt);
%% 1. Look at estimated T2s/fraction as a function of B1 offset and exchange rate
nk=32;ntx=32;
delta = 0;
ka = linspace(0,2.5e-3,nk);
tx = linspace(0.75,1.25,ntx);
t2app = zeros(nk,ntx,2);
fapp = zeros(nk,ntx);
for ii=1:nk
for jj=1:ntx
s = EPGX_TSE_BM(a0*tx(jj),ESP,T1,T2,f,ka(ii),'delta',delta);
t2sol = lsqnonneg(S',abs(s(:)));
[~,pks] = findpeaks(t2sol);
tmp = t2s(pks);
t2app(ii,jj,:)=tmp(1:2);%<- in case more than 2 peaks
% fraction
fapp(ii,jj) = sum(t2sol(pks(1)+(-5:5))) / sum(t2sol(:)); %<-- look 5 points either side
end
disp([ii jj])
end
%% Now examine effect of delta and kx for B1scaling=1
nk=32;nd=32;
ka2 = linspace(0,2.5e-3,nk);
dppm = linspace(-1,1,nd);
delta = dppm*1e-6*3*42.6e3;% ppm * 3T * 42.6kHz/T
nt2_2 = 500;
t2s_2 = linspace(10,120,nt2_2);
r2s_2 = 1./t2s_2;
tt = ESP*(1:Necho);
S_2 =exp(-r2s_2(:)*tt);
t2app_2 = zeros(nk,nd,2);
fapp_2 = zeros(nk,nd);
for ii=1:nk
for jj=1:nd
s = EPGX_TSE_BM(a0,ESP,T1,T2,f,ka2(ii),'delta',delta(jj));
t2sol = lsqnonneg(S_2',abs(s(:)));
[~,pks] = findpeaks(t2sol);
tmp = t2s_2(pks);
t2app_2(ii,jj,:)=tmp(1:2);%<- in case more than 2 peaks
% fraction
fapp_2(ii,jj) = sum(t2sol(pks(1)+(-5:5))) / sum(t2sol(:)); %<-- look 5 points either side
end
disp([ii jj])
end
%% Combined figure
%%% example curve
[s,Fn] = EPGX_TSE_BM(a0*1.1,ESP,T1,T2,f,2e-3);
t2sol = lsqnonneg(S',abs(s(:)));
[~,pks] = findpeaks(t2sol);
t2s(pks)
sum(t2sol(pks(1)+(-5:5)))/ sum(t2sol(:)) %<-- look 5 points either side
figure(1);clf;
nr=2;nc=3;
subplot(nr,nc,2)
imagesc(tx,ka*1e3,fapp,[0.12 0.22])
hold
[cc,h]=contour(tx,ka*1e3,fapp,0.1:0.02:0.24,'linewidth',1.5);
h.LineColor = [1 1 1];
clabel(cc,h,'Color',[1 1 1],'fontweight','bold')
title('$$\hat{f}$$','Interpreter','latex','fontsize',16)
xlabel('B_1 scaling factor')
ylabel('k_a, s^{-1}')
set(gca,'FontSize',12)
colorbar
subplot(nr,nc,5)
imagesc(tx,ka*1e3,t2app(:,:,1),[16 45])
hold
[cc,h]=contour(tx,ka*1e3,t2app(:,:,1),16:4:36,'linewidth',1.5);
h.LineColor = [1 1 1];
clabel(cc,h,'Color',[1 1 1],'fontweight','bold')
title('$$\hat{T}_{2,b}$$','Interpreter','latex','fontsize',16)
xlabel('B_1 scaling factor')
ylabel('k_a, s^{-1}')
set(gca,'FontSize',12)
colorbar
subplot(nr,nc,4)
plot(t2s,t2sol)
grid on
hold
xlabel('T_2 / ms')
ylabel('au')
title('T_2 spectrum from NNLS')
xlim([15 105])
set(gca,'FontSize',12)
subplot(nr,nc,1)
plot((1:50)*ESP,abs(s),'linewidth',2)
grid on
hold
plot((1:50)*ESP,squeeze(abs(Fn(52,:,:))),'linewidth',2)
xlabel('Echo time / ms')
ylabel('Signal (F_0)')
title('Echo amplitudes')
xlim([1 50]*ESP)
set(gca,'FontSize',12)
subplot(nr,nc,3)
imagesc(dppm,ka*1e3,fapp_2,[0.12 0.22])
hold
[cc,h]=contour(dppm,ka*1e3,fapp_2,0.08:0.02:0.24,'linewidth',1.5);
h.LineColor = [1 1 1];
clabel(cc,h,'Color',[1 1 1],'fontweight','bold')
title('$$\hat{f}$$','Interpreter','latex','fontsize',16)
xlabel('\delta_b ppm (@3T)')
ylabel('k_a, s^{-1}')
set(gca,'FontSize',12)
colorbar
subplot(nr,nc,6)
imagesc(dppm,ka*1e3,t2app_2(:,:,1),[10 22])
hold
[cc,h]=contour(dppm,ka*1e3,t2app_2(:,:,1),15:25,'linewidth',1.5);
h.LineColor = [1 1 1];
clabel(cc,h,'Color',[1 1 1],'fontweight','bold')
title('$$\hat{T}_{2,b}$$','Interpreter','latex')
xlabel('\delta_b ppm (@3T)')
ylabel('k_a, s^{-1}')
set(gca,'FontSize',12)
colorbar
gg=get(gcf,'children');
%%% INset plot
%
axes(gg(2))
ax=axes('Position',[0.12 0.2229 0.0949 0.0996]);
box on
pp = patch(t2s([-5:5]+pks(1)),t2sol([-5:5]+pks(1)),ones([1 11]));
xlim([19 21])
grid on
pp.FaceColor = [0.75 0.75 0.];
pp.EdgeColor = [0 0.5 0.75];
aa=annotation('arrow',[0.11 0.09],[0.2104 0.1653]);
colormap viridis %<-- https://uk.mathworks.com/matlabcentral/fileexchange/51986-perceptually-uniform-colormaps
pause(0.01)
%
cbww=0.01;cbhh=0.2;
ww = 0.225;hh=0.32;
lg = 0.07;
ga = 0.09;
gg(1).Position = [lg+2*ga+3*ww+0.01 0.15 cbww cbhh];
gg(2).Position = [lg+2*ga+2*ww 0.1 ww hh];
gg(3).Position = [lg+2*ga+3*ww+0.01 0.65 cbww cbhh];
gg(4).Position = [lg+2*ga+2*ww 0.6 ww hh];
gg(7).Position = [lg+lg+2*ww+0.01 0.15 cbww cbhh];
gg(8).Position = [lg+lg+ww 0.1 ww hh];
gg(9).Position = [lg+lg+2*ww+0.01 0.65 cbww cbhh];
gg(10).Position = [lg+lg+ww 0.6 ww hh];
gg(5).Position = [lg 0.6 ww hh];
gg(6).Position = [lg 0.1 ww hh];
%%% labels
axes(gg(5))
fs=18;
text(-30,-0.15,'(a)','fontsize',fs,'fontweight','bold')
text(-30,-1.7,'(b)','fontsize',fs,'fontweight','bold')
text(280,-0.15,'(c)','fontsize',fs,'fontweight','bold')
text(280,-1.7,'(d)','fontsize',fs,'fontweight','bold')
text(640,-0.15,'(e)','fontsize',fs,'fontweight','bold')
text(640,-1.7,'(f)','fontsize',fs,'fontweight','bold')
text(600,0.05,'$$\hat{f}$$','Interpreter','latex','fontsize',14);%,'fontangle','italic')
text(970,0.05,'$$\hat{f}$$','Interpreter','latex','fontsize',14);%,'fontangle','italic')
text(580,-1.5,'ms','fontsize',14);%,'fontangle','italic')
text(940,-1.5,'ms','fontsize',14);%,'fontangle','italic')
% legend
axes(gg(5))
legend('Total echo amplitude','Compartment a','Compartment b')
setpospap([360 231 900 450])
%
print -r300 -dpng bin/Test2_fig1.png