-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_movie.m
249 lines (200 loc) · 9.2 KB
/
generate_movie.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
clear all
for loop_j=0:1
for mainlooop=0:5
if mainlooop==0 text_title='Pulse Evolution (no chem. shift evolution)';end
if mainlooop==1 text_title='Pulse Evolution';end
if mainlooop==2 text_title='Pulse Evolution PI(x) Evolution';end
if mainlooop==3 text_title='Pulse Evolution PI(y) Evolution';end
if mainlooop==4 text_title='Pulse Evolution PI(y) inv(J) Evolution ';end
if mainlooop==5 text_title='Pulse Evolution PI(x) inv(J) Evolution ';end
% for mainlooop=-3
clear stor_tr
clear stor_tr_crude
clear stor_t_crude
clear stor_t
main_ratio=90;
figure(1)
% Z = peaks;
% surf(Z)
% axis tight manual
% ax = gca;
% ax.NextPlot = 'replaceChildren';
if loop_j
writerObj = VideoWriter(['mov_' num2str(mainlooop) '_largeJ_.avi']);
else
writerObj = VideoWriter(['mov_' num2str(mainlooop) '.avi']);
end
% writerObj = VideoWriter(['mov_' num2str(mainlooop) '.mp4']);
writerObj.Quality = 75;%75 is default
open(writerObj);
axis tight
set(gca,'nextplot','replacechildren');
set(gcf,'Renderer','zbuffer');
list_of_values= 0.00:1:main_ratio+1;
loops = 360;
loops = 1;
count_sto=1;
F(size(list_of_values,2)+1) = struct('cdata',[],'colormap',[]);
counter_frames=1;
pul_dur=10e-6;
angle_pulse=90/180*pi;%90 deg
ampli_hz=(angle_pulse/pul_dur)/(2*pi);
disp(['pulse amplitude : ' num2str(ampli_hz) ' Hz'])
loop_offset=0+000*1000;
start_pt=[0 -1 0];
tmax=0.1;
center=10.123421;
center=0;
if mainlooop>0
center=0.3213123;
end
J=4;%pefect refocus...
if loop_j==1
J=8.25;
else
J=0.5;
end
larmo=[center ]+[-J/2 J/2];
starting_vector=[ 0 -1 0];
pos_mag=(starting_vector'*ones(1,size(larmo,2)))';%starts on x...
t_step=0.05;
firstr1=0;
tau=10;%(defaul no second pulse
rf=0.0000000;
% if mod(round(t*20),6)==0
R2=0;
R1=0;
before_180=1;
for t = 0:0.000001:tmax
% for t = 0:0.000001:0.05
% X = sin(loopj*pi/10)*Z;
%surf(X,Z)
% larmo=[10.123122 ];
increment_tilt=pi/100000;
inc=0;
% tilt_angle=atan((ampli_hz/loop_offset));
% if tilt_angle<0, tilt_angle=tilt_angle+pi;end
for loop=1:size(larmo,2)
v=[rf 0 larmo(1,loop) ];
di=cross(v,pos_mag(loop,:));
pos_mag(loop,:)=pos_mag(loop,:)+di*increment_tilt;
end
% di=di/norm(pos_mag);
% pos_mag(1,1)=pos_mag(1,1)*exp(-R2*increment_tilt);
% pos_mag(1,2)=pos_mag(1,2)*exp(-R2*increment_tilt);
if R1~=0
if firstr1==0
valref=pos_mag(1,3);diff=1-valref;
firstr1=1;
end
diff=diff*((exp(-R1*increment_tilt)));
pos_mag(1,3)=1-diff;
end
nu_eff=sqrt(loop_offset*loop_offset+ampli_hz*ampli_hz);
%
% how_much_further=2;
% if size(factor,2)==1
% plot3(how_much_further*[0 sin(tilt_angle)],[0 0],how_much_further*[0 cos(tilt_angle)],'k--')
% text(how_much_further*[sin(tilt_angle)],[ 0],how_much_further*[ cos(tilt_angle)],'Beff')
%
% end
% %%%%%%%%%%%%%%%%%
%
%
% figure('Units','inches', 'PaperPositionMode','auto', 'Position',[0 0 4 4]);
if mainlooop>1
if before_180
if t>tmax/2
% apply pi pulse
if mainlooop<3 || mainlooop>4
pos_mag(:,1)=-pos_mag(:,1);before_180=0;
else
pos_mag(:,2)=-pos_mag(:,2);before_180=0;
end
if mainlooop>=4
J=-J;
larmo=[center ]+[-J/2 J/2];
end
end
end
end
%work on figure
if mod(round(t*1e6),500)==0
where_low=-3;
disp(['time: ' num2str(t) '/' max(num2str(tmax)) ' ' num2str(rf)] )
cur_f=figure(1);clf;hold on
% black arrow
for loop=1:size(larmo,2)
fig_gen_spheres(pos_mag(loop,:))
end
%midd arro
[v1 v2]=view();
cen_vect=pos_mag(1,:)*0.5+0.5*pos_mag(2,:);
color_inphase='g';
color_antiphase='r';
mi_dist=0.2;
if sum(sum((cen_vect).*(cen_vect)))>(mi_dist/2)*(mi_dist/2)
fig_gen_spheres(cen_vect,[v1 v2],color_inphase)
else
plot3( [0 cen_vect(:,1)],[0 cen_vect(:,2)],[ 0 cen_vect(:,3)],color_inphase,'LineWidth',2)
end
if sum(sum(((pos_mag(1,:)-cen_vect).*(pos_mag(1,:)-cen_vect))))>(mi_dist/2)*(mi_dist/2)
fig_gen_spheres([ pos_mag(1,:);cen_vect],[v1 v2],color_antiphase)
fig_gen_spheres([ pos_mag(2,:);cen_vect],[v1 v2],color_antiphase)
else
plot3( pos_mag(:,1),pos_mag(:,2),pos_mag(:,3),color_antiphase,'LineWidth',2)
end
% store last point for full trajectory plot
stor_tr_crude(count_sto,:)=pos_mag(1,:);
stor_t_crude(count_sto,:)=t;
count_sto=count_sto+1;
% interpolation of
[stor_tr, stor_t]=interp_to_smooth(stor_tr_crude,stor_t_crude);
% plot3(stor_tr(:,1),stor_tr(:,2),stor_tr(:,3),'k-','linewidth',1.25)
plot3( [0.5 0.5],[-1 1],[where_low where_low],'k-')
plot3(-[0.5 0.5],[-1 1],[where_low where_low],'k-')
plot3(-[0.0 0.0],[-1 1],[where_low where_low],'k:')
plot3(+[1 1],[-1 1],[where_low where_low],'k:')
plot3([-1 1],[-1 -1],[where_low where_low],'k-')
plot3(-[1 1],[-1 1],[where_low where_low]+0.5,'k-')
plot3(-[1 1],[-1 1],[where_low where_low]+1,'k:')
plot3(-[1 1],[-1 1],[where_low where_low]+0,'k:')
plot3(-[1 1],[-1 -1],[0 1 ]+where_low,'k-')
% list_t=2*(t/tmax)*(1:size(stor_tr,1))/size(stor_tr,1)-1;
list_t=2*(t/tmax)*(stor_t)/max(abs(stor_t))-1;
% plot3( 0.5+0.5*stor_tr(:,1),list_t,stor_tr(:,3)*0+where_low,'g-','linewidth',1.25)
% plot3(-0.5+0.5*stor_tr(:,2),list_t,stor_tr(:,3)*0+where_low,'b-','linewidth',1.25)
% plot3(stor_tr(:,3)*0-1,list_t,0.5+0.5*stor_tr(:,3)+where_low,'r-','linewidth',1.25)
% phase_a=cos(anglet/360*2*pi)+j*sin(anglet/360*2*pi);%as complex number
% phase_a=phase_a/(abs(phase_a));
% [dist_in_hz erro_in_deg]=shap_fn3d(loopj-1,mainlooop,main_ratio);
% [dist_in_hz erro_in_deg]=shap_fn3d(loopj-1,mainlooop,main_ratio);
axis([ -1 1 -1 1 where_low 1])
%plot3(store_traj(:,1),store_traj(:,2),store_traj(:,3),'k-','linewidth',1.5)
%plot3(store_traj(:,1),store_traj(:,2),0*store_traj(:,3),'k-','linewidth',1)
axis off
set(gcf,'color','w');
text(0,0,1.3,text_title,'HorizontalAlignment','center')
draw_unit_circle([0;0;0])
drawnow;
tmp_frame = getframe;
if counter_frames==1
si=size(tmp_frame.cdata);
else
tmp_frame.cdata=tmp_frame.cdata(1:si(1,1),1:si(1,2),1:si(1,3));
end
F(counter_frames)=tmp_frame;
writeVideo(writerObj,F(counter_frames));
counter_frames=counter_frames+1;
end
end
close(writerObj);
%movie(F,2)
% figure(111)
% clf
% plot(store_dis_in_hz(:,1),store_erro_in_deg(:,1),'b-');
% hold on
% plot(store_dis_in_hz(:,2),store_erro_in_deg(:,2),'r-');
% print('-depsc','-tiff','-r600',[ 'Phase_error_nearby_small_signals' num2str(main_ratio) '.eps']);%here
end
end