-
Notifications
You must be signed in to change notification settings - Fork 9
/
rfwrite.m
executable file
·141 lines (112 loc) · 3.02 KB
/
rfwrite.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
function rfwrite(rf, nompw, ang, GAMMA, isodelay, g, thk)
% rfwrite(rf, nompw, ang, GAMMA, isodelay, nombw)
% OR
% rfwrite(rf, nompw, ang, GAMMA, isodelay, g, thk)
%
% Write RF pulse and rfstat information into prompted filename
% optionally will write phase and gradient
% Files can be read back into matlab by rfread() or signaread()
%
% rf - in G
% nompw - in sec
% ang - flip angle in radians
% GAMMA (optional) - in Hz/G (leave empty for protons)
% isodelay (optional) - in sec, leave empty for estimate
% nombw - in Hz (can be set to zero if unnecessary)
% OR
% g - in G/cm
% thk - thickness in cm
%
% PEZL 9/26/07, 6/16/08
% based on code from Chuck and Adam
%
% modified by Hong Shang July 2014
% reorder parameters to be consistent with our system
GAMMA_H1 = 4257;
if (nargin < 4) || isempty(GAMMA)
GAMMA = GAMMA_H1;
end
if nargin > 6
gwrite = 1;
else
gwrite = 0;
end
root_fname = input('Root file name: ', 's');
if isempty(root_fname)
fprintf(1,'Not saving files \n');
return;
end;
% scale for proton GAMMA for epic
rf = rf * GAMMA / GAMMA_H1;
maxrf = max(abs(rf));
rfn = rf / maxrf;
nrf = length(rf);
% write dat file
dat_name = sprintf('%s.dat', root_fname);
fid = fopen(dat_name, 'w');
if fid == -1,
fprintf(1, 'Error opening %s \n', dat_name);
return;
end;
pon = (rfn >= 0.00001);
temp_pw = 0;
max_pw = 0;
for n=1:nrf
temp_pw = temp_pw + pon(n);
if (and(pon(n) == 0, temp_pw ~= 0))
max_pw = max(max_pw, temp_pw);
temp_pw = 0;
end;
end;
max_pw = max_pw / n;
dty_cyc = sum(abs(rfn) > 0.2236)/nrf;
if dty_cyc < max_pw,
dty_cyc = max_pw;
end;
if nargin < 6
nombw = 0.0;
elseif gwrite
maxg = max(abs(g));
nombw = GAMMA * maxg * thk;
else
nombw = g;
end
fprintf(fid,'%10d \t\t #extgradfile\n', gwrite);
fprintf(fid,'%10d \t\t #res\n', nrf);
fprintf(fid,'%10d \t\t #pw\n',round(nompw*1e6));
fprintf(fid,'%10.7f \t\t #nom_flip \n',ang*180/pi);
abswidth = sum(abs(rfn))/nrf;
fprintf(fid,'%10.7f \t\t #abswidth \n',abswidth);
effwidth = sum(abs(rfn).^2)/nrf;
fprintf(fid,'%10.7f \t\t #effwidth \n',effwidth);
area = sum(abs(rfn))/nrf;
fprintf(fid,'%10.7f \t\t #area \n',area);
fprintf(fid,'%10.7f \t\t #dtycyc \n',dty_cyc);
fprintf(fid,'%10.7f \t\t #maxpw \n',max_pw);
max_b1 = maxrf;
fprintf(fid,'%10.7f \t\t #max_b1 \n',max_b1);
int_b1_sqr = sum(abs(rf).^2 * nompw / nrf * 1e3);
fprintf(fid,'%10.7f \t\t #max_int_b1_sqr \n',int_b1_sqr);
rms_b1 = sqrt(sum(abs(rf).^2))/nrf;
fprintf(fid,'%10.7f \t\t #max_rms_b1 \n',rms_b1);
fprintf(fid,'%10.7f \t\t #nom_bw \n',nombw);
if gwrite
fprintf(fid,'%10.3f \t\t #a_gzs \n',maxg);
thk_scale = thk * GAMMA / GAMMA_H1 * 10;
fprintf(fid,'%10.3f \t\t #nom_thk(mm) \n',thk_scale);
end
fclose(fid);
% Now write out RF and Gradient
%
rho_fname = sprintf('%s.rho', root_fname);
if any(imag(rf(:)))
signa(abs(rfn),rho_fname);
theta_fname = sprintf('%s.pha', root_fname);
signa(angle(rfn),theta_fname,1/pi);
else
signa(rfn,rho_fname);
end
if gwrite
g_fname = sprintf('%s.grd', root_fname);
signa(g,g_fname);
end