% Bloch Equation Simulation, Excercise F-1a
% -----------------------------------------
% 

rf = [pi/4 pi/4];	% Complex sequence of RF rotations.
			% This will make more sense in later exercises.

T1 = 600;       % ms.
T2 = 100;       % ms.

freq = [-500:5:500];	% Hz.
sig = 0*freq;		% Allocate space.

% Starting magnetization.

for f=1:length(freq)
    M = [0;0;1];
    dT = 2.3;	% ms between pulses.
    M = throt(abs(rf(1)),angle(rf(1))) * M;	% RF Rotation.

    for k = 2:length(rf)
	[A,B] = freeprecess(dT,T1,T2,freq(f));
	M = A*M+B;				% Propagate to next pulse.
    	M = throt(abs(rf(k)),angle(rf(k))) * M;	% RF Rotation.
    end;
    sig(f) = M(1)+i*M(2);

end;

subplot(2,1,1);
plot(freq,abs(sig));
ylabel('Signal (fraction of M_0)');
xlabel('Frequency (Hz)');
title('Signal Amplitude');
grid on;

subplot(2,1,2);
plot(freq,angle(sig));
ylabel('Phase (rad)'); 
xlabel('Frequency (Hz)');
title('Signal Phase');
grid on;







