% Gyromagnetic ratios (Hz/gauss, 1 gauss = 10e-4 tesla) from
% http://hyperphysics.phy-astr.gsu.edu/Hbase/nuclear/nmr.html#c1

gamma_p = 2.6753E4; % proton
gamma_f = 2.518E4; % fluorine

% Both have nuclear spin I = 1/2
% which means that there are only two spin states

hbar = 4.136e-15; %eV*sec

N = 1000;
Bext = linspace(0,10000,N); % external field

% Plot proton level splittings
p_up = -gamma_p*hbar*1/2*Bext;
p_down = -p_up;

subplot(121);
plot(Bext,p_up); hold on;
plot(Bext,p_down);
xlabel('External field B_0 (gauss)');
ylabel('Magnetic energy (eV), H = -\mu{\cdot}B');
title('Splitting of nuclear spin states of a proton');
grid on;
plot([1770 1770], [-6e-7 6e-7],'r');

% Plot fluorine level splittings
f_up = -gamma_f*hbar*1/2*Bext;
f_down = -f_up;

subplot(122);
plot(Bext,f_up); hold on;
plot(Bext,f_down);
xlabel('External field B_0 (gauss)');
ylabel('Magnetic energy (eV), H = -\mu{\cdot}B');
title('Splitting of nuclear spin states of fluorine');
plot([1770 1770], [-6e-7 6e-7],'r');
grid on;