image thumbnail

spin echo simulation

by

 

NMR, 90,180 deg rotations

test_res_many_avi.m
% for arrow:
global cl_df  al_df  r0_df  r1_df  h1_df  h2_df  R_df
cl_df=[1 0 0]; % default color
al_df=1; % default alpha
r0_df=0.03; % default arrow base radius
r1_df=0.1; % default arrow tip radius
h1_df=0.4; % default arrow tip height
h2_df=0.35; % default arrow tip height internal
nnn=50;
phi=(0:2*pi/nnn:2*pi)';
R_df=[cos(phi),sin(phi)]; % default sin cos values

na=10; % nunmber of arrows


B=[0;0;3]; % magnetic field

%J=[0;0.0;1]; % momentum
J=zeros(3,na);
J(3,:)=1;

Bm=sqrt(B'*B);

gm=1; % hyropmagnetic ratio

B1a=[0.2; 0; 0]; % aditional fieled amplitude
w=gm*Bm; % aditional field angular frequency = precession frequerncy

Br=0.02*randn(3,na); % random field

close all;
figure('units','normalized','position',[0.05 0.07  0.92 0.8]);

%subplot(2,1,1);
sx=0.8;
sy=0.8;
ha1=axes('position',[0.95-sx 0.95-sy sx sy]);


hold on;
hb=create_3d_arrow([0;0;0],B,[0 0 1]);
axis equal;
view(3);
light;
hj=zeros(1,na);
for nc=1:na
    hj(nc)=create_3d_arrow([0;0;0],J(:,nc),[1 0 0]);
end

%subplot(2,1,2);
ha2=axes('position',[0.07 0.07 0.3 0.2]);
hm=plot(NaN,NaN,'k.-');
title('mean magnetization norm');
xlabel('time');


lm=4;
lma=[-lm lm];

dt=0.001;
tm=160;
ta=0:dt:tm;
Lta=length(ta);
tic;
dtc=100;
t1=15.5480;
t2=50;
t3=80;
taa=[];
mJLa=[];
clear F;
fc=1;
for tc=1:Lta
    t=ta(tc);
    B1=B1a*cos(w*t);
    Bt=B;
    if t<=t1
        Bt=B+B1;
    end
    if (t2<=t)&&(t<=t3)
        Bt=B+B1;
    end
    for nc=1:na
        Btt=Bt+Br(:,nc);
        J(:,nc)=J(:,nc)+dt*gm*cross(J(:,nc),Btt);
    end
    if mod(tc,dtc)==0
        for nc=1:na
            update_3d_arrow(hj(nc),[0;0;0],J(:,nc));
        end
        update_3d_arrow(hb,[0;0;0],Bt);
        %subplot(2,1,1);
        xlim(ha1,lma);
        ylim(ha1,lma);
        zlim(ha1,lma);
        
        disp([num2str(t) '   ' num2str(mean(J(3,:)))]);
        mJ=mean(J,2);
        mJL=sqrt(mJ'*mJ);
        taa=[taa ta(tc)];
        mJLa=[mJLa mJL];
        set(hm,'XData',taa,'YData',mJLa);
        
        drawnow;
        
        F(fc)=getframe(gcf);
        fc=fc+1;
        
        
    end
    
end
toc
movie2avi(F,'spin_echo_avi','fps',10,'compression','Cinepak'); 

Contact us