
% -- Examples of EPG for bSSFP and gradient spoiling ---

%  Download epg_funcs.tar from the Matlab directory first!

close all;
clear
FZ = [0;0;1];
N =200
for k=1:N
  FZ = epg_rf(FZ,pi/3,pi/2);
  FZ = epg_grelax(FZ , 500,100,5,0,0,1,0);
end;
size(FZ)
FZ(1,1)
M = epg_FZ2spins(FZ,500,0);
size(M)
Mxy = M(1,:)+i*M(2,:);
magphase(Mxy*500);

disp('First plot, one cycle of bSSFP signal');
pause; 



FZ = [0;0;1];
for k=1:N
 FZ = epg_grelax(FZ , 500,100,2.5,0,0,1,0);
 FZ = epg_rf(FZ,pi/3,pi/2);
 FZ = epg_grelax(FZ , 500,100,2.5,0,0,1,0);
 FZ = epg_grelax(FZ , 500,100,2.5,0,0,1,0);
 FZ = epg_rf(FZ,-pi/3,pi/2);
 FZ = epg_grelax(FZ , 500,100,2.5,0,0,1,0);
end;
M = epg_FZ2spins(FZ,1000,0)*1000;
size(FZ)
Mxy = M(1,:)+i*M(2,:);
figure; magphase(Mxy);
mean(Mxy)

disp('Second plot, two cycles of bSSFP signal');
pause; 

FZ1 = FZ;
FZ1 = epg_grelax(FZ , 500,100,2.5,0,0,1,0);
M = epg_FZ2spins(FZ1,1000,0)*1000;
Mxy = M(1,:)+i*M(2,:);
figure; magphase(Mxy);
mean(Mxy)
FZ1(1,1)


disp('End of TR now - compare mean to F0 state.');
pause; 

epg_show(FZ(:,1:5),0,.25);
disp('F/Z states.');
disp('Note 2,1 plot shows steady state');
pause;

disp('EPG states - mid TR');
pause; 

epg_show(FZ1(:,1:5),0,.25);

disp('EPG states - end TR');
pause; 

T1 = 500;
T2=100;
TR = 5;
TE = 0;

% -- Ernst angle for this T1;
alph = acos(exp(-TR/T1))	
ans*pi/180

FZ = [0;0;1];

for k=1:N
FZ = epg_grelax(FZ , 500,100,TR,0,0,1,0);
FZ = epg_rf(FZ,alph,pi/2);
end;
epg_show(FZ(:,1:5),0,.1);


disp('EPG states - Ernst angle');
pause; 




FZ1 = [0;0;1];
for k=1:N
FZ1 = epg_grelax(FZ1 , 500,100,TR,0,0,1,0);
FZ1(1:2,:)=0;
FZ1 = epg_rf(FZ1,alph,pi/2);
end;
figure;
epg_show(FZ1(:,1:5),0,.1);

disp('EPG states - Perfect Spoiling at Ernst angle');
pause; 

